mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (#134713)
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.
This commit is contained in:
parent
4d31d19a1d
commit
c6e63d9d35
16 changed files with 830 additions and 421 deletions
|
@ -76,3 +76,32 @@
|
|||
* to allow the user to optimize based on the platform they're using. */
|
||||
#define HASHLIB_GIL_MINSIZE 2048
|
||||
|
||||
static inline int
|
||||
_Py_hashlib_data_argument(PyObject **res, PyObject *data, PyObject *string)
|
||||
{
|
||||
if (data != NULL && string == NULL) {
|
||||
// called as H(data) or H(data=...)
|
||||
*res = data;
|
||||
return 1;
|
||||
}
|
||||
else if (data == NULL && string != NULL) {
|
||||
// called as H(string=...)
|
||||
*res = string;
|
||||
return 1;
|
||||
}
|
||||
else if (data == NULL && string == NULL) {
|
||||
// fast path when no data is given
|
||||
assert(!PyErr_Occurred());
|
||||
*res = NULL;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
// called as H(data=..., string)
|
||||
*res = NULL;
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"'data' and 'string' are mutually exclusive "
|
||||
"and support for 'string' keyword parameter "
|
||||
"is slated for removal in a future version.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue