diff options
Diffstat (limited to 'Lib/hmac.py')
-rw-r--r-- | Lib/hmac.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/hmac.py b/Lib/hmac.py index 4297a7171a..d13b205bbb 100644 --- a/Lib/hmac.py +++ b/Lib/hmac.py @@ -4,7 +4,7 @@ Implements the HMAC algorithm as described by RFC 2104. """ import warnings as _warnings -from operator import _compare_digest as compare_digest +from _operator import _compare_digest as compare_digest trans_5C = bytes((x ^ 0x5C) for x in range(256)) trans_36 = bytes((x ^ 0x36) for x in range(256)) @@ -31,11 +31,11 @@ class HMAC: A hashlib constructor returning a new hash object. Defaults to hashlib.md5. - Note: key and msg must be bytes objects. + Note: key and msg must be a bytes or bytearray objects. """ - if not isinstance(key, bytes): - raise TypeError("key: expected bytes, but got %r" % type(key).__name__) + if not isinstance(key, (bytes, bytearray)): + raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__) if digestmod is None: import hashlib @@ -75,8 +75,6 @@ class HMAC: def update(self, msg): """Update this hashing object with the string msg. """ - if not isinstance(msg, bytes): - raise TypeError("expected bytes, but got %r" % type(msg).__name__) self.inner.update(msg) def copy(self): |