diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2006-12-27 03:31:24 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2006-12-27 03:31:24 (GMT) |
commit | 71662323992907f1da51ea61a6f29b09e571c089 (patch) | |
tree | cb36bc45b63ffe3bba59c33dc067683885aef873 /Lib/hmac.py | |
parent | a7ebb33975ab31fb794774010e9bd52685314517 (diff) | |
download | cpython-71662323992907f1da51ea61a6f29b09e571c089.zip cpython-71662323992907f1da51ea61a6f29b09e571c089.tar.gz cpython-71662323992907f1da51ea61a6f29b09e571c089.tar.bz2 |
[Rest of patch #1182394] Add ._current() method so that we can use the written-in-C .hexdigest() method
Diffstat (limited to 'Lib/hmac.py')
-rw-r--r-- | Lib/hmac.py | 16 |
1 files changed, 12 insertions, 4 deletions
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 @@ 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. |