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.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py
index e0deb36b..2a3e82d4 100644
--- a/tests/hazmat/primitives/test_block.py
+++ b/tests/hazmat/primitives/test_block.py
@@ -36,23 +36,19 @@ class DummyMode(object):
class TestCipher(object):
- def test_instantiate_without_backend(self):
- Cipher(
- algorithms.AES(binascii.unhexlify(b"0" * 32)),
- modes.CBC(binascii.unhexlify(b"0" * 32))
- )
-
- def test_creates_encryptor(self):
+ def test_creates_encryptor(self, backend):
cipher = Cipher(
algorithms.AES(binascii.unhexlify(b"0" * 32)),
- modes.CBC(binascii.unhexlify(b"0" * 32))
+ modes.CBC(binascii.unhexlify(b"0" * 32)),
+ backend
)
assert isinstance(cipher.encryptor(), interfaces.CipherContext)
- def test_creates_decryptor(self):
+ def test_creates_decryptor(self, backend):
cipher = Cipher(
algorithms.AES(binascii.unhexlify(b"0" * 32)),
- modes.CBC(binascii.unhexlify(b"0" * 32))
+ modes.CBC(binascii.unhexlify(b"0" * 32)),
+ backend
)
assert isinstance(cipher.decryptor(), interfaces.CipherContext)
@@ -114,6 +110,22 @@ class TestCipherContext(object):
with pytest.raises(UnsupportedAlgorithm):
cipher.decryptor()
+ def test_incorrectly_padded(self, backend):
+ cipher = Cipher(
+ algorithms.AES(b"\x00" * 16),
+ modes.CBC(b"\x00" * 16),
+ backend
+ )
+ encryptor = cipher.encryptor()
+ encryptor.update(b"1")
+ with pytest.raises(ValueError):
+ encryptor.finalize()
+
+ decryptor = cipher.decryptor()
+ decryptor.update(b"1")
+ with pytest.raises(ValueError):
+ decryptor.finalize()
+
class TestModeValidation(object):
def test_cbc(self, backend):