support byteslike for OTP (#4710)

diff --git a/docs/hazmat/primitives/twofactor.rst b/docs/hazmat/primitives/twofactor.rst
index b48db59..51625df 100644
--- a/docs/hazmat/primitives/twofactor.rst
+++ b/docs/hazmat/primitives/twofactor.rst
@@ -41,9 +41,10 @@
         >>> 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 @@
         >>> 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 4c561f7..14cb08a 100644
--- a/tests/hazmat/primitives/twofactor/test_hotp.py
+++ b/tests/hazmat/primitives/twofactor/test_hotp.py
@@ -109,6 +109,11 @@
             "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 9582971..59d875a 100644
--- a/tests/hazmat/primitives/twofactor/test_totp.py
+++ b/tests/hazmat/primitives/twofactor/test_totp.py
@@ -139,6 +139,12 @@
             "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"