Skip to content

Commit 7fd1396

Browse files
committed
reudce diff
1 parent 6c08f0d commit 7fd1396

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Modules/md5module.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include "Python.h"
2424
#include "hashlib.h"
25-
#include "pycore_strhex.h" // _Py_strhex()
2625

2726
/*[clinic input]
2827
module _md5
@@ -133,7 +132,7 @@ static PyObject *
133132
MD5Type_digest_impl(MD5object *self)
134133
/*[clinic end generated code: output=eb691dc4190a07ec input=bc0c4397c2994be6]*/
135134
{
136-
uint8_t digest[MD5_DIGESTSIZE];
135+
unsigned char digest[MD5_DIGESTSIZE];
137136
HASHLIB_ACQUIRE_LOCK(self);
138137
Hacl_Hash_MD5_digest(self->hash_state, digest);
139138
HASHLIB_RELEASE_LOCK(self);
@@ -150,11 +149,20 @@ static PyObject *
150149
MD5Type_hexdigest_impl(MD5object *self)
151150
/*[clinic end generated code: output=17badced1f3ac932 input=b60b19de644798dd]*/
152151
{
153-
uint8_t digest[MD5_DIGESTSIZE];
152+
unsigned char digest[MD5_DIGESTSIZE];
154153
HASHLIB_ACQUIRE_LOCK(self);
155154
Hacl_Hash_MD5_digest(self->hash_state, digest);
156155
HASHLIB_RELEASE_LOCK(self);
157-
return _Py_strhex((const char *)digest, MD5_DIGESTSIZE);
156+
157+
const char *hexdigits = "0123456789abcdef";
158+
char digest_hex[MD5_DIGESTSIZE * 2];
159+
char *str = digest_hex;
160+
for (size_t i=0; i < MD5_DIGESTSIZE; i++) {
161+
unsigned char byte = digest[i];
162+
*str++ = hexdigits[byte >> 4];
163+
*str++ = hexdigits[byte & 0x0f];
164+
}
165+
return PyUnicode_FromStringAndSize(digest_hex, sizeof(digest_hex));
158166
}
159167

160168
static void

0 commit comments

Comments
 (0)