summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_hmac.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2013-07-01 11:08:42 (GMT)
committerChristian Heimes <christian@cheimes.de>2013-07-01 11:08:42 (GMT)
commit04926aeb2f88c39a25505e4a0474c6fb735e0f46 (patch)
treee2f8f58f84ec61dfb533a58320af98409c9b5c57 /Lib/test/test_hmac.py
parentec4bdac8dd8c1a2fb6c211046dd0fca47a9896f2 (diff)
downloadcpython-04926aeb2f88c39a25505e4a0474c6fb735e0f46.zip
cpython-04926aeb2f88c39a25505e4a0474c6fb735e0f46.tar.gz
cpython-04926aeb2f88c39a25505e4a0474c6fb735e0f46.tar.bz2
Issue 18240: The HMAC module is no longer restricted to bytes and accepts
any bytes-like object, e.g. memoryview. Original patch by Jonas Borgström.
Diffstat (limited to 'Lib/test/test_hmac.py')
-rw-r--r--Lib/test/test_hmac.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py
index 4ca7cec..efd63ad 100644
--- a/Lib/test/test_hmac.py
+++ b/Lib/test/test_hmac.py
@@ -253,6 +253,20 @@ class ConstructorTestCase(unittest.TestCase):
except:
self.fail("Constructor call with text argument raised exception.")
+ def test_with_bytearray(self):
+ try:
+ h = hmac.HMAC(bytearray(b"key"), bytearray(b"hash this!"))
+ self.assertEqual(h.hexdigest(), '34325b639da4cfd95735b381e28cb864')
+ except:
+ self.fail("Constructor call with bytearray arguments raised exception.")
+
+ def test_with_memoryview_msg(self):
+ try:
+ h = hmac.HMAC(b"key", memoryview(b"hash this!"))
+ self.assertEqual(h.hexdigest(), '34325b639da4cfd95735b381e28cb864')
+ except:
+ self.fail("Constructor call with memoryview msg raised exception.")
+
def test_withmodule(self):
# Constructor call with text and digest module.
try: