mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.14] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134961)
OpenSSL and HACL*-based hash functions constructors now support both `data` and `string` parameters. Previously these constructor functions inconsistently supported sometimes `data` and sometimes `string`, while the documentation expected `data` to be given in all cases. (cherry picked from commitc6e63d9d35
) (cherry picked from commit379d0bc956
)
This commit is contained in:
parent
5d07d16d45
commit
777fd4979c
16 changed files with 937 additions and 502 deletions
|
@ -141,29 +141,29 @@ def __get_openssl_constructor(name):
|
|||
return __get_builtin_constructor(name)
|
||||
|
||||
|
||||
def __py_new(name, data=b'', **kwargs):
|
||||
def __py_new(name, *args, **kwargs):
|
||||
"""new(name, data=b'', **kwargs) - Return a new hashing object using the
|
||||
named algorithm; optionally initialized with data (which must be
|
||||
a bytes-like object).
|
||||
"""
|
||||
return __get_builtin_constructor(name)(data, **kwargs)
|
||||
return __get_builtin_constructor(name)(*args, **kwargs)
|
||||
|
||||
|
||||
def __hash_new(name, data=b'', **kwargs):
|
||||
def __hash_new(name, *args, **kwargs):
|
||||
"""new(name, data=b'') - Return a new hashing object using the named algorithm;
|
||||
optionally initialized with data (which must be a bytes-like object).
|
||||
"""
|
||||
if name in __block_openssl_constructor:
|
||||
# Prefer our builtin blake2 implementation.
|
||||
return __get_builtin_constructor(name)(data, **kwargs)
|
||||
return __get_builtin_constructor(name)(*args, **kwargs)
|
||||
try:
|
||||
return _hashlib.new(name, data, **kwargs)
|
||||
return _hashlib.new(name, *args, **kwargs)
|
||||
except ValueError:
|
||||
# If the _hashlib module (OpenSSL) doesn't support the named
|
||||
# hash, try using our builtin implementations.
|
||||
# This allows for SHA224/256 and SHA384/512 support even though
|
||||
# the OpenSSL library prior to 0.9.8 doesn't provide them.
|
||||
return __get_builtin_constructor(name)(data)
|
||||
return __get_builtin_constructor(name)(*args, **kwargs)
|
||||
|
||||
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue