diff options
-rw-r--r-- | docs/hazmat/primitives/twofactor.rst | 14 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_hotp.py | 5 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_totp.py | 6 |
3 files changed, 19 insertions, 6 deletions
diff --git a/docs/hazmat/primitives/twofactor.rst b/docs/hazmat/primitives/twofactor.rst index b48db599..51625dfc 100644 --- a/docs/hazmat/primitives/twofactor.rst +++ b/docs/hazmat/primitives/twofactor.rst @@ -41,9 +41,10 @@ codes (HMAC). >>> hotp_value = hotp.generate(0) >>> hotp.verify(hotp_value, 0) - :param bytes key: Per-user secret key. This value must be kept secret - and be at least 128 :term:`bits`. It is recommended that - the key be 160 bits. + :param key: Per-user secret key. This value must be kept secret + and be at least 128 :term:`bits`. It is recommended that + the key be 160 bits. + :type key: :term:`bytes-like` :param int length: Length of generated one time password as ``int``. :param cryptography.hazmat.primitives.hashes.HashAlgorithm algorithm: A :class:`~cryptography.hazmat.primitives.hashes` @@ -163,9 +164,10 @@ similar to the following code. >>> totp_value = totp.generate(time_value) >>> totp.verify(totp_value, time_value) - :param bytes key: Per-user secret key. This value must be kept secret - and be at least 128 :term:`bits`. It is recommended that the - key be 160 bits. + :param key: Per-user secret key. This value must be kept secret + and be at least 128 :term:`bits`. It is recommended that the + key be 160 bits. + :type key: :term:`bytes-like` :param int length: Length of generated one time password as ``int``. :param cryptography.hazmat.primitives.hashes.HashAlgorithm algorithm: A :class:`~cryptography.hazmat.primitives.hashes` diff --git a/tests/hazmat/primitives/twofactor/test_hotp.py b/tests/hazmat/primitives/twofactor/test_hotp.py index 4c561f70..14cb08a8 100644 --- a/tests/hazmat/primitives/twofactor/test_hotp.py +++ b/tests/hazmat/primitives/twofactor/test_hotp.py @@ -109,6 +109,11 @@ class TestHOTP(object): "GNBVGY3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&issuer=Foo" "&counter=1") + def test_buffer_protocol(self, backend): + key = bytearray(b"a long key with lots of entropy goes here") + hotp = HOTP(key, 6, SHA1(), backend) + assert hotp.generate(10) == b"559978" + def test_invalid_backend(): secret = b"12345678901234567890" diff --git a/tests/hazmat/primitives/twofactor/test_totp.py b/tests/hazmat/primitives/twofactor/test_totp.py index 95829713..59d875af 100644 --- a/tests/hazmat/primitives/twofactor/test_totp.py +++ b/tests/hazmat/primitives/twofactor/test_totp.py @@ -139,6 +139,12 @@ class TestTOTP(object): "DGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&issuer=World" "&period=30") + def test_buffer_protocol(self, backend): + key = bytearray(b"a long key with lots of entropy goes here") + totp = TOTP(key, 8, hashes.SHA512(), 30, backend) + time = 60 + assert totp.generate(time) == b"53049576" + def test_invalid_backend(): secret = b"12345678901234567890" |