File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change 2121#endif
2222
2323#include "Python.h"
24+ #include "pycore_strhex.h" // _Py_strhex()
25+
2426#include "hashlib.h"
2527
2628/*[clinic input]
@@ -136,7 +138,7 @@ static PyObject *
136138MD5Type_digest_impl (MD5object * self )
137139/*[clinic end generated code: output=eb691dc4190a07ec input=bc0c4397c2994be6]*/
138140{
139- unsigned char digest [MD5_DIGESTSIZE ];
141+ uint8_t digest [MD5_DIGESTSIZE ];
140142 ENTER_HASHLIB (self );
141143 Hacl_Hash_MD5_digest (self -> hash_state , digest );
142144 LEAVE_HASHLIB (self );
@@ -153,20 +155,11 @@ static PyObject *
153155MD5Type_hexdigest_impl (MD5object * self )
154156/*[clinic end generated code: output=17badced1f3ac932 input=b60b19de644798dd]*/
155157{
156- unsigned char digest [MD5_DIGESTSIZE ];
158+ uint8_t digest [MD5_DIGESTSIZE ];
157159 ENTER_HASHLIB (self );
158160 Hacl_Hash_MD5_digest (self -> hash_state , digest );
159161 LEAVE_HASHLIB (self );
160-
161- const char * hexdigits = "0123456789abcdef" ;
162- char digest_hex [MD5_DIGESTSIZE * 2 ];
163- char * str = digest_hex ;
164- for (size_t i = 0 ; i < MD5_DIGESTSIZE ; i ++ ) {
165- unsigned char byte = digest [i ];
166- * str ++ = hexdigits [byte >> 4 ];
167- * str ++ = hexdigits [byte & 0x0f ];
168- }
169- return PyUnicode_FromStringAndSize (digest_hex , sizeof (digest_hex ));
162+ return _Py_strhex ((const char * )digest , MD5_DIGESTSIZE );
170163}
171164
172165static void
You can’t perform that action at this time.
0 commit comments