aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2013-11-15 16:19:50 -0800
committerDavid Reid <dreid@dreid.org>2013-11-15 16:19:50 -0800
commit0a394df31c4165d0230843ebea2717b3cd3caafa (patch)
tree5c674a900d0f7465cde2796b9bba21a87d67b56e /tests
parent9489c769dbd7ea7c6830b5fcd70095818452e607 (diff)
downloadcryptography-0a394df31c4165d0230843ebea2717b3cd3caafa.tar.gz
cryptography-0a394df31c4165d0230843ebea2717b3cd3caafa.tar.bz2
cryptography-0a394df31c4165d0230843ebea2717b3cd3caafa.zip
Implement and document an interface for cipher algorithms
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/bindings/test_openssl.py12
-rw-r--r--tests/hazmat/primitives/test_block.py12
2 files changed, 18 insertions, 6 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 241c6411..e4f8dd8b 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -15,16 +15,18 @@ import pytest
from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.bindings.openssl.backend import backend, Backend
+from cryptography.hazmat.primitives import interfaces
from cryptography.hazmat.primitives.ciphers import Cipher
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.modes import CBC
-class FakeMode(object):
+class DummyMode(object):
pass
-class FakeCipher(object):
+@interfaces.register(interfaces.CipherAlgorithm)
+class DummyCipher(object):
pass
@@ -58,12 +60,12 @@ class TestOpenSSL(object):
def test_nonexistent_cipher(self):
b = Backend()
b.register_cipher_adapter(
- FakeCipher,
- FakeMode,
+ DummyCipher,
+ DummyMode,
lambda backend, cipher, mode: backend.ffi.NULL
)
cipher = Cipher(
- FakeCipher(), FakeMode(), backend=b,
+ DummyCipher(), DummyMode(), backend=b,
)
with pytest.raises(UnsupportedAlgorithm):
cipher.encryptor()
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py
index 938cff36..963136b9 100644
--- a/tests/hazmat/primitives/test_block.py
+++ b/tests/hazmat/primitives/test_block.py
@@ -24,6 +24,11 @@ from cryptography.hazmat.primitives.ciphers import (
)
+@interfaces.register(interfaces.CipherAlgorithm)
+class DummyCipher(object):
+ pass
+
+
class TestCipher(object):
def test_instantiate_without_backend(self):
Cipher(
@@ -45,6 +50,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):
@@ -90,7 +100,7 @@ class TestCipherContext(object):
def test_nonexistent_cipher(self, backend):
cipher = Cipher(
- object(), object(), backend
+ DummyCipher(), object(), backend
)
with pytest.raises(UnsupportedAlgorithm):
cipher.encryptor()