summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-07-10 13:20:29 (GMT)
committerGuido van Rossum <guido@python.org>2007-07-10 13:20:29 (GMT)
commitf895307a945d30fd5207f4c512ac2c0b5f59b335 (patch)
treeed20ee7d0702f5083493b14162365f972849a9b1
parentdc12288e1114a41221c5dbc1f300fea0a6cd83c5 (diff)
downloadcpython-f895307a945d30fd5207f4c512ac2c0b5f59b335.zip
cpython-f895307a945d30fd5207f4c512ac2c0b5f59b335.tar.gz
cpython-f895307a945d30fd5207f4c512ac2c0b5f59b335.tar.bz2
Make sure hexdigest() returns str, not str8.
-rw-r--r--Modules/_hashopenssl.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index 47fc674..dba1aa6 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -127,17 +127,10 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
EVP_MD_CTX_cleanup(&temp_ctx);
- /* Create a new string */
- /* NOTE: not thread safe! modifying an already created string object */
- /* (not a problem because we hold the GIL by default) */
- retval = PyString_FromStringAndSize(NULL, digest_size * 2);
- if (!retval)
- return NULL;
- hex_digest = PyString_AS_STRING(retval);
- if (!hex_digest) {
- Py_DECREF(retval);
- return NULL;
- }
+ /* 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++) {
@@ -149,6 +142,8 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
c = (c>9) ? c+'a'-10 : c + '0';
hex_digest[j++] = c;
}
+ retval = PyUnicode_FromStringAndSize(hex_digest, digest_size * 2);
+ PyMem_Free(hex_digest);
return retval;
}