aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/bindings
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-07 14:25:44 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-07 14:25:44 -0800
commit60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c (patch)
tree5912a5ebeec4f4ffe8ecd6b0fd11b1794a8772c5 /tests/hazmat/bindings
parent105e8137799a2ef7ec8275e3c01d61a04884413b (diff)
parent635b542ded9ede772a2ca907e8bb5349ded333bd (diff)
downloadcryptography-60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c.tar.gz
cryptography-60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c.tar.bz2
cryptography-60f1d8b89cf7eb6f4d58eed7be9b816056c1df9c.zip
Merge branch 'master' into fernet
Diffstat (limited to 'tests/hazmat/bindings')
-rw-r--r--tests/hazmat/bindings/test_openssl.py34
1 files changed, 31 insertions, 3 deletions
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index 9ce882e4..f1493e8d 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -13,9 +13,19 @@
import pytest
-from cryptography.hazmat.bindings.openssl.backend import backend
-from cryptography.hazmat.primitives.block.ciphers import AES
-from cryptography.hazmat.primitives.block.modes import CBC
+from cryptography.exceptions import UnsupportedAlgorithm
+from cryptography.hazmat.bindings.openssl.backend import backend, Backend
+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):
+ pass
+
+
+class FakeCipher(object):
+ pass
class TestOpenSSL(object):
@@ -39,3 +49,21 @@ class TestOpenSSL(object):
def test_register_duplicate_cipher_adapter(self):
with pytest.raises(ValueError):
backend.ciphers.register_cipher_adapter(AES, CBC, None)
+
+ def test_instances_share_ffi(self):
+ b = Backend()
+ assert b.ffi is backend.ffi
+ assert b.lib is backend.lib
+
+ def test_nonexistent_cipher(self):
+ b = Backend()
+ b.ciphers.register_cipher_adapter(
+ FakeCipher,
+ FakeMode,
+ lambda backend, cipher, mode: backend.ffi.NULL
+ )
+ cipher = Cipher(
+ FakeCipher(), FakeMode(), backend=b,
+ )
+ with pytest.raises(UnsupportedAlgorithm):
+ cipher.encryptor()