]> granicus.if.org Git - python/commitdiff
[Rest of patch #1182394] Add ._current() method so that we can use the written-in...
authorAndrew M. Kuchling <amk@amk.ca>
Wed, 27 Dec 2006 03:31:24 +0000 (03:31 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Wed, 27 Dec 2006 03:31:24 +0000 (03:31 +0000)
Lib/hmac.py
Misc/ACKS
Misc/NEWS

index ed5afc711ae54fbcd313fbffdbd643d0e3d2deca..88c3fd5377a56c651df305d0f570b10a3b8f0fb8 100644 (file)
@@ -78,6 +78,15 @@ class HMAC:
         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 @@ class HMAC:
         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.
index d5d7675bc25d48bf332d6c4693e7ad4a96e917ad..b1981140b0a33b875c2f6945a44897433e390dea 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -285,6 +285,7 @@ Chris Hoffman
 Albert Hofkamp
 Jonathan Hogg
 Gerrit Holl
+Shane Holloway
 Rune Holm
 Philip Homburg
 Naofumi Honda
index 92f81ebff4337583770f0c4de152079516a007d8..363320b1ea32d84fa647ed2c78520d9e693ca159 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,6 +103,8 @@ Core and builtins
 Library
 -------
 
+- Patch #1182394 from Shane Holloway: speed up HMAC.hexdigest.
+
 - Patch #1262036: Prevent TarFiles from being added to themselves under
   certain conditions.