diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-07 14:25:44 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-07 14:25:44 -0800 |
commit | 60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c (patch) | |
tree | 5912a5ebeec4f4ffe8ecd6b0fd11b1794a8772c5 /tests/hazmat/primitives/test_block.py | |
parent | 105e8137799a2ef7ec8275e3c01d61a04884413b (diff) | |
parent | 635b542ded9ede772a2ca907e8bb5349ded333bd (diff) | |
download | cryptography-60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c.tar.gz cryptography-60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c.tar.bz2 cryptography-60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c.zip |
Merge branch 'master' into fernet
Diffstat (limited to 'tests/hazmat/primitives/test_block.py')
-rw-r--r-- | tests/hazmat/primitives/test_block.py | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py index e0ed6697..28f34478 100644 --- a/tests/hazmat/primitives/test_block.py +++ b/tests/hazmat/primitives/test_block.py @@ -17,36 +17,39 @@ import binascii import pytest +from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.primitives import interfaces -from cryptography.hazmat.primitives.block import BlockCipher, ciphers, modes +from cryptography.hazmat.primitives.ciphers import ( + Cipher, algorithms, modes +) -class TestBlockCipher(object): +class TestCipher(object): def test_instantiate_without_backend(self): - BlockCipher( - ciphers.AES(binascii.unhexlify(b"0" * 32)), + Cipher( + algorithms.AES(binascii.unhexlify(b"0" * 32)), modes.CBC(binascii.unhexlify(b"0" * 32)) ) def test_creates_encryptor(self): - cipher = BlockCipher( - ciphers.AES(binascii.unhexlify(b"0" * 32)), + cipher = Cipher( + algorithms.AES(binascii.unhexlify(b"0" * 32)), modes.CBC(binascii.unhexlify(b"0" * 32)) ) assert isinstance(cipher.encryptor(), interfaces.CipherContext) def test_creates_decryptor(self): - cipher = BlockCipher( - ciphers.AES(binascii.unhexlify(b"0" * 32)), + cipher = Cipher( + algorithms.AES(binascii.unhexlify(b"0" * 32)), modes.CBC(binascii.unhexlify(b"0" * 32)) ) assert isinstance(cipher.decryptor(), interfaces.CipherContext) -class TestBlockCipherContext(object): +class TestCipherContext(object): def test_use_after_finalize(self, backend): - cipher = BlockCipher( - ciphers.AES(binascii.unhexlify(b"0" * 32)), + cipher = Cipher( + algorithms.AES(binascii.unhexlify(b"0" * 32)), modes.CBC(binascii.unhexlify(b"0" * 32)), backend ) @@ -66,8 +69,8 @@ class TestBlockCipherContext(object): decryptor.finalize() def test_unaligned_block_encryption(self, backend): - cipher = BlockCipher( - ciphers.AES(binascii.unhexlify(b"0" * 32)), + cipher = Cipher( + algorithms.AES(binascii.unhexlify(b"0" * 32)), modes.ECB(), backend ) @@ -84,3 +87,13 @@ class TestBlockCipherContext(object): assert len(pt) == 80 assert pt == b"a" * 80 decryptor.finalize() + + def test_nonexistent_cipher(self, backend): + cipher = Cipher( + object(), object(), backend + ) + with pytest.raises(UnsupportedAlgorithm): + cipher.encryptor() + + with pytest.raises(UnsupportedAlgorithm): + cipher.decryptor() |