Use s* to receive data. Fixes #3552.

This commit is contained in:
Martin v. Löwis 2008-08-14 15:52:23 +00:00
parent 42b2f2ec78
commit 7b9cb2579c
2 changed files with 24 additions and 21 deletions

View File

@ -411,14 +411,14 @@ PyDoc_STRVAR(MD5_update__doc__,
static PyObject * static PyObject *
MD5_update(MD5object *self, PyObject *args) MD5_update(MD5object *self, PyObject *args)
{ {
unsigned char *cp; Py_buffer buf;
int len;
if (!PyArg_ParseTuple(args, "s*:update", &buf))
if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
return NULL; return NULL;
md5_process(&self->hash_state, cp, len); md5_process(&self->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
@ -511,11 +511,11 @@ MD5_new(PyObject *self, PyObject *args, PyObject *kwdict)
{ {
static char *kwlist[] = {"string", NULL}; static char *kwlist[] = {"string", NULL};
MD5object *new; MD5object *new;
unsigned char *cp = NULL; Py_buffer buf;
int len; buf.buf = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
&cp, &len)) { &buf)) {
return NULL; return NULL;
} }
@ -528,8 +528,10 @@ MD5_new(PyObject *self, PyObject *args, PyObject *kwdict)
Py_DECREF(new); Py_DECREF(new);
return NULL; return NULL;
} }
if (cp) if (buf.buf) {
md5_process(&new->hash_state, cp, len); md5_process(&new->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
}
return (PyObject *)new; return (PyObject *)new;
} }

View File

@ -387,14 +387,14 @@ PyDoc_STRVAR(SHA1_update__doc__,
static PyObject * static PyObject *
SHA1_update(SHA1object *self, PyObject *args) SHA1_update(SHA1object *self, PyObject *args)
{ {
unsigned char *cp; Py_buffer buf;
int len;
if (!PyArg_ParseTuple(args, "s#:update", &cp, &len)) if (!PyArg_ParseTuple(args, "s*:update", &buf))
return NULL; return NULL;
sha1_process(&self->hash_state, cp, len); sha1_process(&self->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
@ -487,11 +487,10 @@ SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict)
{ {
static char *kwlist[] = {"string", NULL}; static char *kwlist[] = {"string", NULL};
SHA1object *new; SHA1object *new;
unsigned char *cp = NULL; Py_buffer buf;
int len;
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
&cp, &len)) { &buf)) {
return NULL; return NULL;
} }
@ -504,8 +503,10 @@ SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict)
Py_DECREF(new); Py_DECREF(new);
return NULL; return NULL;
} }
if (cp) if (buf.buf) {
sha1_process(&new->hash_state, cp, len); sha1_process(&new->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
}
return (PyObject *)new; return (PyObject *)new;
} }