diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2014-01-30 11:58:40 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2014-01-30 11:58:40 -0800 |
commit | 87899d4fd55881a4dbec1ee32b79a5bd315ec33f (patch) | |
tree | c7b97590702b54dcd339fe3f20c188f5f470087f /tests/hazmat/backends/test_multibackend.py | |
parent | 6ced2f6444c956b88d42cc61fe9a38751b912c9a (diff) | |
download | cryptography-87899d4fd55881a4dbec1ee32b79a5bd315ec33f.tar.gz cryptography-87899d4fd55881a4dbec1ee32b79a5bd315ec33f.tar.bz2 cryptography-87899d4fd55881a4dbec1ee32b79a5bd315ec33f.zip |
Direct tests for the hash support
Diffstat (limited to 'tests/hazmat/backends/test_multibackend.py')
-rw-r--r-- | tests/hazmat/backends/test_multibackend.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index dc58a585..f300b6c8 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -15,6 +15,7 @@ import pytest from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.backends.multibackend import PrioritizedMultiBackend +from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes @@ -34,6 +35,19 @@ class DummyCipherBackend(object): raise UnsupportedAlgorithm +class DummyHashBackend(object): + def __init__(self, supported_algorithms): + self._algorithms = supported_algorithms + + def hash_supported(self, algorithm): + return type(algorithm) in self._algorithms + + def create_hash_ctx(self, algorithm): + if not self.hash_supported(algorithm): + raise UnsupportedAlgorithm + + + class TestPrioritizedMultiBackend(object): def test_ciphers(self): backend = PrioritizedMultiBackend([ @@ -62,3 +76,14 @@ class TestPrioritizedMultiBackend(object): cipher.encryptor() with pytest.raises(UnsupportedAlgorithm): cipher.decryptor() + + def test_hashes(self): + backend = PrioritizedMultiBackend([ + DummyHashBackend([hashes.MD5]) + ]) + assert backend.hash_supported(hashes.MD5()) + + hashes.Hash(hashes.MD5(), backend=backend) + + with pytest.raises(UnsupportedAlgorithm): + hashes.Hash(hashes.SHA1(), backend=backend) |