Merge pull request #601 from dreid/confusing-padding-example
Don't throw away the result of padder.update because it confuses users.
diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py
index 49a4014..4de0202 100644
--- a/cryptography/hazmat/backends/multibackend.py
+++ b/cryptography/hazmat/backends/multibackend.py
@@ -16,7 +16,7 @@
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 @@
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 ca21c9f..ce77ce2 100644
--- a/tests/hazmat/backends/test_multibackend.py
+++ b/tests/hazmat/backends/test_multibackend.py
@@ -16,7 +16,7 @@
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 @@
@utils.register_interface(PBKDF2HMACBackend)
-class DummyPBKDF2HMAC(object):
+class DummyPBKDF2HMACBackend(object):
def __init__(self, supported_algorithms):
self._algorithms = supported_algorithms
@@ -80,6 +80,12 @@
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):
backend = MultiBackend([
@@ -134,7 +140,7 @@
def test_pbkdf2(self):
backend = MultiBackend([
- DummyPBKDF2HMAC([hashes.MD5])
+ DummyPBKDF2HMACBackend([hashes.MD5])
])
assert backend.pbkdf2_hmac_supported(hashes.MD5())
@@ -142,3 +148,16 @@
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)