diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-08-29 09:36:09 +0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2016-08-28 21:36:09 -0400 |
commit | 306ce512a28cdba29adf98125d894b90bb6bd78b (patch) | |
tree | 369dd5e4ea6b99638f2750e9f4873439f9545551 /tests/hazmat/primitives/test_hashes.py | |
parent | d6871fe568983b46a3b688c3222289357a7f56cd (diff) | |
download | cryptography-306ce512a28cdba29adf98125d894b90bb6bd78b.tar.gz cryptography-306ce512a28cdba29adf98125d894b90bb6bd78b.tar.bz2 cryptography-306ce512a28cdba29adf98125d894b90bb6bd78b.zip |
blake2b/blake2s support (#3116)
* blake2b/blake2s support
Doesn't support keying, personalization, salting, or tree hashes so
the API is pretty simple right now.
* implement digest_size via utils.read_only_property
* un-keyed for spelling's sake
* test copying + digest_size checks
* unkeyed is too a word
* line wrap
* reword the docs
* use the evp algorithm name in the error
This will make BLAKE2 alternate digest size errors a bit less confusing
* add changelog entry and docs about supported digest_size
Diffstat (limited to 'tests/hazmat/primitives/test_hashes.py')
-rw-r--r-- | tests/hazmat/primitives/test_hashes.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index a109c219..fe96b322 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -159,6 +159,54 @@ class TestMD5(object): ) +@pytest.mark.supported( + only_if=lambda backend: backend.hash_supported( + hashes.BLAKE2b(digest_size=64)), + skip_message="Does not support BLAKE2b", +) +@pytest.mark.requires_backend_interface(interface=HashBackend) +class TestBLAKE2b(object): + test_BLAKE2b = generate_base_hash_test( + hashes.BLAKE2b(digest_size=64), + digest_size=64, + block_size=128, + ) + + def test_invalid_digest_size(self, backend): + with pytest.raises(ValueError): + hashes.BLAKE2b(digest_size=65) + + with pytest.raises(ValueError): + hashes.BLAKE2b(digest_size=0) + + with pytest.raises(ValueError): + hashes.BLAKE2b(digest_size=-1) + + +@pytest.mark.supported( + only_if=lambda backend: backend.hash_supported( + hashes.BLAKE2s(digest_size=32)), + skip_message="Does not support BLAKE2s", +) +@pytest.mark.requires_backend_interface(interface=HashBackend) +class TestBLAKE2s(object): + test_BLAKE2s = generate_base_hash_test( + hashes.BLAKE2s(digest_size=32), + digest_size=32, + block_size=64, + ) + + def test_invalid_digest_size(self, backend): + with pytest.raises(ValueError): + hashes.BLAKE2s(digest_size=33) + + with pytest.raises(ValueError): + hashes.BLAKE2s(digest_size=0) + + with pytest.raises(ValueError): + hashes.BLAKE2s(digest_size=-1) + + def test_invalid_backend(): pretend_backend = object() |