diff options
author | Gregory P. Smith <greg@krypto.org> | 2015-04-25 23:22:26 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2015-04-25 23:22:26 (GMT) |
commit | 8cb6569fe14ba8e57ab1a2bea68594747852a9d1 (patch) | |
tree | 4391a41ff833b66e6482f5abbf7f0714f23ccf67 /Modules/sha512module.c | |
parent | 644adc6adaecf5249de68211f70c0825a36fe6f7 (diff) | |
download | cpython-8cb6569fe14ba8e57ab1a2bea68594747852a9d1.zip cpython-8cb6569fe14ba8e57ab1a2bea68594747852a9d1.tar.gz cpython-8cb6569fe14ba8e57ab1a2bea68594747852a9d1.tar.bz2 |
Implements issue #9951: Adds a hex() method to bytes, bytearray, & memoryview.
Also updates a few internal implementations of the same thing to use the
new built-in code.
Contributed by Arnon Yaari.
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] |