diff -r b9b521efeba3 Doc/library/hmac.rst --- a/Doc/library/hmac.rst Sat May 18 17:56:42 2013 +0200 +++ b/Doc/library/hmac.rst Mon Jun 17 22:16:45 2013 +0200 @@ -16,18 +16,18 @@ .. function:: new(key, msg=None, digestmod=None) - Return a new hmac object. *key* is a bytes object giving the secret key. If - *msg* is present, the method call ``update(msg)`` is made. *digestmod* is - the digest constructor or module for the HMAC object to use. It defaults to - the :func:`hashlib.md5` constructor. + Return a new hmac object. *key* is a bytes or bytearray object giving the + secret key. If *msg* is present, the method call ``update(msg)`` is made. + *digestmod* is the digest constructor or module for the HMAC object to use. + It defaults to the :func:`hashlib.md5` constructor. An HMAC object has the following methods: .. method:: HMAC.update(msg) - Update the hmac object with the bytes object *msg*. Repeated calls are - equivalent to a single call with the concatenation of all the arguments: + Update the hmac object with *msg*. Repeated calls are equivalent to a + single call with the concatenation of all the arguments: ``m.update(a); m.update(b)`` is equivalent to ``m.update(a + b)``. diff -r b9b521efeba3 Lib/hmac.py --- a/Lib/hmac.py Sat May 18 17:56:42 2013 +0200 +++ b/Lib/hmac.py Mon Jun 17 22:16:45 2013 +0200 @@ -29,11 +29,11 @@ A hashlib constructor returning a new hash object. Defaults to hashlib.md5. - Note: key and msg must be bytes objects. + Note: key must be a bytes or bytearray object. """ - if not isinstance(key, bytes): - raise TypeError("expected bytes, but got %r" % type(key).__name__) + if not isinstance(key, (bytes, bytearray)): + raise TypeError("expected bytes or bytearray, but got %r" % type(key).__name__) if digestmod is None: import hashlib @@ -73,8 +73,6 @@ 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):