@@ -1101,39 +1101,38 @@ _hashlib_HASHXOF_digest_impl(HASHobject *self, Py_ssize_t length)
1101
1101
/*[clinic end generated code: output=dcb09335dd2fe908 input=224d047da2c12a42]*/
1102
1102
{
1103
1103
EVP_MD_CTX * temp_ctx ;
1104
- PyObject * retval ;
1105
1104
1106
1105
if (length == 0 ) {
1107
1106
return Py_GetConstant (Py_CONSTANT_EMPTY_BYTES );
1108
1107
}
1109
1108
1110
- retval = PyBytes_FromStringAndSize ( NULL , length );
1111
- if (retval == NULL ) {
1109
+ PyBytesWriter * writer = PyBytesWriter_Create ( length );
1110
+ if (writer == NULL ) {
1112
1111
return NULL ;
1113
1112
}
1114
1113
1115
1114
temp_ctx = py_wrapper_EVP_MD_CTX_new ();
1116
1115
if (temp_ctx == NULL ) {
1117
- Py_DECREF ( retval );
1116
+ PyBytesWriter_Discard ( writer );
1118
1117
return NULL ;
1119
1118
}
1120
1119
1121
1120
if (_hashlib_HASH_copy_locked (self , temp_ctx ) < 0 ) {
1122
1121
goto error ;
1123
1122
}
1124
1123
if (!EVP_DigestFinalXOF (temp_ctx ,
1125
- (unsigned char * )PyBytes_AS_STRING ( retval ),
1124
+ (unsigned char * )PyBytesWriter_GetData ( writer ),
1126
1125
length ))
1127
1126
{
1128
1127
notify_ssl_error_occurred_in (Py_STRINGIFY (EVP_DigestFinalXOF ));
1129
1128
goto error ;
1130
1129
}
1131
1130
1132
1131
EVP_MD_CTX_free (temp_ctx );
1133
- return retval ;
1132
+ return PyBytesWriter_Finish ( writer ) ;
1134
1133
1135
1134
error :
1136
- Py_DECREF ( retval );
1135
+ PyBytesWriter_Discard ( writer );
1137
1136
EVP_MD_CTX_free (temp_ctx );
1138
1137
return NULL ;
1139
1138
}
@@ -1750,7 +1749,6 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
1750
1749
long maxmem , long dklen )
1751
1750
/*[clinic end generated code: output=d424bc3e8c6b9654 input=bdeac9628d07f7a1]*/
1752
1751
{
1753
- PyObject * key = NULL ;
1754
1752
int retval ;
1755
1753
1756
1754
if (password -> len > INT_MAX ) {
@@ -1791,8 +1789,8 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
1791
1789
return NULL ;
1792
1790
}
1793
1791
1794
- key = PyBytes_FromStringAndSize ( NULL , dklen );
1795
- if (key == NULL ) {
1792
+ PyBytesWriter * writer = PyBytesWriter_Create ( dklen );
1793
+ if (writer == NULL ) {
1796
1794
return NULL ;
1797
1795
}
1798
1796
@@ -1801,16 +1799,16 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt,
1801
1799
(const char * )password -> buf , (size_t )password -> len ,
1802
1800
(const unsigned char * )salt -> buf , (size_t )salt -> len ,
1803
1801
(uint64_t )n , (uint64_t )r , (uint64_t )p , (uint64_t )maxmem ,
1804
- ( unsigned char * ) PyBytes_AS_STRING ( key ), (size_t )dklen
1802
+ PyBytesWriter_GetData ( writer ), (size_t )dklen
1805
1803
);
1806
1804
Py_END_ALLOW_THREADS
1807
1805
1808
1806
if (!retval ) {
1809
- Py_DECREF ( key );
1807
+ PyBytesWriter_Discard ( writer );
1810
1808
notify_ssl_error_occurred_in (Py_STRINGIFY (EVP_PBE_scrypt ));
1811
1809
return NULL ;
1812
1810
}
1813
- return key ;
1811
+ return PyBytesWriter_Finish ( writer ) ;
1814
1812
}
1815
1813
1816
1814
#undef HASHLIB_SCRYPT_MAX_DKLEN
0 commit comments