diff options
-rw-r--r-- | cryptography/hazmat/primitives/twofactor/hotp.py | 3 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_hotp.py | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/cryptography/hazmat/primitives/twofactor/hotp.py b/cryptography/hazmat/primitives/twofactor/hotp.py index 88bde715..83260225 100644 --- a/cryptography/hazmat/primitives/twofactor/hotp.py +++ b/cryptography/hazmat/primitives/twofactor/hotp.py @@ -27,6 +27,9 @@ class HOTP(object): if len(key) < 16: raise ValueError("Key length has to be at least 128 bits.") + if not isinstance(length, six.integer_types): + raise TypeError("Length parameter must be an integer type") + if length < 6 or length > 8: raise ValueError("Length of HOTP has to be between 6 to 8.") diff --git a/tests/hazmat/primitives/twofactor/test_hotp.py b/tests/hazmat/primitives/twofactor/test_hotp.py index 4c726b77..0f8c4a53 100644 --- a/tests/hazmat/primitives/twofactor/test_hotp.py +++ b/tests/hazmat/primitives/twofactor/test_hotp.py @@ -87,3 +87,9 @@ class TestHOTP(object): with pytest.raises(InvalidToken): hotp.verify(b"123456", counter) + + def test_length_not_int(self, backend): + secret = b"12345678901234567890" + + with pytest.raises(TypeError): + HOTP(secret, b"foo", SHA1(), backend) |