diff options
Diffstat (limited to 'tests/hazmat/backends')
| -rw-r--r-- | tests/hazmat/backends/test_commoncrypto.py | 6 | ||||
| -rw-r--r-- | tests/hazmat/backends/test_multibackend.py | 24 | ||||
| -rw-r--r-- | tests/hazmat/backends/test_openssl.py | 12 | 
3 files changed, 24 insertions, 18 deletions
diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py index 72ed61c0..7c703f67 100644 --- a/tests/hazmat/backends/test_commoncrypto.py +++ b/tests/hazmat/backends/test_commoncrypto.py @@ -16,13 +16,15 @@ from __future__ import absolute_import, division, print_function  import pytest  from cryptography import utils -from cryptography.exceptions import InternalError, UnsupportedCipher +from cryptography.exceptions import InternalError, _Reasons  from cryptography.hazmat.bindings.commoncrypto.binding import Binding  from cryptography.hazmat.primitives import interfaces  from cryptography.hazmat.primitives.ciphers.algorithms import AES  from cryptography.hazmat.primitives.ciphers.base import Cipher  from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM +from ...utils import raises_unsupported_algorithm +  @utils.register_interface(interfaces.CipherAlgorithm)  class DummyCipher(object): @@ -63,5 +65,5 @@ class TestCommonCrypto(object):          cipher = Cipher(              DummyCipher(), GCM(b"fake_iv_here"), backend=b,          ) -        with pytest.raises(UnsupportedCipher): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):              cipher.encryptor() diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index c5c0d82a..b7bcaf69 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -17,7 +17,7 @@ import pytest  from cryptography import utils  from cryptography.exceptions import ( -    UnsupportedAlgorithm, UnsupportedCipher, UnsupportedHash +    UnsupportedAlgorithm, _Reasons  )  from cryptography.hazmat.backends.interfaces import (      CipherBackend, HMACBackend, HashBackend, PBKDF2HMACBackend, RSABackend @@ -27,6 +27,8 @@ from cryptography.hazmat.primitives import hashes, hmac  from cryptography.hazmat.primitives.asymmetric import padding  from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from ...utils import raises_unsupported_algorithm +  @utils.register_interface(CipherBackend)  class DummyCipherBackend(object): @@ -38,11 +40,11 @@ class DummyCipherBackend(object):      def create_symmetric_encryption_ctx(self, algorithm, mode):          if not self.cipher_supported(algorithm, mode): -            raise UnsupportedCipher +            raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_CIPHER)      def create_symmetric_decryption_ctx(self, algorithm, mode):          if not self.cipher_supported(algorithm, mode): -            raise UnsupportedCipher +            raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_CIPHER)  @utils.register_interface(HashBackend) @@ -55,7 +57,7 @@ class DummyHashBackend(object):      def create_hash_ctx(self, algorithm):          if not self.hash_supported(algorithm): -            raise UnsupportedHash +            raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_HASH)  @utils.register_interface(HMACBackend) @@ -68,7 +70,7 @@ class DummyHMACBackend(object):      def create_hmac_ctx(self, key, algorithm):          if not self.hmac_supported(algorithm): -            raise UnsupportedHash +            raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_HASH)  @utils.register_interface(PBKDF2HMACBackend) @@ -82,7 +84,7 @@ class DummyPBKDF2HMACBackend(object):      def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,                             key_material):          if not self.pbkdf2_hmac_supported(algorithm): -            raise UnsupportedHash +            raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_HASH)  @utils.register_interface(RSABackend) @@ -123,9 +125,9 @@ class TestMultiBackend(object):              modes.CBC(b"\x00" * 16),              backend=backend          ) -        with pytest.raises(UnsupportedCipher): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):              cipher.encryptor() -        with pytest.raises(UnsupportedCipher): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):              cipher.decryptor()      def test_hashes(self): @@ -136,7 +138,7 @@ class TestMultiBackend(object):          hashes.Hash(hashes.MD5(), backend=backend) -        with pytest.raises(UnsupportedHash): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):              hashes.Hash(hashes.SHA1(), backend=backend)      def test_hmac(self): @@ -147,7 +149,7 @@ class TestMultiBackend(object):          hmac.HMAC(b"", hashes.MD5(), backend=backend) -        with pytest.raises(UnsupportedHash): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):              hmac.HMAC(b"", hashes.SHA1(), backend=backend)      def test_pbkdf2(self): @@ -158,7 +160,7 @@ class TestMultiBackend(object):          backend.derive_pbkdf2_hmac(hashes.MD5(), 10, b"", 10, b"") -        with pytest.raises(UnsupportedHash): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):              backend.derive_pbkdf2_hmac(hashes.SHA1(), 10, b"", 10, b"")      def test_rsa(self): diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 3747f436..016da0fc 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -17,7 +17,7 @@ import pytest  from cryptography import utils  from cryptography.exceptions import ( -    InternalError, UnsupportedCipher, UnsupportedHash +    InternalError, _Reasons  )  from cryptography.hazmat.backends.openssl.backend import Backend, backend  from cryptography.hazmat.primitives import hashes, interfaces @@ -26,6 +26,8 @@ from cryptography.hazmat.primitives.ciphers import Cipher  from cryptography.hazmat.primitives.ciphers.algorithms import AES  from cryptography.hazmat.primitives.ciphers.modes import CBC +from ...utils import raises_unsupported_algorithm +  @utils.register_interface(interfaces.Mode)  class DummyMode(object): @@ -78,7 +80,7 @@ class TestOpenSSL(object):          cipher = Cipher(              DummyCipher(), mode, backend=b,          ) -        with pytest.raises(UnsupportedCipher): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):              cipher.encryptor()      def test_consume_errors(self): @@ -140,7 +142,7 @@ class TestOpenSSL(object):      def test_derive_pbkdf2_raises_unsupported_on_old_openssl(self):          if backend.pbkdf2_hmac_supported(hashes.SHA256()):              pytest.skip("Requires an older OpenSSL") -        with pytest.raises(UnsupportedHash): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):              backend.derive_pbkdf2_hmac(hashes.SHA256(), 10, b"", 1000, b"")      @pytest.mark.skipif( @@ -153,7 +155,7 @@ class TestOpenSSL(object):              key_size=512,              backend=backend          ) -        with pytest.raises(UnsupportedHash): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):              private_key.signer(                  padding.PSS(                      mgf=padding.MGF1( @@ -165,7 +167,7 @@ class TestOpenSSL(object):                  backend              )          public_key = private_key.public_key() -        with pytest.raises(UnsupportedHash): +        with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):              public_key.verifier(                  b"sig",                  padding.PSS(  | 
