diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2014-02-26 21:20:41 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2014-02-26 21:20:41 -0800 |
commit | 2b241a2efbe17d1b865c9249b904bf0d6df8a76f (patch) | |
tree | ddfaa8451e60ab0c8bd9e6915cd9c69fe043d2af | |
parent | d8c8f7cde6b43d08f39cd11cd2e2dd3ed7feb5a5 (diff) | |
download | cryptography-2b241a2efbe17d1b865c9249b904bf0d6df8a76f.tar.gz cryptography-2b241a2efbe17d1b865c9249b904bf0d6df8a76f.tar.bz2 cryptography-2b241a2efbe17d1b865c9249b904bf0d6df8a76f.zip |
Initial work
-rw-r--r-- | cryptography/exceptions.py | 27 | ||||
-rw-r--r-- | cryptography/hazmat/backends/commoncrypto/backend.py | 10 | ||||
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 14 |
3 files changed, 34 insertions, 17 deletions
diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py index b4962591..b98f6ab9 100644 --- a/cryptography/exceptions.py +++ b/cryptography/exceptions.py @@ -11,8 +11,29 @@ # See the License for the specific language governing permissions and # limitations under the License. +import abc -class UnsupportedAlgorithm(Exception): +import six + +from cryptography import utils + + +class UnsupportedAlgorithm(six.with_metaclass(abc.ABCBase)): + pass + + +@utils.register_interface(UnsupportedAlgorithm) +class UnsupportedCipher(Exception): + pass + + +@utils.register_interface(UnsupportedAlgorithm) +class UnsupportedHash(Exception): + pass + + +@utils.register_interface(UnsupportedAlgorithm) +class UnsupportedPadding(Exception): pass @@ -46,7 +67,3 @@ class InvalidKey(Exception): class InvalidToken(Exception): pass - - -class UnsupportedPadding(Exception): - pass diff --git a/cryptography/hazmat/backends/commoncrypto/backend.py b/cryptography/hazmat/backends/commoncrypto/backend.py index 4a451d34..53228b31 100644 --- a/cryptography/hazmat/backends/commoncrypto/backend.py +++ b/cryptography/hazmat/backends/commoncrypto/backend.py @@ -17,7 +17,7 @@ from collections import namedtuple from cryptography import utils from cryptography.exceptions import ( - UnsupportedAlgorithm, InvalidTag, InternalError + InvalidTag, InternalError, UnsupportedCipher, UnsupportedHash ) from cryptography.hazmat.backends.interfaces import ( HashBackend, HMACBackend, CipherBackend, PBKDF2HMACBackend @@ -273,7 +273,7 @@ class _CipherContext(object): try: cipher_enum, mode_enum = registry[type(cipher), type(mode)] except KeyError: - raise UnsupportedAlgorithm( + raise UnsupportedCipher( "cipher {0} in {1} mode is not supported " "by this backend".format( cipher.name, mode.name if mode else mode) @@ -346,7 +346,7 @@ class _GCMCipherContext(object): try: cipher_enum, mode_enum = registry[type(cipher), type(mode)] except KeyError: - raise UnsupportedAlgorithm( + raise UnsupportedCipher( "cipher {0} in {1} mode is not supported " "by this backend".format( cipher.name, mode.name if mode else mode) @@ -420,7 +420,7 @@ class _HashContext(object): try: methods = self._backend._hash_mapping[self.algorithm.name] except KeyError: - raise UnsupportedAlgorithm( + raise UnsupportedHash( "{0} is not a supported hash on this backend".format( algorithm.name) ) @@ -463,7 +463,7 @@ class _HMACContext(object): try: alg = self._backend._supported_hmac_algorithms[algorithm.name] except KeyError: - raise UnsupportedAlgorithm( + raise UnsupportedHash( "{0} is not a supported HMAC hash on this backend".format( algorithm.name) ) diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index 00fdc266..47d2b106 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -17,8 +17,8 @@ import itertools from cryptography import utils from cryptography.exceptions import ( - UnsupportedAlgorithm, InvalidTag, InternalError, AlreadyFinalized, - UnsupportedPadding + InvalidTag, InternalError, AlreadyFinalized, UnsupportedPadding, + UnsupportedCipher, UnsupportedHash ) from cryptography.hazmat.backends.interfaces import ( CipherBackend, HashBackend, HMACBackend, PBKDF2HMACBackend, RSABackend @@ -206,7 +206,7 @@ class Backend(object): assert res == 1 else: if not isinstance(algorithm, hashes.SHA1): - raise UnsupportedAlgorithm( + raise UnsupportedHash( "This version of OpenSSL only supports PBKDF2HMAC with " "SHA1" ) @@ -377,7 +377,7 @@ class _CipherContext(object): try: adapter = registry[type(cipher), type(mode)] except KeyError: - raise UnsupportedAlgorithm( + raise UnsupportedCipher( "cipher {0} in {1} mode is not supported " "by this backend".format( cipher.name, mode.name if mode else mode) @@ -385,7 +385,7 @@ class _CipherContext(object): evp_cipher = adapter(self._backend, cipher, mode) if evp_cipher == self._backend._ffi.NULL: - raise UnsupportedAlgorithm( + raise UnsupportedCipher( "cipher {0} in {1} mode is not supported " "by this backend".format( cipher.name, mode.name if mode else mode) @@ -496,7 +496,7 @@ class _HashContext(object): evp_md = self._backend._lib.EVP_get_digestbyname( algorithm.name.encode("ascii")) if evp_md == self._backend._ffi.NULL: - raise UnsupportedAlgorithm( + raise UnsupportedHash( "{0} is not a supported hash on this backend".format( algorithm.name) ) @@ -545,7 +545,7 @@ class _HMACContext(object): evp_md = self._backend._lib.EVP_get_digestbyname( algorithm.name.encode('ascii')) if evp_md == self._backend._ffi.NULL: - raise UnsupportedAlgorithm( + raise UnsupportedHash( "{0} is not a supported hash on this backend".format( algorithm.name) ) |