diff options
Diffstat (limited to 'tests/hazmat/backends')
| -rw-r--r-- | tests/hazmat/backends/test_commoncrypto.py | 13 | ||||
| -rw-r--r-- | tests/hazmat/backends/test_openssl.py | 53 | 
2 files changed, 16 insertions, 50 deletions
diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py index f7200016..2b730e93 100644 --- a/tests/hazmat/backends/test_commoncrypto.py +++ b/tests/hazmat/backends/test_commoncrypto.py @@ -6,23 +6,16 @@ from __future__ import absolute_import, division, print_function  import pytest -from cryptography import utils  from cryptography.exceptions import InternalError, _Reasons  from cryptography.hazmat.backends import _available_backends -from cryptography.hazmat.primitives.ciphers import Cipher, CipherAlgorithm +from cryptography.hazmat.primitives.ciphers import Cipher  from cryptography.hazmat.primitives.ciphers.algorithms import AES  from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM +from ...doubles import DummyCipherAlgorithm  from ...utils import raises_unsupported_algorithm -@utils.register_interface(CipherAlgorithm) -class DummyCipher(object): -    name = "dummy-cipher" -    block_size = None -    key_size = None - -  @pytest.mark.skipif("commoncrypto" not in                      [i.name for i in _available_backends()],                      reason="CommonCrypto not available") @@ -55,7 +48,7 @@ class TestCommonCrypto(object):          from cryptography.hazmat.backends.commoncrypto.backend import Backend          b = Backend()          cipher = Cipher( -            DummyCipher(), GCM(b"fake_iv_here"), backend=b, +            DummyCipherAlgorithm(), GCM(b"fake_iv_here"), backend=b,          )          with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):              cipher.encryptor() diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index f94b94ab..072f8be3 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -21,15 +21,16 @@ from cryptography.hazmat.backends.openssl.backend import (  from cryptography.hazmat.backends.openssl.ec import _sn_to_elliptic_curve  from cryptography.hazmat.primitives import hashes, serialization  from cryptography.hazmat.primitives.asymmetric import dsa, ec, padding -from cryptography.hazmat.primitives.ciphers import ( -    BlockCipherAlgorithm, Cipher, CipherAlgorithm -) +from cryptography.hazmat.primitives.ciphers import Cipher  from cryptography.hazmat.primitives.ciphers.algorithms import AES -from cryptography.hazmat.primitives.ciphers.modes import CBC, CTR, Mode +from cryptography.hazmat.primitives.ciphers.modes import CBC, CTR  from ..primitives.fixtures_dsa import DSA_KEY_2048  from ..primitives.fixtures_rsa import RSA_KEY_2048, RSA_KEY_512  from ..primitives.test_ec import _skip_curve_unsupported +from ...doubles import ( +    DummyAsymmetricPadding, DummyCipherAlgorithm, DummyHashAlgorithm, DummyMode +)  from ...utils import load_vectors_from_file, raises_unsupported_algorithm @@ -47,32 +48,6 @@ class TestLibreSkip(object):              skip_if_libre_ssl(u"LibreSSL 2.1.6") -@utils.register_interface(Mode) -class DummyMode(object): -    name = "dummy-mode" - -    def validate_for_algorithm(self, algorithm): -        pass - - -@utils.register_interface(CipherAlgorithm) -class DummyCipher(object): -    name = "dummy-cipher" -    key_size = None - - -@utils.register_interface(padding.AsymmetricPadding) -class DummyPadding(object): -    name = "dummy-cipher" - - -@utils.register_interface(hashes.HashAlgorithm) -class DummyHash(object): -    name = "dummy-hash" -    block_size = None -    digest_size = None - -  class DummyMGF(object):      _salt_length = 0 @@ -111,12 +86,12 @@ class TestOpenSSL(object):      def test_nonexistent_cipher(self, mode):          b = Backend()          b.register_cipher_adapter( -            DummyCipher, +            DummyCipherAlgorithm,              type(mode),              lambda backend, cipher, mode: backend._ffi.NULL          )          cipher = Cipher( -            DummyCipher(), mode, backend=b, +            DummyCipherAlgorithm(), mode, backend=b,          )          with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER):              cipher.encryptor() @@ -383,11 +358,11 @@ class TestOpenSSLRSA(object):      def test_rsa_padding_unsupported_pss_mgf1_hash(self):          assert backend.rsa_padding_supported( -            padding.PSS(mgf=padding.MGF1(DummyHash()), salt_length=0) +            padding.PSS(mgf=padding.MGF1(DummyHashAlgorithm()), salt_length=0)          ) is False      def test_rsa_padding_unsupported(self): -        assert backend.rsa_padding_supported(DummyPadding()) is False +        assert backend.rsa_padding_supported(DummyAsymmetricPadding()) is False      def test_rsa_padding_supported_pkcs1v15(self):          assert backend.rsa_padding_supported(padding.PKCS1v15()) is True @@ -462,12 +437,8 @@ class TestOpenSSLRSA(object):  )  class TestOpenSSLCMAC(object):      def test_unsupported_cipher(self): -        @utils.register_interface(BlockCipherAlgorithm) -        class FakeAlgorithm(object): -            block_size = 64 -          with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER): -            backend.create_cmac_ctx(FakeAlgorithm()) +            backend.create_cmac_ctx(DummyCipherAlgorithm())  class TestOpenSSLCreateX509CSR(object): @@ -498,7 +469,9 @@ class TestOpenSSLSignX509Certificate(object):          private_key = RSA_KEY_2048.private_key(backend)          with pytest.raises(TypeError): -            backend.create_x509_certificate(object(), private_key, DummyHash()) +            backend.create_x509_certificate( +                object(), private_key, DummyHashAlgorithm() +            )      @pytest.mark.skipif(          backend._lib.OPENSSL_VERSION_NUMBER >= 0x10001000,  | 
