diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-08-21 02:45:15 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-08-21 02:45:15 (GMT) |
commit | 0cc7444ea9870c11b6ce0c61e4c761609f295f69 (patch) | |
tree | a224dd4313542388b7260dac81680a80e4e56240 /Lib/hmac.py | |
parent | bf6f31b65fa0947c97276b0007adc3276040c706 (diff) | |
download | cpython-0cc7444ea9870c11b6ce0c61e4c761609f295f69.zip cpython-0cc7444ea9870c11b6ce0c61e4c761609f295f69.tar.gz cpython-0cc7444ea9870c11b6ce0c61e4c761609f295f69.tar.bz2 |
speed hack can be implemented more cleanly by directly calling __new__
Diffstat (limited to 'Lib/hmac.py')
-rw-r--r-- | Lib/hmac.py | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/Lib/hmac.py b/Lib/hmac.py index 5572751..e878e1a 100644 --- a/Lib/hmac.py +++ b/Lib/hmac.py @@ -12,10 +12,6 @@ trans_36 = bytes((x ^ 0x36) for x in range(256)) # 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 -# that the latter return very quickly. HMAC("") in contrast is quite -# expensive. -_secret_backdoor_key = object() class HMAC: """RFC 2104 HMAC class. Also complies with RFC 4231. @@ -36,9 +32,6 @@ class HMAC: Note: key and msg must be bytes objects. """ - if key is _secret_backdoor_key: # cheap - return - if not isinstance(key, bytes): raise TypeError("expected bytes, but got %r" % type(key).__name__) @@ -89,7 +82,8 @@ class HMAC: An update to this copy won't affect the original object. """ - other = self.__class__(_secret_backdoor_key) + # Call __new__ directly to avoid the expensive __init__. + other = self.__class__.__new__(self.__class__) other.digest_cons = self.digest_cons other.digest_size = self.digest_size other.inner = self.inner.copy() |