aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-09-10 17:21:07 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-09-10 17:21:07 -0700
commit180606f3e7fd9083567e9754fca39e44b5b06b15 (patch)
treeeeb8de4708f836b9ebac3690f2483322ace2ca4a /tests
parent29828520d833b0be94e0755785ad0f0a42cd35e6 (diff)
parent2354fcdcb46589eeba3fe0cfd25e3f2315b2b89f (diff)
downloadcryptography-180606f3e7fd9083567e9754fca39e44b5b06b15.tar.gz
cryptography-180606f3e7fd9083567e9754fca39e44b5b06b15.tar.bz2
cryptography-180606f3e7fd9083567e9754fca39e44b5b06b15.zip
Merge pull request #55 from reaperhulk/parameterize-encrypt-changes
Changes to parameterize_encrypt_test to support other NIST vectors
Diffstat (limited to 'tests')
-rw-r--r--tests/primitives/test_nist.py52
1 files changed, 30 insertions, 22 deletions
diff --git a/tests/primitives/test_nist.py b/tests/primitives/test_nist.py
index 65d130ad..8bef118e 100644
--- a/tests/primitives/test_nist.py
+++ b/tests/primitives/test_nist.py
@@ -28,13 +28,13 @@ from cryptography.primitives.block import BlockCipher, ciphers, modes
from ..utils import load_nist_vectors_from_file
-def parameterize_encrypt_test(cipher, vector_type, fnames):
- return pytest.mark.parametrize(("key", "iv", "plaintext", "ciphertext"),
+def parameterize_encrypt_test(cipher, vector_type, params, fnames):
+ return pytest.mark.parametrize(params,
list(itertools.chain.from_iterable(
load_nist_vectors_from_file(
os.path.join(cipher, vector_type, fname),
"ENCRYPT",
- ["key", "iv", "plaintext", "ciphertext"],
+ params
)
for fname in fnames
))
@@ -42,20 +42,24 @@ def parameterize_encrypt_test(cipher, vector_type, fnames):
class TestAES_CBC(object):
- @parameterize_encrypt_test("AES", "KAT", [
- "CBCGFSbox128.rsp",
- "CBCGFSbox192.rsp",
- "CBCGFSbox256.rsp",
- "CBCKeySbox128.rsp",
- "CBCKeySbox192.rsp",
- "CBCKeySbox256.rsp",
- "CBCVarKey128.rsp",
- "CBCVarKey192.rsp",
- "CBCVarKey256.rsp",
- "CBCVarTxt128.rsp",
- "CBCVarTxt192.rsp",
- "CBCVarTxt256.rsp",
- ])
+ @parameterize_encrypt_test(
+ "AES", "KAT",
+ ("key", "iv", "plaintext", "ciphertext"),
+ [
+ "CBCGFSbox128.rsp",
+ "CBCGFSbox192.rsp",
+ "CBCGFSbox256.rsp",
+ "CBCKeySbox128.rsp",
+ "CBCKeySbox192.rsp",
+ "CBCKeySbox256.rsp",
+ "CBCVarKey128.rsp",
+ "CBCVarKey192.rsp",
+ "CBCVarKey256.rsp",
+ "CBCVarTxt128.rsp",
+ "CBCVarTxt192.rsp",
+ "CBCVarTxt256.rsp",
+ ]
+ )
def test_KAT(self, key, iv, plaintext, ciphertext):
cipher = BlockCipher(
ciphers.AES(binascii.unhexlify(key)),
@@ -65,11 +69,15 @@ class TestAES_CBC(object):
actual_ciphertext += cipher.finalize()
assert binascii.hexlify(actual_ciphertext) == ciphertext
- @parameterize_encrypt_test("AES", "MMT", [
- "CBCMMT128.rsp",
- "CBCMMT192.rsp",
- "CBCMMT256.rsp",
- ])
+ @parameterize_encrypt_test(
+ "AES", "MMT",
+ ("key", "iv", "plaintext", "ciphertext"),
+ [
+ "CBCMMT128.rsp",
+ "CBCMMT192.rsp",
+ "CBCMMT256.rsp",
+ ]
+ )
def test_MMT(self, key, iv, plaintext, ciphertext):
cipher = BlockCipher(
ciphers.AES(binascii.unhexlify(key)),