diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-11 20:43:52 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-11-11 20:43:52 -0600 |
commit | f7f6a9f77ade1b190766c37cc8967375b5093175 (patch) | |
tree | ccaf9bcf7033a58c9e55f2996b328f108da66c1b /tests/hazmat | |
parent | 92beb221fc0a1bd8ef1b955a98e1385daed0f207 (diff) | |
download | cryptography-f7f6a9f77ade1b190766c37cc8967375b5093175.tar.gz cryptography-f7f6a9f77ade1b190766c37cc8967375b5093175.tar.bz2 cryptography-f7f6a9f77ade1b190766c37cc8967375b5093175.zip |
Remove separate file loaders and replace with one
All tests updated to work with the new simplified loader
Diffstat (limited to 'tests/hazmat')
-rw-r--r-- | tests/hazmat/primitives/test_3des.py | 14 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_aes.py | 12 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_arc4.py | 4 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_blowfish.py | 10 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_camellia.py | 10 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_cast5.py | 4 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_hash_vectors.py | 18 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_hmac_vectors.py | 16 | ||||
-rw-r--r-- | tests/hazmat/primitives/utils.py | 22 |
9 files changed, 62 insertions, 48 deletions
diff --git a/tests/hazmat/primitives/test_3des.py b/tests/hazmat/primitives/test_3des.py index 1543cfd7..69ec9c9a 100644 --- a/tests/hazmat/primitives/test_3des.py +++ b/tests/hazmat/primitives/test_3des.py @@ -23,12 +23,12 @@ import os from cryptography.hazmat.primitives.ciphers import algorithms, modes from .utils import generate_encrypt_test -from ...utils import load_nist_vectors_from_file +from ...utils import load_nist_vectors class TestTripleDES_CBC(object): test_KAT = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "3DES", "CBC"), [ "TCBCinvperm.rsp", @@ -42,7 +42,7 @@ class TestTripleDES_CBC(object): ) test_MMT = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "3DES", "CBC"), [ "TCBCMMT1.rsp", @@ -58,7 +58,7 @@ class TestTripleDES_CBC(object): class TestTripleDES_OFB(object): test_KAT = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "3DES", "OFB"), [ "TOFBpermop.rsp", @@ -72,7 +72,7 @@ class TestTripleDES_OFB(object): ) test_MMT = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "3DES", "OFB"), [ "TOFBMMT1.rsp", @@ -88,7 +88,7 @@ class TestTripleDES_OFB(object): class TestTripleDES_CFB(object): test_KAT = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "3DES", "CFB"), [ "TCFB64invperm.rsp", @@ -102,7 +102,7 @@ class TestTripleDES_CFB(object): ) test_MMT = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "3DES", "CFB"), [ "TCFB64MMT1.rsp", diff --git a/tests/hazmat/primitives/test_aes.py b/tests/hazmat/primitives/test_aes.py index c4818409..7c8cab72 100644 --- a/tests/hazmat/primitives/test_aes.py +++ b/tests/hazmat/primitives/test_aes.py @@ -20,13 +20,13 @@ from cryptography.hazmat.primitives.ciphers import algorithms, modes from .utils import generate_encrypt_test from ...utils import ( - load_nist_vectors_from_file, load_openssl_vectors_from_file + load_nist_vectors, load_openssl_vectors, ) class TestAES(object): test_CBC = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "AES", "CBC"), [ "CBCGFSbox128.rsp", @@ -50,7 +50,7 @@ class TestAES(object): ) test_ECB = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "AES", "ECB"), [ "ECBGFSbox128.rsp", @@ -74,7 +74,7 @@ class TestAES(object): ) test_OFB = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "AES", "OFB"), [ "OFBGFSbox128.rsp", @@ -98,7 +98,7 @@ class TestAES(object): ) test_CFB = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "AES", "CFB"), [ "CFB128GFSbox128.rsp", @@ -122,7 +122,7 @@ class TestAES(object): ) test_CTR = generate_encrypt_test( - load_openssl_vectors_from_file, + load_openssl_vectors, os.path.join("ciphers", "AES", "CTR"), ["aes-128-ctr.txt", "aes-192-ctr.txt", "aes-256-ctr.txt"], lambda key, iv: algorithms.AES(binascii.unhexlify(key)), diff --git a/tests/hazmat/primitives/test_arc4.py b/tests/hazmat/primitives/test_arc4.py index 71b5d63a..302658f6 100644 --- a/tests/hazmat/primitives/test_arc4.py +++ b/tests/hazmat/primitives/test_arc4.py @@ -19,12 +19,12 @@ import os from cryptography.hazmat.primitives.ciphers import algorithms from .utils import generate_stream_encryption_test -from ...utils import load_nist_vectors_from_file +from ...utils import load_nist_vectors class TestARC4(object): test_rfc = generate_stream_encryption_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "ARC4"), [ "rfc-6229-40.txt", diff --git a/tests/hazmat/primitives/test_blowfish.py b/tests/hazmat/primitives/test_blowfish.py index 6f670ad7..eea0ac33 100644 --- a/tests/hazmat/primitives/test_blowfish.py +++ b/tests/hazmat/primitives/test_blowfish.py @@ -19,12 +19,12 @@ import os from cryptography.hazmat.primitives.ciphers import algorithms, modes from .utils import generate_encrypt_test -from ...utils import load_nist_vectors_from_file +from ...utils import load_nist_vectors class TestBlowfish(object): test_ECB = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "Blowfish"), ["bf-ecb.txt"], lambda key: algorithms.Blowfish(binascii.unhexlify(key)), @@ -36,7 +36,7 @@ class TestBlowfish(object): ) test_CBC = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "Blowfish"), ["bf-cbc.txt"], lambda key, iv: algorithms.Blowfish(binascii.unhexlify(key)), @@ -48,7 +48,7 @@ class TestBlowfish(object): ) test_OFB = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "Blowfish"), ["bf-ofb.txt"], lambda key, iv: algorithms.Blowfish(binascii.unhexlify(key)), @@ -60,7 +60,7 @@ class TestBlowfish(object): ) test_CFB = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "Blowfish"), ["bf-cfb.txt"], lambda key, iv: algorithms.Blowfish(binascii.unhexlify(key)), diff --git a/tests/hazmat/primitives/test_camellia.py b/tests/hazmat/primitives/test_camellia.py index e1be5d1d..223269a2 100644 --- a/tests/hazmat/primitives/test_camellia.py +++ b/tests/hazmat/primitives/test_camellia.py @@ -20,13 +20,13 @@ from cryptography.hazmat.primitives.ciphers import algorithms, modes from .utils import generate_encrypt_test from ...utils import ( - load_cryptrec_vectors_from_file, load_openssl_vectors_from_file + load_cryptrec_vectors, load_openssl_vectors ) class TestCamellia(object): test_ECB = generate_encrypt_test( - load_cryptrec_vectors_from_file, + load_cryptrec_vectors, os.path.join("ciphers", "Camellia"), [ "camellia-128-ecb.txt", @@ -42,7 +42,7 @@ class TestCamellia(object): ) test_CBC = generate_encrypt_test( - load_openssl_vectors_from_file, + load_openssl_vectors, os.path.join("ciphers", "Camellia"), ["camellia-cbc.txt"], lambda key, iv: algorithms.Camellia(binascii.unhexlify(key)), @@ -54,7 +54,7 @@ class TestCamellia(object): ) test_OFB = generate_encrypt_test( - load_openssl_vectors_from_file, + load_openssl_vectors, os.path.join("ciphers", "Camellia"), ["camellia-ofb.txt"], lambda key, iv: algorithms.Camellia(binascii.unhexlify(key)), @@ -66,7 +66,7 @@ class TestCamellia(object): ) test_CFB = generate_encrypt_test( - load_openssl_vectors_from_file, + load_openssl_vectors, os.path.join("ciphers", "Camellia"), ["camellia-cfb.txt"], lambda key, iv: algorithms.Camellia(binascii.unhexlify(key)), diff --git a/tests/hazmat/primitives/test_cast5.py b/tests/hazmat/primitives/test_cast5.py index 4256e2c4..486b5b5a 100644 --- a/tests/hazmat/primitives/test_cast5.py +++ b/tests/hazmat/primitives/test_cast5.py @@ -19,12 +19,12 @@ import os from cryptography.hazmat.primitives.ciphers import algorithms, modes from .utils import generate_encrypt_test -from ...utils import load_nist_vectors_from_file +from ...utils import load_nist_vectors class TestCAST5(object): test_ECB = generate_encrypt_test( - lambda path: load_nist_vectors_from_file(path), + load_nist_vectors, os.path.join("ciphers", "CAST5"), ["cast5-ecb.txt"], lambda key: algorithms.CAST5(binascii.unhexlify((key))), diff --git a/tests/hazmat/primitives/test_hash_vectors.py b/tests/hazmat/primitives/test_hash_vectors.py index fca839c7..b08beca6 100644 --- a/tests/hazmat/primitives/test_hash_vectors.py +++ b/tests/hazmat/primitives/test_hash_vectors.py @@ -18,12 +18,12 @@ import os from cryptography.hazmat.primitives import hashes from .utils import generate_hash_test, generate_long_string_hash_test -from ...utils import load_hash_vectors_from_file +from ...utils import load_hash_vectors class TestSHA1(object): test_SHA1 = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "SHA1"), [ "SHA1LongMsg.rsp", @@ -37,7 +37,7 @@ class TestSHA1(object): class TestSHA224(object): test_SHA224 = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "SHA2"), [ "SHA224LongMsg.rsp", @@ -51,7 +51,7 @@ class TestSHA224(object): class TestSHA256(object): test_SHA256 = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "SHA2"), [ "SHA256LongMsg.rsp", @@ -65,7 +65,7 @@ class TestSHA256(object): class TestSHA384(object): test_SHA384 = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "SHA2"), [ "SHA384LongMsg.rsp", @@ -79,7 +79,7 @@ class TestSHA384(object): class TestSHA512(object): test_SHA512 = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "SHA2"), [ "SHA512LongMsg.rsp", @@ -93,7 +93,7 @@ class TestSHA512(object): class TestRIPEMD160(object): test_RIPEMD160 = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "ripemd160"), [ "ripevectors.txt", @@ -113,7 +113,7 @@ class TestRIPEMD160(object): class TestWhirlpool(object): test_whirlpool = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "whirlpool"), [ "iso-test-vectors.txt", @@ -135,7 +135,7 @@ class TestWhirlpool(object): class TestMD5(object): test_md5 = generate_hash_test( - load_hash_vectors_from_file, + load_hash_vectors, os.path.join("hashes", "MD5"), [ "rfc-1321.txt", diff --git a/tests/hazmat/primitives/test_hmac_vectors.py b/tests/hazmat/primitives/test_hmac_vectors.py index 52d592b6..570c3d46 100644 --- a/tests/hazmat/primitives/test_hmac_vectors.py +++ b/tests/hazmat/primitives/test_hmac_vectors.py @@ -16,12 +16,12 @@ from __future__ import absolute_import, division, print_function from cryptography.hazmat.primitives import hashes from .utils import generate_hmac_test -from ...utils import load_hash_vectors_from_file +from ...utils import load_hash_vectors class TestHMAC_MD5(object): test_hmac_md5 = generate_hmac_test( - load_hash_vectors_from_file, + load_hash_vectors, "HMAC", [ "rfc-2202-md5.txt", @@ -34,7 +34,7 @@ class TestHMAC_MD5(object): class TestHMAC_SHA1(object): test_hmac_sha1 = generate_hmac_test( - load_hash_vectors_from_file, + load_hash_vectors, "HMAC", [ "rfc-2202-sha1.txt", @@ -47,7 +47,7 @@ class TestHMAC_SHA1(object): class TestHMAC_SHA224(object): test_hmac_sha224 = generate_hmac_test( - load_hash_vectors_from_file, + load_hash_vectors, "HMAC", [ "rfc-4231-sha224.txt", @@ -60,7 +60,7 @@ class TestHMAC_SHA224(object): class TestHMAC_SHA256(object): test_hmac_sha256 = generate_hmac_test( - load_hash_vectors_from_file, + load_hash_vectors, "HMAC", [ "rfc-4231-sha256.txt", @@ -73,7 +73,7 @@ class TestHMAC_SHA256(object): class TestHMAC_SHA384(object): test_hmac_sha384 = generate_hmac_test( - load_hash_vectors_from_file, + load_hash_vectors, "HMAC", [ "rfc-4231-sha384.txt", @@ -86,7 +86,7 @@ class TestHMAC_SHA384(object): class TestHMAC_SHA512(object): test_hmac_sha512 = generate_hmac_test( - load_hash_vectors_from_file, + load_hash_vectors, "HMAC", [ "rfc-4231-sha512.txt", @@ -99,7 +99,7 @@ class TestHMAC_SHA512(object): class TestHMAC_RIPEMD160(object): test_hmac_ripemd160 = generate_hmac_test( - load_hash_vectors_from_file, + load_hash_vectors, "HMAC", [ "rfc-2286-ripemd160.txt", diff --git a/tests/hazmat/primitives/utils.py b/tests/hazmat/primitives/utils.py index 90c15b13..0f975950 100644 --- a/tests/hazmat/primitives/utils.py +++ b/tests/hazmat/primitives/utils.py @@ -8,6 +8,8 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hmac from cryptography.hazmat.primitives.ciphers import Cipher +from ...utils import load_vectors_from_file + def generate_encrypt_test(param_loader, path, file_names, cipher_factory, mode_factory, only_if=lambda backend: True, @@ -15,7 +17,10 @@ def generate_encrypt_test(param_loader, path, file_names, cipher_factory, def test_encryption(self): for backend in _ALL_BACKENDS: for file_name in file_names: - for params in param_loader(os.path.join(path, file_name)): + for params in load_vectors_from_file( + os.path.join(path, file_name), + param_loader + ): yield ( encrypt_test, backend, @@ -55,7 +60,10 @@ def generate_stream_encryption_test(param_loader, path, file_names, def test_stream_encryption(self): for backend in _ALL_BACKENDS: for file_name in file_names: - for params in param_loader(os.path.join(path, file_name)): + for params in load_vectors_from_file( + os.path.join(path, file_name), + param_loader + ): yield ( stream_encryption_test, backend, @@ -93,7 +101,10 @@ def generate_hash_test(param_loader, path, file_names, hash_cls, def test_hash(self): for backend in _ALL_BACKENDS: for file_name in file_names: - for params in param_loader(os.path.join(path, file_name)): + for params in load_vectors_from_file( + os.path.join(path, file_name), + param_loader + ): yield ( hash_test, backend, @@ -173,7 +184,10 @@ def generate_hmac_test(param_loader, path, file_names, algorithm, def test_hmac(self): for backend in _ALL_BACKENDS: for file_name in file_names: - for params in param_loader(os.path.join(path, file_name)): + for params in load_vectors_from_file( + os.path.join(path, file_name), + param_loader + ): yield ( hmac_test, backend, |