summaryrefslogtreecommitdiffstats
path: root/Modules/shamodule.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2000-08-15 06:03:35 (GMT)
committerBarry Warsaw <barry@python.org>2000-08-15 06:03:35 (GMT)
commit57b808d21a7651b303bf22264c4bc47824ab3b51 (patch)
tree1559029efaaaf04c245602627e1ec8d40bf6b3f8 /Modules/shamodule.c
parent3fdcccb82fe8578722b94a18b76fe9d791e7a6e4 (diff)
downloadcpython-57b808d21a7651b303bf22264c4bc47824ab3b51.zip
cpython-57b808d21a7651b303bf22264c4bc47824ab3b51.tar.gz
cpython-57b808d21a7651b303bf22264c4bc47824ab3b51.tar.bz2
SHA_hexdigest(): A couple of small patches to this function, added
after a brief conversation with TP. First, the return values of the PyString_* function calls should be checked for errors. Second, bit-manipulations should be used instead of division for spliting the byte up into its 4 bit digits.
Diffstat (limited to 'Modules/shamodule.c')
-rw-r--r--Modules/shamodule.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Modules/shamodule.c b/Modules/shamodule.c
index 6f7a60d..3761cf5 100644
--- a/Modules/shamodule.c
+++ b/Modules/shamodule.c
@@ -422,14 +422,22 @@ SHA_hexdigest(SHAobject *self, PyObject *args)
/* Create a new string */
retval = PyString_FromStringAndSize(NULL, sizeof(digest) * 2);
+ if (!retval)
+ return NULL;
hex_digest = PyString_AsString(retval);
+ if (!hex_digest) {
+ Py_DECREF(retval);
+ return NULL;
+ }
/* Make hex version of the digest */
for(i=j=0; i<sizeof(digest); i++) {
char c;
- c = digest[i] / 16; c = (c>9) ? c+'a'-10 : c + '0';
+ c = (digest[i] >> 4) & 0xf;
+ c = (c>9) ? c+'a'-10 : c + '0';
hex_digest[j++] = c;
- c = digest[i] % 16; c = (c>9) ? c+'a'-10 : c + '0';
+ c = (digest[i] & 0xf);
+ c = (c>9) ? c+'a'-10 : c + '0';
hex_digest[j++] = c;
}
return retval;