From 6870241a88e208fa5612610f02cc1d57f0f26448 Mon Sep 17 00:00:00 2001 From: Ayrx Date: Sat, 15 Mar 2014 23:29:36 +0800 Subject: Added backend check to kdf primitives --- tests/hazmat/primitives/test_hkdf.py | 9 ++++++++- tests/hazmat/primitives/test_pbkdf2hmac.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_hkdf.py b/tests/hazmat/primitives/test_hkdf.py index e3e2a9df..3dea3f27 100644 --- a/tests/hazmat/primitives/test_hkdf.py +++ b/tests/hazmat/primitives/test_hkdf.py @@ -17,7 +17,7 @@ import six import pytest -from cryptography.exceptions import AlreadyFinalized, InvalidKey +from cryptography.exceptions import AlreadyFinalized, InvalidKey, UnsupportedInterface from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.hkdf import HKDF @@ -145,3 +145,10 @@ class TestHKDF(object): ) hkdf.verify(b"foo", six.u("bar")) + + +def test_invalid_backend(): + pretend_backend = object() + + with pytest.raises(UnsupportedInterface): + HKDF(hashes.SHA256(), 16, None, None, pretend_backend) diff --git a/tests/hazmat/primitives/test_pbkdf2hmac.py b/tests/hazmat/primitives/test_pbkdf2hmac.py index f895935b..a47d879e 100644 --- a/tests/hazmat/primitives/test_pbkdf2hmac.py +++ b/tests/hazmat/primitives/test_pbkdf2hmac.py @@ -18,8 +18,9 @@ import six from cryptography import utils from cryptography.exceptions import ( - InvalidKey, UnsupportedHash, AlreadyFinalized -) + InvalidKey, UnsupportedHash, AlreadyFinalized, + UnsupportedInterface) + from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.backends import default_backend @@ -67,3 +68,10 @@ class TestPBKDF2HMAC(object): kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend()) with pytest.raises(TypeError): kdf.derive(six.u("unicode here")) + + +def test_invalid_backend(): + pretend_backend = object() + + with pytest.raises(UnsupportedInterface): + PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, pretend_backend) -- cgit v1.2.3 From c5c8c3c0c6a57272ba450d896ccd1df9ae70bae7 Mon Sep 17 00:00:00 2001 From: Ayrx Date: Sat, 15 Mar 2014 23:42:37 +0800 Subject: Fixed pep8 error --- tests/hazmat/primitives/test_hkdf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_hkdf.py b/tests/hazmat/primitives/test_hkdf.py index 3dea3f27..42c75c65 100644 --- a/tests/hazmat/primitives/test_hkdf.py +++ b/tests/hazmat/primitives/test_hkdf.py @@ -17,7 +17,9 @@ import six import pytest -from cryptography.exceptions import AlreadyFinalized, InvalidKey, UnsupportedInterface +from cryptography.exceptions import ( + AlreadyFinalized, InvalidKey, UnsupportedInterface) + from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.hkdf import HKDF -- cgit v1.2.3