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/sha1module.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/sha1module.c')
-rw-r--r-- | Modules/sha1module.c | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/Modules/sha1module.c b/Modules/sha1module.c index d1f8936..74b94ba 100644 --- a/Modules/sha1module.c +++ b/Modules/sha1module.c @@ -18,6 +18,7 @@ #include "Python.h" #include "hashlib.h" +#include "pystrhex.h" /*[clinic input] module _sha1 @@ -364,32 +365,12 @@ SHA1Type_hexdigest_impl(SHA1object *self) { unsigned char digest[SHA1_DIGESTSIZE]; struct sha1_state temp; - PyObject *retval; - Py_UCS1 *hex_digest; - int i, j; /* Get the raw (binary) digest value */ temp = self->hash_state; sha1_done(&temp, digest); - /* Create a new string */ - retval = PyUnicode_New(SHA1_DIGESTSIZE * 2, 127); - if (!retval) - return NULL; - hex_digest = PyUnicode_1BYTE_DATA(retval); - - /* Make hex version of the digest */ - for(i=j=0; i<SHA1_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, SHA1_DIGESTSIZE); } /*[clinic input] |