summaryrefslogtreecommitdiff
path: root/Modules/sha256module.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/sha256module.c')
-rw-r--r--Modules/sha256module.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index 8617210917..9f6b41639c 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -445,7 +445,7 @@ SHA256_hexdigest(SHAobject *self, PyObject *unused)
unsigned char digest[SHA_DIGESTSIZE];
SHAobject temp;
PyObject *retval;
- Py_UNICODE *hex_digest;
+ Py_UCS1 *hex_digest;
int i, j;
/* Get the raw (binary) digest value */
@@ -453,25 +453,22 @@ SHA256_hexdigest(SHAobject *self, PyObject *unused)
sha_final(digest, &temp);
/* Create a new string */
- retval = PyUnicode_FromStringAndSize(NULL, self->digestsize * 2);
+ retval = PyUnicode_New(self->digestsize * 2, 127);
if (!retval)
return NULL;
- hex_digest = PyUnicode_AS_UNICODE(retval);
- if (!hex_digest) {
- Py_DECREF(retval);
- return NULL;
- }
+ hex_digest = PyUnicode_1BYTE_DATA(retval);
/* Make hex version of the digest */
for(i=j=0; i<self->digestsize; i++) {
- char c;
+ unsigned char c;
c = (digest[i] >> 4) & 0xf;
- c = (c>9) ? c+'a'-10 : c + '0';
- hex_digest[j++] = c;
+ hex_digest[j++] = Py_hexdigits[c];
c = (digest[i] & 0xf);
- c = (c>9) ? c+'a'-10 : c + '0';
- hex_digest[j++] = c;
+ hex_digest[j++] = Py_hexdigits[c];
}
+#ifdef Py_DEBUG
+ assert(_PyUnicode_CheckConsistency(retval, 1));
+#endif
return retval;
}