diff options
Diffstat (limited to 'Modules/sha512module.c')
-rw-r--r-- | Modules/sha512module.c | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/Modules/sha512module.c b/Modules/sha512module.c index 4533c00..8237d86 100644 --- a/Modules/sha512module.c +++ b/Modules/sha512module.c @@ -19,6 +19,7 @@ #include "Python.h" #include "structmember.h" #include "hashlib.h" +#include "pystrhex.h" /*[clinic input] module _sha512 @@ -521,32 +522,12 @@ SHA512Type_hexdigest_impl(SHAobject *self) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; - PyObject *retval; - Py_UCS1 *hex_digest; - int i, j; /* Get the raw (binary) digest value */ SHAcopy(self, &temp); sha512_final(digest, &temp); - /* Create a new string */ - retval = PyUnicode_New(self->digestsize * 2, 127); - if (!retval) - return NULL; - hex_digest = PyUnicode_1BYTE_DATA(retval); - - /* Make hex version of the digest */ - for (i=j=0; i<self->digestsize; i++) { - unsigned char c; - c = (digest[i] >> 4) & 0xf; - hex_digest[j++] = Py_hexdigits[c]; - c = (digest[i] & 0xf); - hex_digest[j++] = Py_hexdigits[c]; - } -#ifdef Py_DEBUG - assert(_PyUnicode_CheckConsistency(retval, 1)); -#endif - return retval; + return _Py_strhex((const char *)digest, self->digestsize); } /*[clinic input] |