aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cryptography/exceptions.py16
-rw-r--r--cryptography/hazmat/backends/commoncrypto/backend.py10
-rw-r--r--cryptography/hazmat/backends/openssl/backend.py14
3 files changed, 24 insertions, 16 deletions
diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py
index b4962591..a26dbe18 100644
--- a/cryptography/exceptions.py
+++ b/cryptography/exceptions.py
@@ -16,6 +16,18 @@ class UnsupportedAlgorithm(Exception):
pass
+class UnsupportedCipher(UnsupportedAlgorithm):
+ pass
+
+
+class UnsupportedHash(UnsupportedAlgorithm):
+ pass
+
+
+class UnsupportedPadding(UnsupportedAlgorithm):
+ pass
+
+
class AlreadyFinalized(Exception):
pass
@@ -46,7 +58,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 f05ee3d6..5de506a0 100644
--- a/cryptography/hazmat/backends/openssl/backend.py
+++ b/cryptography/hazmat/backends/openssl/backend.py
@@ -18,8 +18,8 @@ import itertools
from cryptography import utils
from cryptography.exceptions import (
- UnsupportedAlgorithm, InvalidTag, InternalError, AlreadyFinalized,
- UnsupportedPadding, InvalidSignature
+ InvalidTag, InternalError, AlreadyFinalized, UnsupportedPadding,
+ InvalidSignature
)
from cryptography.hazmat.backends.interfaces import (
CipherBackend, HashBackend, HMACBackend, PBKDF2HMACBackend, RSABackend
@@ -211,7 +211,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)
@@ -517,7 +517,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)
)
@@ -567,7 +567,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)
)