mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
Issue #15225: improve error message when hmac is passed a wrong key type.
Patch by Marc Abramowitz.
This commit is contained in:
parent
9c7817e9ee
commit
24ef3e967f
3 changed files with 14 additions and 1 deletions
|
|
@ -35,7 +35,7 @@ def __init__(self, key, msg = None, digestmod = None):
|
|||
"""
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -234,6 +234,18 @@ def test_normal(self):
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ and the list is in rough alphabetical order by last names.
|
|||
|
||||
Rajiv Abraham
|
||||
David Abrahams
|
||||
Marc Abramowitz
|
||||
Ron Adam
|
||||
Ali Afshar
|
||||
Jim Ahlstrom
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue