[Rest of patch #1182394] Add ._current() method so that we can use the written-in-C .hexdigest() method
This commit is contained in:
parent
a7ebb33975
commit
7166232399
16
Lib/hmac.py
16
Lib/hmac.py
|
@ -78,6 +78,15 @@ class HMAC:
|
||||||
other.outer = self.outer.copy()
|
other.outer = self.outer.copy()
|
||||||
return other
|
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):
|
def digest(self):
|
||||||
"""Return the hash value of this hashing object.
|
"""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
|
not altered in any way by this function; you can continue
|
||||||
updating the object after calling this function.
|
updating the object after calling this function.
|
||||||
"""
|
"""
|
||||||
h = self.outer.copy()
|
h = self._current()
|
||||||
h.update(self.inner.digest())
|
|
||||||
return h.digest()
|
return h.digest()
|
||||||
|
|
||||||
def hexdigest(self):
|
def hexdigest(self):
|
||||||
"""Like digest(), but returns a string of hexadecimal digits instead.
|
"""Like digest(), but returns a string of hexadecimal digits instead.
|
||||||
"""
|
"""
|
||||||
return "".join([hex(ord(x))[2:].zfill(2)
|
h = self._current()
|
||||||
for x in tuple(self.digest())])
|
return h.hexdigest()
|
||||||
|
|
||||||
def new(key, msg = None, digestmod = None):
|
def new(key, msg = None, digestmod = None):
|
||||||
"""Create a new hashing object and return it.
|
"""Create a new hashing object and return it.
|
||||||
|
|
|
@ -285,6 +285,7 @@ Chris Hoffman
|
||||||
Albert Hofkamp
|
Albert Hofkamp
|
||||||
Jonathan Hogg
|
Jonathan Hogg
|
||||||
Gerrit Holl
|
Gerrit Holl
|
||||||
|
Shane Holloway
|
||||||
Rune Holm
|
Rune Holm
|
||||||
Philip Homburg
|
Philip Homburg
|
||||||
Naofumi Honda
|
Naofumi Honda
|
||||||
|
|
|
@ -103,6 +103,8 @@ Core and builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Patch #1182394 from Shane Holloway: speed up HMAC.hexdigest.
|
||||||
|
|
||||||
- Patch #1262036: Prevent TarFiles from being added to themselves under
|
- Patch #1262036: Prevent TarFiles from being added to themselves under
|
||||||
certain conditions.
|
certain conditions.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue