From 0857c3f03e2784cac9e2a35f5579e9c4c8dc824a Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 3 Nov 2013 11:29:15 -0800 Subject: Replaced an assertion in the OpenSSL backend with a proper exception --- tests/hazmat/bindings/test_openssl.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'tests/hazmat/bindings') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index 9ce882e4..fcd54ddd 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -11,11 +11,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import binascii + 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.block import BlockCipher +from cryptography.hazmat.primitives.block.ciphers import AES, TripleDES +from cryptography.hazmat.primitives.block.modes import CBC, ECB class TestOpenSSL(object): @@ -39,3 +43,15 @@ class TestOpenSSL(object): def test_register_duplicate_cipher_adapter(self): with pytest.raises(ValueError): backend.ciphers.register_cipher_adapter(AES, CBC, None) + + def test_nonexistant_cipher(self): + b = Backend() + # TODO: this test assumes that 3DES-ECB doesn't exist + b.ciphers.register_cipher_adapter( + TripleDES, ECB, lambda backend, cipher, mode: backend.ffi.NULL + ) + cipher = BlockCipher( + TripleDES(binascii.unhexlify(b"0" * 16)), ECB(), backend=b + ) + with pytest.raises(UnsupportedAlgorithm): + cipher.encryptor() -- cgit v1.2.3 From 7e262a6d730f45d40645323c8462b4c480fe7319 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 3 Nov 2013 19:35:44 -0800 Subject: typo fix --- tests/hazmat/bindings/test_openssl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/hazmat/bindings') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index fcd54ddd..af9be353 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -44,7 +44,7 @@ class TestOpenSSL(object): with pytest.raises(ValueError): backend.ciphers.register_cipher_adapter(AES, CBC, None) - def test_nonexistant_cipher(self): + def test_nonexistent_cipher(self): b = Backend() # TODO: this test assumes that 3DES-ECB doesn't exist b.ciphers.register_cipher_adapter( -- cgit v1.2.3 From 3e252c601592245590e015558a4c082f11ea40cd Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 4 Nov 2013 10:32:21 -0800 Subject: coverage --- tests/hazmat/bindings/test_openssl.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/hazmat/bindings') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index 9ce882e4..d47ae919 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -13,7 +13,7 @@ import pytest -from cryptography.hazmat.bindings.openssl.backend import backend +from cryptography.hazmat.bindings.openssl.backend import backend, Backend from cryptography.hazmat.primitives.block.ciphers import AES from cryptography.hazmat.primitives.block.modes import CBC @@ -39,3 +39,6 @@ class TestOpenSSL(object): def test_register_duplicate_cipher_adapter(self): with pytest.raises(ValueError): backend.ciphers.register_cipher_adapter(AES, CBC, None) + + def test_instantiates(self): + Backend() -- cgit v1.2.3 From b2fc8ac5a367dbedc8d3bbd57dd16deb67b08d01 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 4 Nov 2013 14:02:04 -0800 Subject: Rewrite this test to be good --- tests/hazmat/bindings/test_openssl.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/hazmat/bindings') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index d47ae919..fb01c10a 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -40,5 +40,7 @@ class TestOpenSSL(object): with pytest.raises(ValueError): backend.ciphers.register_cipher_adapter(AES, CBC, None) - def test_instantiates(self): - Backend() + def test_instances_share_ffi(self): + b = Backend() + assert b.ffi is backend.ffi + assert b.lib is backend.lib -- cgit v1.2.3 From 85be46d74706a46b6407685610066506d23a49e8 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 4 Nov 2013 19:23:17 -0800 Subject: Replace assumption with some fakes --- tests/hazmat/bindings/test_openssl.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'tests/hazmat/bindings') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index 3523fa4e..4e8dfa58 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -11,15 +11,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -import binascii - import pytest from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.bindings.openssl.backend import backend, Backend from cryptography.hazmat.primitives.block import BlockCipher -from cryptography.hazmat.primitives.block.ciphers import AES, TripleDES -from cryptography.hazmat.primitives.block.modes import CBC, ECB +from cryptography.hazmat.primitives.block.ciphers import AES +from cryptography.hazmat.primitives.block.modes import CBC + + +class FakeMode(object): + pass + + +class FakeCipher(object): + pass class TestOpenSSL(object): @@ -51,12 +57,11 @@ class TestOpenSSL(object): def test_nonexistent_cipher(self): b = Backend() - # TODO: this test assumes that 3DES-ECB doesn't exist b.ciphers.register_cipher_adapter( - TripleDES, ECB, lambda backend, cipher, mode: backend.ffi.NULL + FakeCipher, FakeMode, lambda backend, cipher, mode: backend.ffi.NULL ) cipher = BlockCipher( - TripleDES(binascii.unhexlify(b"0" * 16)), ECB(), backend=b + FakeCipher(), FakeMode(), backend=b, ) with pytest.raises(UnsupportedAlgorithm): cipher.encryptor() -- cgit v1.2.3 From 86f98a051c9298020ac1d6cdb06ceb513699c7fa Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 4 Nov 2013 19:30:20 -0800 Subject: 79 cols --- tests/hazmat/bindings/test_openssl.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/hazmat/bindings') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index 4e8dfa58..f283a7dd 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -58,7 +58,9 @@ class TestOpenSSL(object): def test_nonexistent_cipher(self): b = Backend() b.ciphers.register_cipher_adapter( - FakeCipher, FakeMode, lambda backend, cipher, mode: backend.ffi.NULL + FakeCipher, + FakeMode, + lambda backend, cipher, mode: backend.ffi.NULL ) cipher = BlockCipher( FakeCipher(), FakeMode(), backend=b, -- cgit v1.2.3 From 21dde56b48bf473932ce815860dd2ec99f2e2c75 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 6 Nov 2013 12:22:09 +0800 Subject: block cipher rename * block renamed to ciphers * ciphers renamed to algorithms * base moved into algorithms --- tests/hazmat/bindings/test_openssl.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/hazmat/bindings') diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index f283a7dd..f1493e8d 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -15,9 +15,9 @@ import pytest from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.bindings.openssl.backend import backend, Backend -from cryptography.hazmat.primitives.block import BlockCipher -from cryptography.hazmat.primitives.block.ciphers import AES -from cryptography.hazmat.primitives.block.modes import CBC +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): @@ -62,7 +62,7 @@ class TestOpenSSL(object): FakeMode, lambda backend, cipher, mode: backend.ffi.NULL ) - cipher = BlockCipher( + cipher = Cipher( FakeCipher(), FakeMode(), backend=b, ) with pytest.raises(UnsupportedAlgorithm): -- cgit v1.2.3