From 0d22bf4a20433916dfb11a1f2aba9182ccbe0f5f Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 12 Feb 2014 10:07:44 -0800 Subject: Added RSABackend to MultiBackend --- tests/hazmat/backends/test_multibackend.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'tests/hazmat/backends/test_multibackend.py') 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) -- cgit v1.2.3 From e7bdb1b3e76346d4e0aa7cbf2291e6f25e7b43b3 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 12 Feb 2014 10:33:24 -0800 Subject: flake8 fix --- tests/hazmat/backends/test_multibackend.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/hazmat/backends/test_multibackend.py') diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index eca9627c..ce77ce2f 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -79,6 +79,7 @@ class DummyPBKDF2HMACBackend(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): -- cgit v1.2.3