From 814efab2a71a869d362c0b488b6c51bb590f0d23 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 3 Oct 2013 09:24:58 -0700 Subject: Explicitly pass around the API, and run all tests under all available APIs --- tests/primitives/test_block.py | 20 ++++++++++++-------- tests/primitives/test_nist.py | 36 ++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 22 deletions(-) (limited to 'tests/primitives') diff --git a/tests/primitives/test_block.py b/tests/primitives/test_block.py index 774409ca..92fd31a3 100644 --- a/tests/primitives/test_block.py +++ b/tests/primitives/test_block.py @@ -23,17 +23,19 @@ from cryptography.primitives.block.base import _Operation class TestBlockCipher(object): - def test_cipher_name(self): + def test_cipher_name(self, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(b"0" * 32)), - modes.CBC(binascii.unhexlify(b"0" * 32)) + modes.CBC(binascii.unhexlify(b"0" * 32)), + api ) assert cipher.name == "AES-128-CBC" - def test_use_after_finalize(self): + def test_use_after_finalize(self, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(b"0" * 32)), - modes.CBC(binascii.unhexlify(b"0" * 32)) + modes.CBC(binascii.unhexlify(b"0" * 32)), + api ) cipher.encrypt(b"a" * 16) cipher.finalize() @@ -42,20 +44,22 @@ class TestBlockCipher(object): with pytest.raises(ValueError): cipher.finalize() - def test_encrypt_with_invalid_operation(self): + def test_encrypt_with_invalid_operation(self, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(b"0" * 32)), - modes.CBC(binascii.unhexlify(b"0" * 32)) + modes.CBC(binascii.unhexlify(b"0" * 32)), + api ) cipher._operation = _Operation.decrypt with pytest.raises(ValueError): cipher.encrypt(b"b" * 16) - def test_finalize_with_invalid_operation(self): + def test_finalize_with_invalid_operation(self, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(b"0" * 32)), - modes.CBC(binascii.unhexlify(b"0" * 32)) + modes.CBC(binascii.unhexlify(b"0" * 32)), + api ) cipher._operation = pretend.stub(name="wat") diff --git a/tests/primitives/test_nist.py b/tests/primitives/test_nist.py index 1e5d2396..261bbd1d 100644 --- a/tests/primitives/test_nist.py +++ b/tests/primitives/test_nist.py @@ -60,10 +60,11 @@ class TestAES_CBC(object): "CBCVarTxt256.rsp", ] ) - def test_KAT(self, key, iv, plaintext, ciphertext): + def test_KAT(self, key, iv, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), modes.CBC(binascii.unhexlify(iv)), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() @@ -78,10 +79,11 @@ class TestAES_CBC(object): "CBCMMT256.rsp", ] ) - def test_MMT(self, key, iv, plaintext, ciphertext): + def test_MMT(self, key, iv, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), modes.CBC(binascii.unhexlify(iv)), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() @@ -107,10 +109,11 @@ class TestAES_ECB(object): "ECBVarTxt256.rsp", ] ) - def test_KAT(self, key, plaintext, ciphertext): + def test_KAT(self, key, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), - modes.ECB() + modes.ECB(), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() @@ -125,10 +128,11 @@ class TestAES_ECB(object): "ECBMMT256.rsp", ] ) - def test_MMT(self, key, plaintext, ciphertext): + def test_MMT(self, key, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), - modes.ECB() + modes.ECB(), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() @@ -154,10 +158,11 @@ class TestAES_OFB(object): "OFBVarTxt256.rsp", ] ) - def test_KAT(self, key, iv, plaintext, ciphertext): + def test_KAT(self, key, iv, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), - modes.OFB(binascii.unhexlify(iv)) + modes.OFB(binascii.unhexlify(iv)), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() @@ -172,10 +177,11 @@ class TestAES_OFB(object): "OFBMMT256.rsp", ] ) - def test_MMT(self, key, iv, plaintext, ciphertext): + def test_MMT(self, key, iv, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), - modes.OFB(binascii.unhexlify(iv)) + modes.OFB(binascii.unhexlify(iv)), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() @@ -201,10 +207,11 @@ class TestAES_CFB(object): "CFB128VarTxt256.rsp", ] ) - def test_KAT(self, key, iv, plaintext, ciphertext): + def test_KAT(self, key, iv, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), - modes.CFB(binascii.unhexlify(iv)) + modes.CFB(binascii.unhexlify(iv)), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() @@ -219,10 +226,11 @@ class TestAES_CFB(object): "CFB128MMT256.rsp", ] ) - def test_MMT(self, key, iv, plaintext, ciphertext): + def test_MMT(self, key, iv, plaintext, ciphertext, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(key)), - modes.CFB(binascii.unhexlify(iv)) + modes.CFB(binascii.unhexlify(iv)), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() -- cgit v1.2.3 From 81a5287984cd31080f7a5a1b249caf626ac8f6bf Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 3 Oct 2013 09:58:45 -0700 Subject: Use a None default so composition is easier --- tests/primitives/test_block.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/primitives') diff --git a/tests/primitives/test_block.py b/tests/primitives/test_block.py index 92fd31a3..774885fa 100644 --- a/tests/primitives/test_block.py +++ b/tests/primitives/test_block.py @@ -31,6 +31,13 @@ class TestBlockCipher(object): ) assert cipher.name == "AES-128-CBC" + def test_instantiate_without_api(self): + cipher = BlockCipher( + ciphers.AES(binascii.unhexlify(b"0" * 32)), + modes.CBC(binascii.unhexlify(b"0" * 32)) + ) + assert cipher.name == "AES-128-CBC" + def test_use_after_finalize(self, api): cipher = BlockCipher( ciphers.AES(binascii.unhexlify(b"0" * 32)), -- cgit v1.2.3