aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichael-hart <michael.hart1994@gmail.com>2014-09-26 00:32:25 +0100
committermichael-hart <michael.hart1994@gmail.com>2014-09-26 18:40:27 +0100
commit801e8c1b88b77e9feb8ad57af166c4b52b15f22a (patch)
tree0e5cabb33f221649e12de0a39fed9f2385d156d2
parentb45731b94d7a50b4b4ca39e6a571fc5c19f509b4 (diff)
downloadcryptography-801e8c1b88b77e9feb8ad57af166c4b52b15f22a.tar.gz
cryptography-801e8c1b88b77e9feb8ad57af166c4b52b15f22a.tar.bz2
cryptography-801e8c1b88b77e9feb8ad57af166c4b52b15f22a.zip
Added all changes lost in merge reset
-rw-r--r--cryptography/hazmat/backends/interfaces.py4
-rw-r--r--docs/hazmat/backends/interfaces.rst6
-rw-r--r--tests/hazmat/backends/test_multibackend.py6
-rw-r--r--tests/hazmat/backends/test_openssl.py2
-rw-r--r--tests/hazmat/primitives/test_serialization.py37
5 files changed, 48 insertions, 7 deletions
diff --git a/cryptography/hazmat/backends/interfaces.py b/cryptography/hazmat/backends/interfaces.py
index 187d7fc5..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.
"""
@@ -303,6 +303,6 @@ class PKCS8SerializationBackend(object):
@abc.abstractmethod
def load_pkcs8_pem_private_key(self, data, password):
"""
- Load a private key from PEM encoded data, using password if the data
+ Load a private key from PKCS8 encoded data, using password if the data
is encrypted.
"""
diff --git a/docs/hazmat/backends/interfaces.rst b/docs/hazmat/backends/interfaces.rst
index f8341d11..e8e1bac2 100644
--- a/docs/hazmat/backends/interfaces.rst
+++ b/docs/hazmat/backends/interfaces.rst
@@ -595,6 +595,12 @@ A specific ``backend`` may provide one or more of these interfaces.
:raises cryptography.exceptions.UnsupportedAlgorithm: If the data is
encrypted with an unsupported algorithm.
+ .. method:: load_pem_public_key(data)
+
+ :param bytes data: PEM data to load.
+ :return: A new instance of the appropriate type of public key serialized data contains.
+ :raises ValueError: If the data could not be deserialized.
+
.. class:: TraditionalOpenSSLSerializationBackend
.. versionadded:: 0.3
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py
index 655acc44..e4a05aae 100644
--- a/tests/hazmat/backends/test_multibackend.py
+++ b/tests/hazmat/backends/test_multibackend.py
@@ -217,6 +217,9 @@ class DummyPEMSerializationBackend(object):
def load_pem_private_key(self, data, password):
pass
+ def load_pem_public_key(self, data):
+ pass
+
class TestMultiBackend(object):
def test_ciphers(self):
@@ -532,7 +535,10 @@ class TestMultiBackend(object):
backend = MultiBackend([DummyPEMSerializationBackend()])
backend.load_pem_private_key(b"keydata", None)
+ backend.load_pem_public_key(b"keydata")
backend = MultiBackend([])
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_SERIALIZATION):
backend.load_pem_private_key(b"keydata", None)
+ with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_SERIALIZATION):
+ backend.load_pem_public_key(b"keydata")
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index cf70f109..d4c5e2e7 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -473,6 +473,8 @@ class TestOpenSSLSerialisationWithOpenSSL(object):
key = pretend.stub(type="unsupported")
with raises_unsupported_algorithm(None):
backend._evp_pkey_to_private_key(key)
+ with raises_unsupported_algorithm(None):
+ backend._evp_pkey_to_public_key(key)
def test_very_long_pem_serialization_password(self):
password = "x" * 1024
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):