diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 7 | ||||
-rw-r--r-- | tests/hazmat/bindings/test_openssl.py | 2 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_padding.py | 9 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 24 | ||||
-rw-r--r-- | tests/hazmat/primitives/utils.py | 18 | ||||
-rw-r--r-- | tests/test_utils.py | 2 |
6 files changed, 35 insertions, 27 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index d55e6cf6..86d5a03b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,7 +18,7 @@ import pytest from cryptography.hazmat.backends import _available_backends from cryptography.hazmat.backends.interfaces import ( CMACBackend, CipherBackend, DSABackend, HMACBackend, HashBackend, - PBKDF2HMACBackend, RSABackend + PBKDF2HMACBackend, RSABackend, TraditionalOpenSSLSerializationBackend ) from .utils import check_backend_support, check_for_iface, select_backends @@ -40,6 +40,11 @@ def pytest_runtest_setup(item): check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item) check_for_iface("dsa", DSABackend, item) check_for_iface("rsa", RSABackend, item) + check_for_iface( + "traditional_openssl_serialization", + TraditionalOpenSSLSerializationBackend, + item + ) check_backend_support(item) diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index 1dbd23b4..58d7602b 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -84,7 +84,7 @@ class TestOpenSSL(object): with pytest.raises(RuntimeError): b._lock_cb(0, b.lib.CRYPTO_LOCK_SSL, "<test>", 1) - # errors shouldnt cause locking + # errors shouldn't cause locking assert lock.acquire(False) lock.release() diff --git a/tests/hazmat/primitives/test_padding.py b/tests/hazmat/primitives/test_padding.py index 932cef1e..cac54f27 100644 --- a/tests/hazmat/primitives/test_padding.py +++ b/tests/hazmat/primitives/test_padding.py @@ -17,6 +17,7 @@ import pytest import six +from cryptography.exceptions import AlreadyFinalized from cryptography.hazmat.primitives import padding @@ -97,15 +98,15 @@ class TestPKCS7(object): def test_use_after_finalize(self): padder = padding.PKCS7(128).padder() b = padder.finalize() - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): padder.update(b"") - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): padder.finalize() unpadder = padding.PKCS7(128).unpadder() unpadder.update(b) unpadder.finalize() - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): unpadder.update(b"") - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): unpadder.finalize() diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 602f5243..38a5d0af 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -26,7 +26,9 @@ from cryptography.exceptions import _Reasons from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.asymmetric import padding, rsa -from .utils import generate_rsa_verification_test +from .utils import ( + _check_rsa_private_key, generate_rsa_verification_test +) from ...utils import ( load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file, raises_unsupported_algorithm @@ -42,24 +44,6 @@ class DummyMGF(object): _salt_length = 0 -def _check_rsa_private_key(skey): - assert skey - assert skey.modulus - assert skey.public_exponent - assert skey.private_exponent - assert skey.p * skey.q == skey.modulus - assert skey.key_size - assert skey.dmp1 == rsa.rsa_crt_dmp1(skey.d, skey.p) - assert skey.dmq1 == rsa.rsa_crt_dmq1(skey.d, skey.q) - assert skey.iqmp == rsa.rsa_crt_iqmp(skey.p, skey.q) - - pkey = skey.public_key() - assert pkey - assert skey.modulus == pkey.modulus - assert skey.public_exponent == pkey.public_exponent - assert skey.key_size == pkey.key_size - - def _flatten_pkcs1_examples(vectors): flattened_vectors = [] for vector in vectors: @@ -95,7 +79,7 @@ def test_modular_inverse(): @pytest.mark.rsa class TestRSA(object): @pytest.mark.parametrize( - "public_exponent,key_size", + ("public_exponent", "key_size"), itertools.product( (3, 5, 65537), (1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1536, 2048) diff --git a/tests/hazmat/primitives/utils.py b/tests/hazmat/primitives/utils.py index 2e838474..6c3f4c95 100644 --- a/tests/hazmat/primitives/utils.py +++ b/tests/hazmat/primitives/utils.py @@ -406,3 +406,21 @@ def rsa_verification_test(backend, params, hash_alg, pad_factory): verifier.verify() else: verifier.verify() + + +def _check_rsa_private_key(skey): + assert skey + assert skey.modulus + assert skey.public_exponent + assert skey.private_exponent + assert skey.p * skey.q == skey.modulus + assert skey.key_size + assert skey.dmp1 == rsa.rsa_crt_dmp1(skey.d, skey.p) + assert skey.dmq1 == rsa.rsa_crt_dmq1(skey.d, skey.q) + assert skey.iqmp == rsa.rsa_crt_iqmp(skey.p, skey.q) + + pkey = skey.public_key() + assert pkey + assert skey.modulus == pkey.modulus + assert skey.public_exponent == pkey.public_exponent + assert skey.key_size == pkey.key_size diff --git a/tests/test_utils.py b/tests/test_utils.py index b50c21fe..7a0b9e74 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2638,7 +2638,7 @@ def test_raises_unsupported_no_exc(): def test_raises_unsupported_algorithm(): - # Check that it doesnt assert if the right things are raised. + # Check that it doesn't assert if the right things are raised. with raises_unsupported_algorithm( _Reasons.BACKEND_MISSING_INTERFACE ) as exc_info: |