diff options
author | Gregory P. Smith <greg@krypto.org> | 2015-04-25 23:42:38 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2015-04-25 23:42:38 (GMT) |
commit | 4dff6f6fa6bfdc14c570d0c6a63021640203e1a6 (patch) | |
tree | 0748440dd4b6782350481e768aa3ec56b48426e3 /Modules/_hashopenssl.c | |
parent | 8cb6569fe14ba8e57ab1a2bea68594747852a9d1 (diff) | |
download | cpython-4dff6f6fa6bfdc14c570d0c6a63021640203e1a6.zip cpython-4dff6f6fa6bfdc14c570d0c6a63021640203e1a6.tar.gz cpython-4dff6f6fa6bfdc14c570d0c6a63021640203e1a6.tar.bz2 |
Issue9951: update _hashopenssl and md5module to use _Py_strhex().
Also update _posixsubprocess to use Py_hexdigits instead of its own constant.
Diffstat (limited to 'Modules/_hashopenssl.c')
-rw-r--r-- | Modules/_hashopenssl.c | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 1566b18..a157fbb 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -16,6 +16,7 @@ #include "Python.h" #include "structmember.h" #include "hashlib.h" +#include "pystrhex.h" /* EVP is the preferred interface to hashing in OpenSSL */ @@ -157,9 +158,7 @@ EVP_hexdigest(EVPobject *self, PyObject *unused) { unsigned char digest[EVP_MAX_MD_SIZE]; EVP_MD_CTX temp_ctx; - PyObject *retval; - char *hex_digest; - unsigned int i, j, digest_size; + unsigned int digest_size; /* Get the raw (binary) digest value */ locked_EVP_MD_CTX_copy(&temp_ctx, self); @@ -168,22 +167,7 @@ EVP_hexdigest(EVPobject *self, PyObject *unused) EVP_MD_CTX_cleanup(&temp_ctx); - /* Allocate a new buffer */ - hex_digest = PyMem_Malloc(digest_size * 2 + 1); - if (!hex_digest) - return PyErr_NoMemory(); - - /* Make hex version of the digest */ - for(i=j=0; i<digest_size; 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]; - } - retval = PyUnicode_FromStringAndSize(hex_digest, digest_size * 2); - PyMem_Free(hex_digest); - return retval; + return _Py_strhex((const char *)digest, digest_size); } PyDoc_STRVAR(EVP_update__doc__, |