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 21
21
#endif
22
22
23
23
#include "Python.h"
24
+ #include "pycore_strhex.h" // _Py_strhex()
25
+
24
26
#include "hashlib.h"
25
27
26
28
/*[clinic input]
@@ -136,7 +138,7 @@ static PyObject *
136
138
MD5Type_digest_impl (MD5object * self )
137
139
/*[clinic end generated code: output=eb691dc4190a07ec input=bc0c4397c2994be6]*/
138
140
{
139
- unsigned char digest [MD5_DIGESTSIZE ];
141
+ uint8_t digest [MD5_DIGESTSIZE ];
140
142
ENTER_HASHLIB (self );
141
143
Hacl_Hash_MD5_digest (self -> hash_state , digest );
142
144
LEAVE_HASHLIB (self );
@@ -153,20 +155,11 @@ static PyObject *
153
155
MD5Type_hexdigest_impl (MD5object * self )
154
156
/*[clinic end generated code: output=17badced1f3ac932 input=b60b19de644798dd]*/
155
157
{
156
- unsigned char digest [MD5_DIGESTSIZE ];
158
+ uint8_t digest [MD5_DIGESTSIZE ];
157
159
ENTER_HASHLIB (self );
158
160
Hacl_Hash_MD5_digest (self -> hash_state , digest );
159
161
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 );
170
163
}
171
164
172
165
static void
You can’t perform that action at this time.
0 commit comments