aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hazmat')
-rw-r--r--tests/hazmat/primitives/test_ciphers.py12
-rw-r--r--tests/hazmat/primitives/test_hkdf.py11
-rw-r--r--tests/hazmat/primitives/test_pbkdf2hmac.py9
-rw-r--r--tests/hazmat/primitives/twofactor/test_hotp.py11
-rw-r--r--tests/hazmat/primitives/twofactor/test_totp.py11
5 files changed, 49 insertions, 5 deletions
diff --git a/tests/hazmat/primitives/test_ciphers.py b/tests/hazmat/primitives/test_ciphers.py
index 50cadf64..d9f83535 100644
--- a/tests/hazmat/primitives/test_ciphers.py
+++ b/tests/hazmat/primitives/test_ciphers.py
@@ -18,7 +18,7 @@ import binascii
import pytest
from cryptography.hazmat.primitives.ciphers.algorithms import (
- AES, Camellia, TripleDES, Blowfish, ARC4, CAST5
+ AES, Camellia, TripleDES, Blowfish, ARC4, CAST5, IDEA
)
@@ -110,3 +110,13 @@ class TestARC4(object):
def test_invalid_key_size(self):
with pytest.raises(ValueError):
ARC4(binascii.unhexlify(b"0" * 34))
+
+
+class TestIDEA(object):
+ def test_key_size(self):
+ cipher = IDEA(b"\x00" * 16)
+ assert cipher.key_size == 128
+
+ def test_invalid_key_size(self):
+ with pytest.raises(ValueError):
+ IDEA(b"\x00" * 17)
diff --git a/tests/hazmat/primitives/test_hkdf.py b/tests/hazmat/primitives/test_hkdf.py
index e3e2a9df..963fb69c 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
+from cryptography.exceptions import (
+ AlreadyFinalized, InvalidKey, UnsupportedInterface
+)
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
@@ -145,3 +147,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..bf1e7f14 100644
--- a/tests/hazmat/primitives/test_pbkdf2hmac.py
+++ b/tests/hazmat/primitives/test_pbkdf2hmac.py
@@ -18,7 +18,7 @@ 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
@@ -67,3 +67,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)
diff --git a/tests/hazmat/primitives/twofactor/test_hotp.py b/tests/hazmat/primitives/twofactor/test_hotp.py
index bc907c9f..548c6264 100644
--- a/tests/hazmat/primitives/twofactor/test_hotp.py
+++ b/tests/hazmat/primitives/twofactor/test_hotp.py
@@ -17,7 +17,7 @@ import os
import pytest
-from cryptography.exceptions import InvalidToken
+from cryptography.exceptions import InvalidToken, UnsupportedInterface
from cryptography.hazmat.primitives.twofactor.hotp import HOTP
from cryptography.hazmat.primitives import hashes
from tests.utils import load_vectors_from_file, load_nist_vectors
@@ -95,3 +95,12 @@ class TestHOTP(object):
with pytest.raises(TypeError):
HOTP(secret, b"foo", SHA1(), backend)
+
+
+def test_invalid_backend():
+ secret = b"12345678901234567890"
+
+ pretend_backend = object()
+
+ with pytest.raises(UnsupportedInterface):
+ HOTP(secret, 8, hashes.SHA1(), pretend_backend)
diff --git a/tests/hazmat/primitives/twofactor/test_totp.py b/tests/hazmat/primitives/twofactor/test_totp.py
index f3bddb88..294c19ab 100644
--- a/tests/hazmat/primitives/twofactor/test_totp.py
+++ b/tests/hazmat/primitives/twofactor/test_totp.py
@@ -15,7 +15,7 @@ from __future__ import absolute_import, division, print_function
import pytest
-from cryptography.exceptions import InvalidToken
+from cryptography.exceptions import InvalidToken, UnsupportedInterface
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.twofactor.totp import TOTP
from tests.utils import load_vectors_from_file, load_nist_vectors
@@ -129,3 +129,12 @@ class TestTOTP(object):
totp = TOTP(secret, 8, hashes.SHA1(), 30, backend)
assert totp.generate(time) == b"94287082"
+
+
+def test_invalid_backend():
+ secret = b"12345678901234567890"
+
+ pretend_backend = object()
+
+ with pytest.raises(UnsupportedInterface):
+ TOTP(secret, 8, hashes.SHA1(), 30, pretend_backend)