Patch by Marc Abramowitz.
"""
if not isinstance(key, bytes):
- raise TypeError("expected bytes, but got %r" % type(key).__name__)
+ raise TypeError("key: expected bytes, but got %r" % type(key).__name__)
if digestmod is None:
import hashlib
except:
self.fail("Standard constructor call raised exception.")
+ def test_with_str_key(self):
+ # Pass a key of type str, which is an error, because it expects a key
+ # of type bytes
+ with self.assertRaises(TypeError):
+ h = hmac.HMAC("key")
+
+ def test_dot_new_with_str_key(self):
+ # Pass a key of type str, which is an error, because it expects a key
+ # of type bytes
+ with self.assertRaises(TypeError):
+ h = hmac.new("key")
+
def test_withtext(self):
# Constructor call with text.
try:
Rajiv Abraham
David Abrahams
+Marc Abramowitz
Ron Adam
Ali Afshar
Jim Ahlstrom