summaryrefslogtreecommitdiff
path: root/Modules/shamodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/shamodule.c')
-rw-r--r--Modules/shamodule.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/Modules/shamodule.c b/Modules/shamodule.c
index efd7204679..a86e722b03 100644
--- a/Modules/shamodule.c
+++ b/Modules/shamodule.c
@@ -236,9 +236,9 @@ sha_init(SHAobject *sha_info)
/* update the SHA digest */
static void
-sha_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
+sha_update(SHAobject *sha_info, SHA_BYTE *buffer, unsigned int count)
{
- int i;
+ unsigned int i;
SHA_INT32 clo;
clo = sha_info->count_lo + ((SHA_INT32) count << 3);
@@ -428,16 +428,16 @@ PyDoc_STRVAR(SHA_update__doc__,
static PyObject *
SHA_update(SHAobject *self, PyObject *args)
{
- unsigned char *cp;
- int len;
+ Py_buffer view;
- if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
+ if (!PyArg_ParseTuple(args, "s*:update", &view))
return NULL;
- sha_update(self, cp, len);
+ sha_update(self, (unsigned char*)view.buf,
+ Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
- Py_INCREF(Py_None);
- return Py_None;
+ PyBuffer_Release(&view);
+ Py_RETURN_NONE;
}
static PyMethodDef SHA_methods[] = {
@@ -535,25 +535,30 @@ SHA_new(PyObject *self, PyObject *args, PyObject *kwdict)
{
static char *kwlist[] = {"string", NULL};
SHAobject *new;
- unsigned char *cp = NULL;
- int len;
+ Py_buffer view = { 0 };
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist,
- &cp, &len)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
+ &view)) {
return NULL;
}
- if ((new = newSHAobject()) == NULL)
+ if ((new = newSHAobject()) == NULL) {
+ PyBuffer_Release(&view);
return NULL;
+ }
sha_init(new);
if (PyErr_Occurred()) {
Py_DECREF(new);
+ PyBuffer_Release(&view);
return NULL;
}
- if (cp)
- sha_update(new, cp, len);
+ if (view.len > 0) {
+ sha_update(new, (unsigned char*)view.buf,
+ Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
+ }
+ PyBuffer_Release(&view);
return (PyObject *)new;
}