summaryrefslogtreecommitdiffstats
path: root/Modules/sha1module.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/sha1module.c')
-rw-r--r--Modules/sha1module.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index b25bd44..daea887 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -218,7 +218,7 @@ void sha1_process(struct sha1_state *sha1,
in += SHA1_BLOCKSIZE;
inlen -= SHA1_BLOCKSIZE;
} else {
- n = MIN(inlen, (SHA1_BLOCKSIZE - sha1->curlen));
+ n = MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen));
memcpy(sha1->buf + sha1->curlen, in, (size_t)n);
sha1->curlen += n;
in += n;
@@ -352,7 +352,7 @@ SHA1_hexdigest(SHA1object *self, PyObject *unused)
unsigned char digest[SHA1_DIGESTSIZE];
struct sha1_state temp;
PyObject *retval;
- Py_UNICODE *hex_digest;
+ Py_UCS1 *hex_digest;
int i, j;
/* Get the raw (binary) digest value */
@@ -360,25 +360,20 @@ SHA1_hexdigest(SHA1object *self, PyObject *unused)
sha1_done(&temp, digest);
/* Create a new string */
- retval = PyUnicode_FromStringAndSize(NULL, SHA1_DIGESTSIZE * 2);
+ retval = PyUnicode_New(SHA1_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<SHA1_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];
}
+ assert(_PyUnicode_CheckConsistency(retval, 1));
return retval;
}