summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-12-27 03:25:31 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2006-12-27 03:25:31 (GMT)
commita7ebb33975ab31fb794774010e9bd52685314517 (patch)
treecfcfed8c538122837acbda6dc9a741285d2db595 /Lib
parenta4b2381b20edfc8be76df63ef06c0f15959ad7a3 (diff)
downloadcpython-a7ebb33975ab31fb794774010e9bd52685314517.zip
cpython-a7ebb33975ab31fb794774010e9bd52685314517.tar.gz
cpython-a7ebb33975ab31fb794774010e9bd52685314517.tar.bz2
[Part of patch #1182394] Move the HMAC blocksize to be a class-level
constant; this allows changing it in a subclass. To accommodate this, copy() now uses __class__. Also add some text to a comment.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/hmac.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/hmac.py b/Lib/hmac.py
index df2bffd..ed5afc7 100644
--- a/Lib/hmac.py
+++ b/Lib/hmac.py
@@ -7,7 +7,7 @@ trans_5C = "".join ([chr (x ^ 0x5C) for x in xrange(256)])
trans_36 = "".join ([chr (x ^ 0x36) for x in xrange(256)])
# The size of the digests returned by HMAC depends on the underlying
-# hashing module used.
+# hashing module used. Use digest_size from the instance of HMAC instead.
digest_size = None
# A unique object passed by HMAC.copy() to the HMAC constructor, in order
@@ -20,6 +20,7 @@ class HMAC:
This supports the API for Cryptographic Hash Functions (PEP 247).
"""
+ blocksize = 64 # 512-bit HMAC; can be changed in subclasses.
def __init__(self, key, msg = None, digestmod = None):
"""Create a new HMAC object.
@@ -47,7 +48,7 @@ class HMAC:
self.inner = self.digest_cons()
self.digest_size = self.inner.digest_size
- blocksize = 64
+ blocksize = self.blocksize
if len(key) > blocksize:
key = self.digest_cons(key).digest()
@@ -70,7 +71,7 @@ class HMAC:
An update to this copy won't affect the original object.
"""
- other = HMAC(_secret_backdoor_key)
+ other = self.__class__(_secret_backdoor_key)
other.digest_cons = self.digest_cons
other.digest_size = self.digest_size
other.inner = self.inner.copy()