aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/backends/test_openssl.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2016-03-05 13:57:16 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2016-03-05 13:57:16 -0500
commit59518a0ccc814fd8ef4d1e6fce6e2858a34a7348 (patch)
treefcbd8c2dfd7ec6caed3a0668bd7deb6fa27d24e4 /tests/hazmat/backends/test_openssl.py
parent6960600f111de1710b01cc4f4ffc6c023d742cd7 (diff)
downloadcryptography-59518a0ccc814fd8ef4d1e6fce6e2858a34a7348.tar.gz
cryptography-59518a0ccc814fd8ef4d1e6fce6e2858a34a7348.tar.bz2
cryptography-59518a0ccc814fd8ef4d1e6fce6e2858a34a7348.zip
Un-double the test doubles
Diffstat (limited to 'tests/hazmat/backends/test_openssl.py')
-rw-r--r--tests/hazmat/backends/test_openssl.py53
1 files changed, 13 insertions, 40 deletions
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,