[Rest of patch #1182394] Add ._current() method so that we can use the written-in-C .hexdigest() method
diff --git a/Lib/hmac.py b/Lib/hmac.py
index ed5afc7..88c3fd5 100644
--- a/Lib/hmac.py
+++ b/Lib/hmac.py
@@ -78,6 +78,15 @@
other.outer = self.outer.copy()
return other
+ def _current(self):
+ """Return a hash object for the current state.
+
+ To be used only internally with digest() and hexdigest().
+ """
+ h = self.outer.copy()
+ h.update(self.inner.digest())
+ return h
+
def digest(self):
"""Return the hash value of this hashing object.
@@ -85,15 +94,14 @@
not altered in any way by this function; you can continue
updating the object after calling this function.
"""
- h = self.outer.copy()
- h.update(self.inner.digest())
+ h = self._current()
return h.digest()
def hexdigest(self):
"""Like digest(), but returns a string of hexadecimal digits instead.
"""
- return "".join([hex(ord(x))[2:].zfill(2)
- for x in tuple(self.digest())])
+ h = self._current()
+ return h.hexdigest()
def new(key, msg = None, digestmod = None):
"""Create a new hashing object and return it.
diff --git a/Misc/ACKS b/Misc/ACKS
index d5d7675..b198114 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -285,6 +285,7 @@
Albert Hofkamp
Jonathan Hogg
Gerrit Holl
+Shane Holloway
Rune Holm
Philip Homburg
Naofumi Honda
diff --git a/Misc/NEWS b/Misc/NEWS
index 92f81eb..363320b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,8 @@
Library
-------
+- Patch #1182394 from Shane Holloway: speed up HMAC.hexdigest.
+
- Patch #1262036: Prevent TarFiles from being added to themselves under
certain conditions.