aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/bindings/test_openssl.py3
-rw-r--r--tests/hazmat/primitives/test_block.py41
2 files changed, 42 insertions, 2 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 1eb6f200..4923d698 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -24,7 +24,8 @@ from cryptography.hazmat.primitives.ciphers.modes import CBC
class DummyMode(object):
- pass
+ def validate_for_algorithm(self, algorithm):
+ pass
@utils.register_interface(interfaces.CipherAlgorithm)
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py
index 4a8e88b4..2a3e82d4 100644
--- a/tests/hazmat/primitives/test_block.py
+++ b/tests/hazmat/primitives/test_block.py
@@ -30,6 +30,11 @@ class DummyCipher(object):
pass
+class DummyMode(object):
+ def validate_for_algorithm(self, algorithm):
+ pass
+
+
class TestCipher(object):
def test_creates_encryptor(self, backend):
cipher = Cipher(
@@ -97,7 +102,7 @@ class TestCipherContext(object):
def test_nonexistent_cipher(self, backend):
cipher = Cipher(
- DummyCipher(), object(), backend
+ DummyCipher(), DummyMode(), backend
)
with pytest.raises(UnsupportedAlgorithm):
cipher.encryptor()
@@ -120,3 +125,37 @@ class TestCipherContext(object):
decryptor.update(b"1")
with pytest.raises(ValueError):
decryptor.finalize()
+
+
+class TestModeValidation(object):
+ def test_cbc(self, backend):
+ with pytest.raises(ValueError):
+ Cipher(
+ algorithms.AES(b"\x00" * 16),
+ modes.CBC(b"abc"),
+ backend,
+ )
+
+ def test_ofb(self, backend):
+ with pytest.raises(ValueError):
+ Cipher(
+ algorithms.AES(b"\x00" * 16),
+ modes.OFB(b"abc"),
+ backend,
+ )
+
+ def test_cfb(self, backend):
+ with pytest.raises(ValueError):
+ Cipher(
+ algorithms.AES(b"\x00" * 16),
+ modes.CFB(b"abc"),
+ backend,
+ )
+
+ def test_ctr(self, backend):
+ with pytest.raises(ValueError):
+ Cipher(
+ algorithms.AES(b"\x00" * 16),
+ modes.CTR(b"abc"),
+ backend,
+ )