diff options
author | Donald Stufft <donald@stufft.io> | 2013-10-18 20:00:20 -0700 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2013-10-18 20:00:20 -0700 |
commit | 1494e3e1ffb192b9c55d200a6346879ca2fe1a8b (patch) | |
tree | 666e3ccb3978d1eb915516937e2fe54127c43649 /tests/primitives | |
parent | 617c0c7e6f89271373f3f15ee05d16c80c8bdd5e (diff) | |
parent | c179407406f0ef5c2b7b5b6316521408ba3803b3 (diff) | |
download | cryptography-1494e3e1ffb192b9c55d200a6346879ca2fe1a8b.tar.gz cryptography-1494e3e1ffb192b9c55d200a6346879ca2fe1a8b.tar.bz2 cryptography-1494e3e1ffb192b9c55d200a6346879ca2fe1a8b.zip |
Merge pull request #125 from reaperhulk/hash-saga-ripeness
Hash Saga Part 5 (RIPEMD160 support)
Diffstat (limited to 'tests/primitives')
-rw-r--r-- | tests/primitives/test_hash_vectors.py | 22 | ||||
-rw-r--r-- | tests/primitives/test_hashes.py | 10 | ||||
-rw-r--r-- | tests/primitives/test_utils.py | 14 | ||||
-rw-r--r-- | tests/primitives/utils.py | 23 |
4 files changed, 67 insertions, 2 deletions
diff --git a/tests/primitives/test_hash_vectors.py b/tests/primitives/test_hash_vectors.py index d0fe46d1..51c4b85d 100644 --- a/tests/primitives/test_hash_vectors.py +++ b/tests/primitives/test_hash_vectors.py @@ -17,7 +17,7 @@ import os from cryptography.primitives import hashes -from .utils import generate_hash_test +from .utils import generate_hash_test, generate_long_string_hash_test from ..utils import load_hash_vectors_from_file @@ -89,3 +89,23 @@ class TestSHA512(object): only_if=lambda api: api.supports_hash(hashes.SHA512), skip_message="Does not support SHA512", ) + + +class TestRIPEMD160(object): + test_RIPEMD160 = generate_hash_test( + load_hash_vectors_from_file, + os.path.join("ISO", "ripemd160"), + [ + "ripevectors.txt", + ], + hashes.RIPEMD160, + only_if=lambda api: api.supports_hash(hashes.RIPEMD160), + skip_message="Does not support RIPEMD160", + ) + + test_RIPEMD160_long_string = generate_long_string_hash_test( + hashes.RIPEMD160, + "52783243c1697bdbe16d37f97f68f08325dc1528", + only_if=lambda api: api.supports_hash(hashes.RIPEMD160), + skip_message="Does not support RIPEMD160", + ) diff --git a/tests/primitives/test_hashes.py b/tests/primitives/test_hashes.py index 2f2dd1c7..bfb45037 100644 --- a/tests/primitives/test_hashes.py +++ b/tests/primitives/test_hashes.py @@ -66,3 +66,13 @@ class TestSHA512(object): only_if=lambda api: api.supports_hash(hashes.SHA512), skip_message="Does not support SHA512", ) + + +class TestRIPEMD160(object): + test_RIPEMD160 = generate_base_hash_test( + hashes.RIPEMD160, + digest_size=20, + block_size=64, + only_if=lambda api: api.supports_hash(hashes.RIPEMD160), + skip_message="Does not support RIPEMD160", + ) diff --git a/tests/primitives/test_utils.py b/tests/primitives/test_utils.py index 43ec8a71..9888309e 100644 --- a/tests/primitives/test_utils.py +++ b/tests/primitives/test_utils.py @@ -1,6 +1,7 @@ import pytest -from .utils import encrypt_test, hash_test, base_hash_test +from .utils import (base_hash_test, encrypt_test, hash_test, + long_string_hash_test) class TestEncryptTest(object): @@ -34,3 +35,14 @@ class TestBaseHashTest(object): skip_message="message!" ) assert exc_info.value.args[0] == "message!" + + +class TestLongHashTest(object): + def test_skips_if_only_if_returns_false(self): + with pytest.raises(pytest.skip.Exception) as exc_info: + long_string_hash_test( + None, None, None, + only_if=lambda api: False, + skip_message="message!" + ) + assert exc_info.value.args[0] == "message!" diff --git a/tests/primitives/utils.py b/tests/primitives/utils.py index 0d4c0eb3..8b32700b 100644 --- a/tests/primitives/utils.py +++ b/tests/primitives/utils.py @@ -95,3 +95,26 @@ def base_hash_test(api, hash_cls, digest_size, block_size, only_if, m_copy = m.copy() assert m != m_copy assert m._ctx != m_copy._ctx + + +def generate_long_string_hash_test(hash_factory, md, only_if=lambda api: True, + skip_message=None): + def test_long_string_hash(self): + for api in _ALL_APIS: + yield( + long_string_hash_test, + api, + hash_factory, + md, + only_if, + skip_message + ) + return test_long_string_hash + + +def long_string_hash_test(api, hash_factory, md, only_if, skip_message): + if not only_if(api): + pytest.skip(skip_message) + m = hash_factory(api) + m.update(b"a" * 1000000) + assert m.hexdigest() == md.lower() |