bpo-33604: Raise TypeError on missing hmac arg. (GH-16805)

Also updates the documentation to clarify the situation surrounding
the digestmod parameter that is required despite its position in the
argument list as of 3.8.0 as well as removing old python2 era
references to "binary strings".

We indavertently had this raise ValueError in 3.8.0 for the missing
arg.  This is not considered an API change as no reasonable code would
be catching this missing argument error in order to handle it.
This commit is contained in:
Gregory P. Smith 2019-10-17 20:30:42 -07:00 committed by GitHub
parent d8ca2354ed
commit f33c57d5c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 28 deletions

View file

@ -14,12 +14,13 @@
This module implements the HMAC algorithm as described by :rfc:`2104`.
.. function:: new(key, msg=None, digestmod=None)
.. function:: new(key, msg=None, digestmod='')
Return a new hmac object. *key* is a bytes or bytearray object giving the
secret key. If *msg* is present, the method call ``update(msg)`` is made.
*digestmod* is the digest name, digest constructor or module for the HMAC
object to use. It supports any name suitable to :func:`hashlib.new`.
object to use. It may be any name suitable to :func:`hashlib.new`.
Despite its argument position, it is required.
.. versionchanged:: 3.4
Parameter *key* can be a bytes or bytearray object.
@ -28,6 +29,8 @@ This module implements the HMAC algorithm as described by :rfc:`2104`.
.. deprecated-removed:: 3.4 3.8
MD5 as implicit default digest for *digestmod* is deprecated.
The digestmod parameter is now required. Pass it as a keyword
argument to avoid awkwardness when you do not have an initial msg.
.. function:: digest(key, msg, digest)
@ -127,7 +130,6 @@ This module also provides the following helper function:
a timing attack could theoretically reveal information about the
types and lengths of *a* and *b*—but not their values.
.. versionadded:: 3.3