aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-02-12 10:07:44 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2014-02-12 10:07:44 -0800
commit0d22bf4a20433916dfb11a1f2aba9182ccbe0f5f (patch)
treedda0db9a3b7e6ed071e78d5b6612d16636ad1220
parentd0f37ea8da57daf9f4f9d60490d1aa3c41dd8845 (diff)
downloadcryptography-0d22bf4a20433916dfb11a1f2aba9182ccbe0f5f.tar.gz
cryptography-0d22bf4a20433916dfb11a1f2aba9182ccbe0f5f.tar.bz2
cryptography-0d22bf4a20433916dfb11a1f2aba9182ccbe0f5f.zip
Added RSABackend to MultiBackend
-rw-r--r--cryptography/hazmat/backends/multibackend.py7
-rw-r--r--tests/hazmat/backends/test_multibackend.py24
2 files changed, 27 insertions, 4 deletions
diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py
index 49a4014d..4de02026 100644
--- a/cryptography/hazmat/backends/multibackend.py
+++ b/cryptography/hazmat/backends/multibackend.py
@@ -16,7 +16,7 @@ from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.backends.interfaces import (
- CipherBackend, HashBackend, HMACBackend, PBKDF2HMACBackend
+ CipherBackend, HashBackend, HMACBackend, PBKDF2HMACBackend, RSABackend
)
@@ -101,3 +101,8 @@ class MultiBackend(object):
except UnsupportedAlgorithm:
pass
raise UnsupportedAlgorithm
+
+ def generate_rsa_private_key(self, public_exponent, key_size):
+ for b in self._filtered_backends(RSABackend):
+ return b.generate_rsa_private_key(public_exponent, key_size)
+ raise UnsupportedAlgorithm
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py
index ca21c9fc..eca9627c 100644
--- a/tests/hazmat/backends/test_multibackend.py
+++ b/tests/hazmat/backends/test_multibackend.py
@@ -16,7 +16,7 @@ import pytest
from cryptography import utils
from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.backends.interfaces import (
- CipherBackend, HashBackend, HMACBackend, PBKDF2HMACBackend
+ CipherBackend, HashBackend, HMACBackend, PBKDF2HMACBackend, RSABackend
)
from cryptography.hazmat.backends.multibackend import MultiBackend
from cryptography.hazmat.primitives import hashes, hmac
@@ -67,7 +67,7 @@ class DummyHMACBackend(object):
@utils.register_interface(PBKDF2HMACBackend)
-class DummyPBKDF2HMAC(object):
+class DummyPBKDF2HMACBackend(object):
def __init__(self, supported_algorithms):
self._algorithms = supported_algorithms
@@ -79,6 +79,11 @@ class DummyPBKDF2HMAC(object):
if not self.pbkdf2_hmac_supported(algorithm):
raise UnsupportedAlgorithm
+@utils.register_interface(RSABackend)
+class DummyRSABackend(object):
+ def generate_rsa_private_key(self, public_exponent, private_key):
+ pass
+
class TestMultiBackend(object):
def test_ciphers(self):
@@ -134,7 +139,7 @@ class TestMultiBackend(object):
def test_pbkdf2(self):
backend = MultiBackend([
- DummyPBKDF2HMAC([hashes.MD5])
+ DummyPBKDF2HMACBackend([hashes.MD5])
])
assert backend.pbkdf2_hmac_supported(hashes.MD5())
@@ -142,3 +147,16 @@ class TestMultiBackend(object):
with pytest.raises(UnsupportedAlgorithm):
backend.derive_pbkdf2_hmac(hashes.SHA1(), 10, b"", 10, b"")
+
+ def test_rsa(self):
+ backend = MultiBackend([
+ DummyRSABackend()
+ ])
+
+ backend.generate_rsa_private_key(
+ key_size=1024, public_exponent=65537
+ )
+
+ backend = MultiBackend([])
+ with pytest.raises(UnsupportedAlgorithm):
+ backend.generate_rsa_private_key(key_size=1024, public_exponent=3)