diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-19 07:38:19 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-19 07:38:19 -0800 |
commit | b29a6b2e4623fa87fecaccc05551b996f684cd53 (patch) | |
tree | f3579a5536862a304eaba25612f07f0c2515c8bd /tests/hazmat/primitives/test_block.py | |
parent | 867acfa0300ca75f2c11c15490e04b556d8bfe99 (diff) | |
parent | 62e96cbb0698d8f7d65d8dd2d301ef975a829d9e (diff) | |
download | cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.gz cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.bz2 cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.zip |
Merge branch 'master' into fernet
Diffstat (limited to 'tests/hazmat/primitives/test_block.py')
-rw-r--r-- | tests/hazmat/primitives/test_block.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py index 28f34478..9460c53d 100644 --- a/tests/hazmat/primitives/test_block.py +++ b/tests/hazmat/primitives/test_block.py @@ -17,13 +17,19 @@ import binascii import pytest -from cryptography.exceptions import UnsupportedAlgorithm +from cryptography import utils +from cryptography.exceptions import UnsupportedAlgorithm, AlreadyFinalized from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.ciphers import ( Cipher, algorithms, modes ) +@utils.register_interface(interfaces.CipherAlgorithm) +class DummyCipher(object): + pass + + class TestCipher(object): def test_instantiate_without_backend(self): Cipher( @@ -45,6 +51,11 @@ class TestCipher(object): ) assert isinstance(cipher.decryptor(), interfaces.CipherContext) + def test_instantiate_with_non_algorithm(self): + algorithm = object() + with pytest.raises(TypeError): + Cipher(algorithm, mode=None) + class TestCipherContext(object): def test_use_after_finalize(self, backend): @@ -56,16 +67,16 @@ class TestCipherContext(object): encryptor = cipher.encryptor() encryptor.update(b"a" * 16) encryptor.finalize() - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): encryptor.update(b"b" * 16) - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): encryptor.finalize() decryptor = cipher.decryptor() decryptor.update(b"a" * 16) decryptor.finalize() - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): decryptor.update(b"b" * 16) - with pytest.raises(ValueError): + with pytest.raises(AlreadyFinalized): decryptor.finalize() def test_unaligned_block_encryption(self, backend): @@ -90,7 +101,7 @@ class TestCipherContext(object): def test_nonexistent_cipher(self, backend): cipher = Cipher( - object(), object(), backend + DummyCipher(), object(), backend ) with pytest.raises(UnsupportedAlgorithm): cipher.encryptor() |