aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-09-08 14:02:48 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2014-09-08 14:02:48 -0700
commita54d342197e9714ebdea32411488c147220a66f6 (patch)
tree6c84ecfef8ff258adcda2964fa622a36a54b91d2
parent79e51a9b9ce3969c9cc67be655a07cf515dfb1d6 (diff)
downloadcryptography-a54d342197e9714ebdea32411488c147220a66f6.tar.gz
cryptography-a54d342197e9714ebdea32411488c147220a66f6.tar.bz2
cryptography-a54d342197e9714ebdea32411488c147220a66f6.zip
multibacken for docs
-rw-r--r--cryptography/hazmat/backends/multibackend.py15
-rw-r--r--tests/hazmat/backends/test_multibackend.py18
2 files changed, 30 insertions, 3 deletions
diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py
index 6893cad6..221f1a1e 100644
--- a/cryptography/hazmat/backends/multibackend.py
+++ b/cryptography/hazmat/backends/multibackend.py
@@ -17,8 +17,9 @@ from cryptography import utils
from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
from cryptography.hazmat.backends.interfaces import (
CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend,
- HashBackend, PBKDF2HMACBackend, PKCS8SerializationBackend,
- RSABackend, TraditionalOpenSSLSerializationBackend
+ HashBackend, PBKDF2HMACBackend, PEMSerializationBackend,
+ PKCS8SerializationBackend, RSABackend,
+ TraditionalOpenSSLSerializationBackend
)
@@ -32,6 +33,7 @@ from cryptography.hazmat.backends.interfaces import (
@utils.register_interface(TraditionalOpenSSLSerializationBackend)
@utils.register_interface(DSABackend)
@utils.register_interface(EllipticCurveBackend)
+@utils.register_interface(PEMSerializationBackend)
class MultiBackend(object):
name = "multibackend"
@@ -318,6 +320,15 @@ class MultiBackend(object):
_Reasons.UNSUPPORTED_ELLIPTIC_CURVE
)
+ def load_pem_private_key(self, data, password):
+ for b in self._filtered_backends(PEMSerializationBackend):
+ return b.load_pem_private_key(data, password)
+
+ raise UnsupportedAlgorithm(
+ "This backend does not support this key serialization.",
+ _Reasons.UNSUPPORTED_SERIALIZATION
+ )
+
def load_pkcs8_pem_private_key(self, data, password):
for b in self._filtered_backends(PKCS8SerializationBackend):
return b.load_pkcs8_pem_private_key(data, password)
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)