aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-19 16:49:26 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-19 16:49:26 -0800
commit9626b5a50460d2f90baa1f1b8c6a09ccc900c178 (patch)
treee6bd8686168074a76711fc17bf18af06a257e4d0 /tests
parenteb7f2a37fee0fdeb70f650b46f580b2eab6d0c05 (diff)
downloadcryptography-9626b5a50460d2f90baa1f1b8c6a09ccc900c178.tar.gz
cryptography-9626b5a50460d2f90baa1f1b8c6a09ccc900c178.tar.bz2
cryptography-9626b5a50460d2f90baa1f1b8c6a09ccc900c178.zip
Validate the IV/nonce length for a given algorithm.
Fixes #159
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/bindings/test_openssl.py3
-rw-r--r--tests/hazmat/primitives/test_block.py17
2 files changed, 18 insertions, 2 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 9f27aab7..1cadc75c 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -23,7 +23,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 9460c53d..b41f8922 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_instantiate_without_backend(self):
Cipher(
@@ -101,10 +106,20 @@ class TestCipherContext(object):
def test_nonexistent_cipher(self, backend):
cipher = Cipher(
- DummyCipher(), object(), backend
+ DummyCipher(), DummyMode(), backend
)
with pytest.raises(UnsupportedAlgorithm):
cipher.encryptor()
with pytest.raises(UnsupportedAlgorithm):
cipher.decryptor()
+
+
+class TestModeValidation(object):
+ def test_cbc(self, backend):
+ with pytest.raises(ValueError):
+ Cipher(
+ algorithms.AES(b"\x00" * 16),
+ modes.CBC(b"abc"),
+ backend,
+ )