Skip to content

Commit 6d7e37d

Browse files
committed
Convert _hashopenssl function
1 parent b864c26 commit 6d7e37d

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Modules/_hashopenssl.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,6 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
14141414
long maxmem, long dklen)
14151415
/*[clinic end generated code: output=14849e2aa2b7b46c input=48a7d63bf3f75c42]*/
14161416
{
1417-
PyObject *key_obj = NULL;
1418-
char *key;
14191417
int retval;
14201418
unsigned long n, r, p;
14211419

@@ -1486,27 +1484,27 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
14861484
return NULL;
14871485
}
14881486

1489-
key_obj = PyBytes_FromStringAndSize(NULL, dklen);
1490-
if (key_obj == NULL) {
1487+
PyBytesWriter *writer = PyBytesWriter_Create(dklen);
1488+
if (writer == NULL) {
14911489
return NULL;
14921490
}
1493-
key = PyBytes_AS_STRING(key_obj);
1491+
unsigned char *key = PyBytesWriter_GetData(writer);
14941492

14951493
Py_BEGIN_ALLOW_THREADS
14961494
retval = EVP_PBE_scrypt(
14971495
(const char*)password->buf, (size_t)password->len,
14981496
(const unsigned char *)salt->buf, (size_t)salt->len,
14991497
n, r, p, maxmem,
1500-
(unsigned char *)key, (size_t)dklen
1498+
key, (size_t)dklen
15011499
);
15021500
Py_END_ALLOW_THREADS
15031501

15041502
if (!retval) {
1505-
Py_CLEAR(key_obj);
1503+
PyBytesWriter_Discard(writer);
15061504
notify_ssl_error_occurred();
15071505
return NULL;
15081506
}
1509-
return key_obj;
1507+
return PyBytesWriter_Finish(writer);
15101508
}
15111509
#endif /* PY_OPENSSL_HAS_SCRYPT */
15121510

0 commit comments

Comments
 (0)