aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-02-23 15:09:56 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-02-23 15:09:56 -0600
commitdff1d43d0ae65da599eb60f99d411112b39fc8e9 (patch)
tree9ee18e09ac73a84855dc42b7188a3a8a21344b11
parenta33df8ed655b507e72bdb4aab377dcf7a81954c5 (diff)
downloadcryptography-dff1d43d0ae65da599eb60f99d411112b39fc8e9.tar.gz
cryptography-dff1d43d0ae65da599eb60f99d411112b39fc8e9.tar.bz2
cryptography-dff1d43d0ae65da599eb60f99d411112b39fc8e9.zip
add basic multibackend so we can do signatures using default_backend
-rw-r--r--cryptography/hazmat/backends/multibackend.py7
-rw-r--r--tests/hazmat/backends/test_multibackend.py11
2 files changed, 18 insertions, 0 deletions
diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py
index 4de02026..eb58dd68 100644
--- a/cryptography/hazmat/backends/multibackend.py
+++ b/cryptography/hazmat/backends/multibackend.py
@@ -24,6 +24,7 @@ from cryptography.hazmat.backends.interfaces import (
@utils.register_interface(HashBackend)
@utils.register_interface(HMACBackend)
@utils.register_interface(PBKDF2HMACBackend)
+@utils.register_interface(RSABackend)
class MultiBackend(object):
name = "multibackend"
@@ -106,3 +107,9 @@ class MultiBackend(object):
for b in self._filtered_backends(RSABackend):
return b.generate_rsa_private_key(public_exponent, key_size)
raise UnsupportedAlgorithm
+
+ def create_rsa_signature_ctx(self, private_key, padding, algorithm):
+ for b in self._filtered_backends(RSABackend):
+ return b.create_rsa_signature_ctx(private_key, padding, algorithm)
+ raise UnsupportedAlgorithm
+
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py
index ce77ce2f..e3f83d3a 100644
--- a/tests/hazmat/backends/test_multibackend.py
+++ b/tests/hazmat/backends/test_multibackend.py
@@ -20,6 +20,7 @@ from cryptography.hazmat.backends.interfaces import (
)
from cryptography.hazmat.backends.multibackend import MultiBackend
from cryptography.hazmat.primitives import hashes, hmac
+from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
@@ -85,6 +86,9 @@ class DummyRSABackend(object):
def generate_rsa_private_key(self, public_exponent, private_key):
pass
+ def create_rsa_signature_ctx(self, private_key, padding, algorithm):
+ pass
+
class TestMultiBackend(object):
def test_ciphers(self):
@@ -158,6 +162,13 @@ class TestMultiBackend(object):
key_size=1024, public_exponent=65537
)
+ backend.create_rsa_signature_ctx("private_key", padding.PKCS1(),
+ hashes.MD5())
+
backend = MultiBackend([])
with pytest.raises(UnsupportedAlgorithm):
backend.generate_rsa_private_key(key_size=1024, public_exponent=3)
+
+ with pytest.raises(UnsupportedAlgorithm):
+ backend.create_rsa_signature_ctx("private_key", padding.PKCS1(),
+ hashes.MD5())