summaryrefslogtreecommitdiff
path: root/Modules/sha256module.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2009-02-12 07:35:29 +0000
committerGregory P. Smith <greg@mad-scientist.com>2009-02-12 07:35:29 +0000
commit5eac8693e162ad8319ac06ddc79914cddf39a378 (patch)
tree34744a86d743ef1b08b39e51cebcb5e9253709a1 /Modules/sha256module.c
parent6aba1d8763d85a7c9be7447c6221ce14db0616d5 (diff)
downloadcpython-5eac8693e162ad8319ac06ddc79914cddf39a378.tar.gz
Fixes Issue #3745: Fix hashlib to always reject unicode and non
buffer-api supporting objects as input no matter how it was compiled (built in implementations or external openssl library).
Diffstat (limited to 'Modules/sha256module.c')
-rw-r--r--Modules/sha256module.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index 523f528876..c653416fbe 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -18,6 +18,7 @@
#include "Python.h"
#include "structmember.h"
+#include "hashlib.h"
/* Endianness testing and definitions */
@@ -480,14 +481,17 @@ PyDoc_STRVAR(SHA256_update__doc__,
static PyObject *
SHA256_update(SHAobject *self, PyObject *args)
{
- unsigned char *cp;
- int len;
+ PyObject *obj;
+ Py_buffer buf;
- if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
+ if (!PyArg_ParseTuple(args, "O:update", &obj))
return NULL;
- sha_update(self, cp, len);
+ GET_BUFFER_VIEW_OR_ERROUT(obj, &buf);
+ sha_update(self, buf.buf, buf.len);
+
+ PyBuffer_Release(&buf);
Py_INCREF(Py_None);
return Py_None;
}
@@ -614,14 +618,17 @@ SHA256_new(PyObject *self, PyObject *args, PyObject *kwdict)
{
static char *kwlist[] = {"string", NULL};
SHAobject *new;
- unsigned char *cp = NULL;
- int len;
+ PyObject *data_obj = NULL;
+ Py_buffer buf;
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist,
- &cp, &len)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
+ &data_obj)) {
return NULL;
}
+ if (data_obj)
+ GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
+
if ((new = newSHA256object()) == NULL)
return NULL;
@@ -631,8 +638,10 @@ SHA256_new(PyObject *self, PyObject *args, PyObject *kwdict)
Py_DECREF(new);
return NULL;
}
- if (cp)
- sha_update(new, cp, len);
+ if (data_obj) {
+ sha_update(new, buf.buf, buf.len);
+ PyBuffer_Release(&buf);
+ }
return (PyObject *)new;
}
@@ -645,14 +654,17 @@ SHA224_new(PyObject *self, PyObject *args, PyObject *kwdict)
{
static char *kwlist[] = {"string", NULL};
SHAobject *new;
- unsigned char *cp = NULL;
- int len;
+ PyObject *data_obj = NULL;
+ Py_buffer buf;
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist,
- &cp, &len)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
+ &data_obj)) {
return NULL;
}
+ if (data_obj)
+ GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
+
if ((new = newSHA224object()) == NULL)
return NULL;
@@ -662,8 +674,10 @@ SHA224_new(PyObject *self, PyObject *args, PyObject *kwdict)
Py_DECREF(new);
return NULL;
}
- if (cp)
- sha_update(new, cp, len);
+ if (data_obj) {
+ sha_update(new, buf.buf, buf.len);
+ PyBuffer_Release(&buf);
+ }
return (PyObject *)new;
}