diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Crypto/Hash/CMAC.py | 2 | ||||
-rw-r--r-- | lib/Crypto/Hash/HMAC.py | 2 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/Hash/common.py | 12 |
3 files changed, 13 insertions, 3 deletions
diff --git a/lib/Crypto/Hash/CMAC.py b/lib/Crypto/Hash/CMAC.py index 107db96..6305054 100644 --- a/lib/Crypto/Hash/CMAC.py +++ b/lib/Crypto/Hash/CMAC.py @@ -320,7 +320,7 @@ class CMAC(_SmoothMAC): has been tampered with or that the MAC key is incorrect. """ - self.verify(unhexlify(hex_mac_tag)) + self.verify(unhexlify(tobytes(hex_mac_tag))) def new(key, msg = None, ciphermod = None): """Create a new CMAC object. diff --git a/lib/Crypto/Hash/HMAC.py b/lib/Crypto/Hash/HMAC.py index b44a082..8865411 100644 --- a/lib/Crypto/Hash/HMAC.py +++ b/lib/Crypto/Hash/HMAC.py @@ -238,7 +238,7 @@ class HMAC: has been tampered with or that the MAC key is incorrect. """ - self.verify(unhexlify(hex_mac_tag)) + self.verify(unhexlify(tobytes(hex_mac_tag))) def new(key, msg = None, digestmod = None): """Create a new HMAC object. diff --git a/lib/Crypto/SelfTest/Hash/common.py b/lib/Crypto/SelfTest/Hash/common.py index 968caa2..2b3cbc3 100644 --- a/lib/Crypto/SelfTest/Hash/common.py +++ b/lib/Crypto/SelfTest/Hash/common.py @@ -206,7 +206,17 @@ class MACSelfTest(unittest.TestCase): h.update(b("blah blah blah")) # Corrupt the original hash object out5 = binascii.b2a_hex(h2.digest()) # The copied hash object should return the correct result - # PY3K: hexdigest() should return str(), and digest() bytes + # PY3K: Check that hexdigest() returns str and digest() returns bytes + if sys.version_info[0] > 2: + self.assertTrue(isinstance(h.digest(), type(b("")))) + self.assertTrue(isinstance(h.hexdigest(), type(""))) + + # PY3K: Check that .hexverify() accepts bytes or str + if sys.version_info[0] > 2: + h.hexverify(h.hexdigest()) + h.hexverify(h.hexdigest().encode('ascii')) + + # PY3K: hexdigest() should return str, and digest() should return bytes self.assertEqual(expected, out1) if sys.version_info[0] == 2: self.assertEqual(expected, out2) |