diff -r c0b0e7aef360 Modules/sha1module.c --- a/Modules/sha1module.c Tue Jan 07 23:29:19 2014 -0700 +++ b/Modules/sha1module.c Wed Jan 08 19:17:17 2014 +0800 @@ -34,6 +34,17 @@ #define SHA1_BLOCKSIZE 64 #define SHA1_DIGESTSIZE 20 +/*[clinic input] +module _sha1 +class _sha1.SHA1 +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ +/*[python input] +class SHA1object_converter(self_converter): + type = "SHA1object *" +[python start generated code]*/ +/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + /* The structure for storing SHA1 info */ struct sha1_state { @@ -373,11 +384,26 @@ return retval; } -PyDoc_STRVAR(SHA1_update__doc__, -"Update this hash object's state with the provided string."); +/*[clinic input] +_sha1.SHA1.update + + self: SHA1object + args: object + / + +Update this hash object's state with the provided string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha1_SHA1_update__doc__, +"update(args)\n" +"Update this hash object\'s state with the provided string."); + +#define _SHA1_SHA1_UPDATE_METHODDEF \ + {"update", (PyCFunction)_sha1_SHA1_update, METH_O, _sha1_SHA1_update__doc__}, static PyObject * -SHA1_update(SHA1object *self, PyObject *args) +_sha1_SHA1_update(SHA1object *self, PyObject *args) +/*[clinic end generated code: checksum=a39d7531d589e7124e2ba96359cb2be591758c2c]*/ { PyObject *obj; Py_buffer buf; @@ -397,8 +423,8 @@ static PyMethodDef SHA1_methods[] = { {"copy", (PyCFunction)SHA1_copy, METH_NOARGS, SHA1_copy__doc__}, {"digest", (PyCFunction)SHA1_digest, METH_NOARGS, SHA1_digest__doc__}, + _SHA1_SHA1_UPDATE_METHODDEF {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc__}, - {"update", (PyCFunction)SHA1_update, METH_VARARGS, SHA1_update__doc__}, {NULL, NULL} /* sentinel */ }; @@ -474,27 +500,55 @@ /* The single module-level function: new() */ -PyDoc_STRVAR(SHA1_new__doc__, +/*[clinic input] +_sha1.SHA1.sha1 + + [ + string: object = NULL + ] + +Return a new SHA1 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha1_SHA1_sha1__doc__, +"sha1(string=None)\n" "Return a new SHA1 hash object; optionally initialized with a string."); +#define _SHA1_SHA1_SHA1_METHODDEF \ + {"sha1", (PyCFunction)_sha1_SHA1_sha1, METH_VARARGS|METH_KEYWORDS, _sha1_SHA1_sha1__doc__}, + static PyObject * -SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict) +_sha1_SHA1_sha1_impl(PyObject *self, PyObject *string); + +static PyObject * +_sha1_SHA1_sha1(PyObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"string", NULL}; + PyObject *return_value = NULL; + static char *_keywords[] = {"string", NULL}; + PyObject *string = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|O:sha1", _keywords, + &string)) + goto exit; + return_value = _sha1_SHA1_sha1_impl(self, string); + +exit: + return return_value; +} + +static PyObject * +_sha1_SHA1_sha1_impl(PyObject *self, PyObject *string) +/*[clinic end generated code: checksum=ee414d8be9a6b1d5e00052af67cd5cfcd7924078]*/ +{ SHA1object *new; - PyObject *data_obj = NULL; Py_buffer buf; - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, - &data_obj)) { - return NULL; - } - - if (data_obj) - GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); + if (string) + GET_BUFFER_VIEW_OR_ERROUT(string, &buf); if ((new = newSHA1object()) == NULL) { - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } @@ -503,11 +557,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } - if (data_obj) { + if (string) { sha1_process(&new->hash_state, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -519,7 +573,7 @@ /* List of functions exported by this module */ static struct PyMethodDef SHA1_functions[] = { - {"sha1",(PyCFunction)SHA1_new, METH_VARARGS|METH_KEYWORDS,SHA1_new__doc__}, + _SHA1_SHA1_SHA1_METHODDEF {NULL, NULL} /* Sentinel */ };