diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-05-01 15:47:24 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-05-02 08:48:29 -0500 |
commit | 29c3008aa12d845850aae6d8f52aee6d3609dda0 (patch) | |
tree | 64e7899946d829f10ff70431ece9ebb66b18ae8c | |
parent | d80ff2d3a6a443e5aea217d6bc3d356dab2b99b4 (diff) | |
download | cryptography-29c3008aa12d845850aae6d8f52aee6d3609dda0.tar.gz cryptography-29c3008aa12d845850aae6d8f52aee6d3609dda0.tar.bz2 cryptography-29c3008aa12d845850aae6d8f52aee6d3609dda0.zip |
expand DSA multibackend support
-rw-r--r-- | cryptography/hazmat/backends/multibackend.py | 25 | ||||
-rw-r--r-- | tests/hazmat/backends/test_multibackend.py | 34 |
2 files changed, 59 insertions, 0 deletions
diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py index 981a60bd..753f4fc6 100644 --- a/cryptography/hazmat/backends/multibackend.py +++ b/cryptography/hazmat/backends/multibackend.py @@ -158,6 +158,31 @@ class MultiBackend(object): raise UnsupportedAlgorithm("DSA is not supported by the backend", _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM) + def create_dsa_verification_ctx(self, public_key, signature, algorithm): + for b in self._filtered_backends(DSABackend): + return b.create_dsa_verification_ctx(public_key, signature, + algorithm) + raise UnsupportedAlgorithm("DSA is not supported by the backend", + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM) + + def create_dsa_signature_ctx(self, private_key, algorithm): + for b in self._filtered_backends(DSABackend): + return b.create_dsa_signature_ctx(private_key, algorithm) + raise UnsupportedAlgorithm("DSA is not supported by the backend", + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM) + + def dsa_hash_supported(self, algorithm): + for b in self._filtered_backends(DSABackend): + return b.dsa_hash_supported(algorithm) + raise UnsupportedAlgorithm("DSA is not supported by the backend", + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM) + + def dsa_parameters_supported(self, p, q, g): + for b in self._filtered_backends(DSABackend): + return b.dsa_parameters_supported(p, q, g) + raise UnsupportedAlgorithm("DSA is not supported by the backend", + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM) + def cmac_algorithm_supported(self, algorithm): return any( b.cmac_algorithm_supported(algorithm) diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index d8c09bd7..c31b235e 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -107,6 +107,18 @@ class DummyDSABackend(object): def generate_dsa_private_key(self, parameters): pass + def create_dsa_signature_ctx(self, private_key, algorithm): + pass + + def create_dsa_verification_ctx(self, public_key, signature, algorithm): + pass + + def dsa_hash_supported(self, algorithm): + pass + + def dsa_parameters_supported(self, p, q, g): + pass + @utils.register_interface(CMACBackend) class DummyCMACBackend(object): @@ -238,6 +250,28 @@ class TestMultiBackend(object): ): backend.generate_dsa_private_key(parameters) + with raises_unsupported_algorithm( + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM + ): + backend.create_dsa_signature_ctx("private_key", hashes.SHA1()) + + with raises_unsupported_algorithm( + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM + ): + backend.create_dsa_verification_ctx( + "public_key", b"sig", hashes.SHA1() + ) + + with raises_unsupported_algorithm( + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM + ): + backend.dsa_hash_supported(hashes.SHA1()) + + with raises_unsupported_algorithm( + _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM + ): + backend.dsa_parameters_supported('p', 'q', 'g') + def test_cmac(self): backend = MultiBackend([ DummyCMACBackend([algorithms.AES]) |