aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_block.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hazmat/primitives/test_block.py')
-rw-r--r--tests/hazmat/primitives/test_block.py39
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()