From 254811fd619188610298485a66885784944c1de8 Mon Sep 17 00:00:00 2001 From: michael-hart Date: Fri, 26 Sep 2014 00:32:25 +0100 Subject: Added all changes lost in merge reset --- cryptography/hazmat/backends/interfaces.py | 2 +- tests/hazmat/backends/test_multibackend.py | 2 +- tests/hazmat/primitives/test_serialization.py | 37 +++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cryptography/hazmat/backends/interfaces.py b/cryptography/hazmat/backends/interfaces.py index f3d64820..dc720ad3 100644 --- a/cryptography/hazmat/backends/interfaces.py +++ b/cryptography/hazmat/backends/interfaces.py @@ -282,7 +282,7 @@ class PEMSerializationBackend(object): """ @abc.abstractmethod - def load_pem_public_key(self, data, password): + def load_pem_public_key(self, data): """ Loads a public key from PEM encoded data. """ diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index 45c12b34..e4a05aae 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -218,7 +218,7 @@ class DummyPEMSerializationBackend(object): pass def load_pem_public_key(self, data): - pass + pass class TestMultiBackend(object): diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 4bc7e811..2ee096be 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -82,21 +82,40 @@ class TestPEMSerialization(object): assert key assert isinstance(key, interfaces.EllipticCurvePrivateKey) - def test_load_pem_rsa_public_key(self, backend): - key = load_vectors_from_file( + @pytest.mark.parametrize( + ("key_file"), + [ + os.path.join("asymmetric", "PKCS8", "unenc-rsa-pkcs8.pub.pem"), os.path.join( "asymmetric", "PEM_Serialization", "rsa_public_key.pem"), + ), + ] + ) + def test_load_pem_rsa_public_key(self, key_file, backend): + key = load_vectors_from_file( + key_file, lambda pemfile: load_pem_public_key( pemfile.read().encode(), backend ) ) assert key assert isinstance(key, interfaces.RSAPublicKey) + if isinstance(key, interfaces.RSAPublicKeyWithNumbers): + numbers = key.public_numbers() + assert numbers.e == 65537 - def test_load_pem_dsa_public_key(self, backend): + @pytest.mark.parametrize( + ("key_file"), + [ + os.path.join("asymmetric", "PKCS8", "unenc-dsa-pkcs8.pub.pem"), + os.path.join( + "asymmetric", "PEM_Serialization", + "dsa_public_key.pem" +), ), + ] + def test_load_pem_dsa_public_key(self, keyfile, backend): key = load_vectors_from_file( - os.path.join( - "asymmetric", "PEM_Serialization", "dsa_public_key.pem"), + keyfile, lambda pemfile: load_pem_public_key( pemfile.read().encode(), backend ) @@ -104,6 +123,14 @@ class TestPEMSerialization(object): assert key assert isinstance(key, interfaces.DSAPublicKey) + def test_load_pem_ec_public_key(self, backend): + key = load_vectors_from_file( + os.path.join("asymmetric", "PEM_Serialization", + "ec_public_key.pem"), + lambda pemfile: load_pem_public_key( + pemfile.read().encode(), backend + ) + ) @pytest.mark.traditional_openssl_serialization class TestTraditionalOpenSSLSerialization(object): -- cgit v1.2.3