diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-07-31 06:50:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-31 06:50:16 (GMT) |
commit | f1d36d8efaecd5c84cb35e35119b283f37d83c40 (patch) | |
tree | 055434182e3f7859d01386eac0766fc7a1d69193 /Lib/hashlib.py | |
parent | 4b8a7f51da224d1a0ad8159935f78ba4e6e16037 (diff) | |
download | cpython-f1d36d8efaecd5c84cb35e35119b283f37d83c40.zip cpython-f1d36d8efaecd5c84cb35e35119b283f37d83c40.tar.gz cpython-f1d36d8efaecd5c84cb35e35119b283f37d83c40.tar.bz2 |
bpo-33729: Fix issues with arguments parsing in hashlib. (GH-8346)
* help(hashlib) didn't work because of incorrect module name in blake2b and
blake2s classes.
* Constructors blake2*(), sha3_*(), shake_*() and keccak_*() incorrectly
accepted keyword argument "string" for binary data, but documented as
accepting the "data" keyword argument. Now this parameter is positional-only.
* Keyword-only parameters in blake2b() and blake2s() were not documented as
keyword-only.
* Default value for some parameters of blake2b() and blake2s() was None,
which is not acceptable value.
* The length argument for shake_*.digest() was wrapped out to 32 bits.
* The argument for shake_128.digest() and shake_128.hexdigest() was not
positional-only as intended.
* TypeError messages for incorrect arguments in all constructors sha3_*(),
shake_*() and keccak_*() incorrectly referred to sha3_224.
Also made the following enhancements:
* More accurately specified input and result types for strings, bytes and
bytes-like objects.
* Unified positional parameter names for update() and constructors.
* Improved formatting.
Diffstat (limited to 'Lib/hashlib.py')
-rw-r--r-- | Lib/hashlib.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py index e30c610..4e783a8 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -25,18 +25,18 @@ Choose your hash function wisely. Some have known collision weaknesses. sha384 and sha512 will be slow on 32 bit platforms. Hash objects have these methods: - - update(arg): Update the hash object with the bytes in arg. Repeated calls - are equivalent to a single call with the concatenation of all - the arguments. - - digest(): Return the digest of the bytes passed to the update() method - so far. - - hexdigest(): Like digest() except the digest is returned as a unicode - object of double length, containing only hexadecimal digits. - - copy(): Return a copy (clone) of the hash object. This can be used to - efficiently compute the digests of strings that share a common - initial substring. - -For example, to obtain the digest of the string 'Nobody inspects the + - update(data): Update the hash object with the bytes in data. Repeated calls + are equivalent to a single call with the concatenation of all + the arguments. + - digest(): Return the digest of the bytes passed to the update() method + so far as a bytes object. + - hexdigest(): Like digest() except the digest is returned as a string + of double length, containing only hexadecimal digits. + - copy(): Return a copy (clone) of the hash object. This can be used to + efficiently compute the digests of datas that share a common + initial substring. + +For example, to obtain the digest of the byte string 'Nobody inspects the spammish repetition': >>> import hashlib @@ -130,14 +130,15 @@ def __get_openssl_constructor(name): def __py_new(name, data=b'', **kwargs): """new(name, data=b'', **kwargs) - Return a new hashing object using the - named algorithm; optionally initialized with data (which must be bytes). + named algorithm; optionally initialized with data (which must be + a bytes-like object). """ return __get_builtin_constructor(name)(data, **kwargs) def __hash_new(name, data=b'', **kwargs): """new(name, data=b'') - Return a new hashing object using the named algorithm; - optionally initialized with data (which must be bytes). + optionally initialized with data (which must be a bytes-like object). """ if name in {'blake2b', 'blake2s'}: # Prefer our blake2 implementation. |