From f0ca2e8bf0eaaba32ea0fe1a608c2a5c6348f5fa Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 8 Sep 2014 11:40:48 -0700 Subject: Start moving everything to the new API --- tests/hazmat/primitives/test_serialization.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 30ac4f3d..e960878b 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -22,15 +22,33 @@ import pytest from cryptography.exceptions import _Reasons from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.serialization import ( - load_pem_pkcs8_private_key, load_pem_traditional_openssl_private_key + load_pem_private_key, load_pem_pkcs8_private_key, + load_pem_traditional_openssl_private_key ) from .utils import _check_rsa_private_numbers, load_vectors_from_file from ...utils import raises_unsupported_algorithm +@pytest.mark.pem_serialization +class TestPEMSerialization(object): + def test_load_pem_rsa_private_key(self, backend): + key = load_vectors_from_file( + os.path.join( + "asymmetric", "Traditional_OpenSSL_Serialization", "key1.pem"), + lambda pemfile: load_pem_private_key( + pemfile.read().encode(), b"123456", backend + ) + ) + + assert key + assert isinstance(key, interfaces.RSAPrivateKey) + if isinstance(key, interfaces.RSAPrivateKeyWithNumbers): + _check_rsa_private_numbers(key.private_numbers()) + + @pytest.mark.traditional_openssl_serialization -class TestTraditionalOpenSSLSerialisation(object): +class TestTraditionalOpenSSLSerialization(object): @pytest.mark.parametrize( ("key_file", "password"), [ @@ -252,7 +270,7 @@ class TestTraditionalOpenSSLSerialisation(object): @pytest.mark.pkcs8_serialization -class TestPKCS8Serialisation(object): +class TestPKCS8Serialization(object): @pytest.mark.parametrize( ("key_file", "password"), [ -- cgit v1.2.3 From e53677a149b646deb2be1d6ffbd3e27a960b2f8c Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 8 Sep 2014 12:43:02 -0700 Subject: fixes --- tests/conftest.py | 4 +++- tests/hazmat/primitives/test_serialization.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index af146386..b7981c9d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,7 +18,8 @@ import pytest from cryptography.hazmat.backends import _available_backends from cryptography.hazmat.backends.interfaces import ( CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend, - HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend, RSABackend, + HashBackend, PBKDF2HMACBackend, PEMSerializationBackend, + PKCS8SerializationBackend, RSABackend, TraditionalOpenSSLSerializationBackend ) from .utils import check_backend_support, check_for_iface, select_backends @@ -48,6 +49,7 @@ def pytest_runtest_setup(item): ) check_for_iface("pkcs8_serialization", PKCS8SerializationBackend, item) check_for_iface("elliptic", EllipticCurveBackend, item) + check_for_iface("pem_serialization", PEMSerializationBackend, item) check_backend_support(item) diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index e960878b..9333a6bd 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -22,7 +22,7 @@ import pytest from cryptography.exceptions import _Reasons from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.serialization import ( - load_pem_private_key, load_pem_pkcs8_private_key, + load_pem_pkcs8_private_key, load_pem_private_key, load_pem_traditional_openssl_private_key ) -- cgit v1.2.3 From a54d342197e9714ebdea32411488c147220a66f6 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 8 Sep 2014 14:02:48 -0700 Subject: multibacken for docs --- tests/hazmat/backends/test_multibackend.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index 168ed688..655acc44 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -19,7 +19,8 @@ from cryptography.exceptions import ( ) from cryptography.hazmat.backends.interfaces import ( CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend, - HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend, RSABackend, + HashBackend, PBKDF2HMACBackend, PEMSerializationBackend, + PKCS8SerializationBackend, RSABackend, TraditionalOpenSSLSerializationBackend ) from cryptography.hazmat.backends.multibackend import MultiBackend @@ -211,6 +212,12 @@ class DummyTraditionalOpenSSLSerializationBackend(object): pass +@utils.register_interface(PEMSerializationBackend) +class DummyPEMSerializationBackend(object): + def load_pem_private_key(self, data, password): + pass + + class TestMultiBackend(object): def test_ciphers(self): backend = MultiBackend([ @@ -520,3 +527,12 @@ class TestMultiBackend(object): backend = MultiBackend([]) with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_SERIALIZATION): backend.load_traditional_openssl_pem_private_key(b"keydata", None) + + def test_pem_serialization_backend(self): + backend = MultiBackend([DummyPEMSerializationBackend()]) + + backend.load_pem_private_key(b"keydata", None) + + backend = MultiBackend([]) + with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_SERIALIZATION): + backend.load_pem_private_key(b"keydata", None) -- cgit v1.2.3