diff -r 89b738e3d0c9 Modules/sha512module.c --- a/Modules/sha512module.c Thu Jan 23 09:49:42 2014 +0200 +++ b/Modules/sha512module.c Thu Jan 23 17:44:44 2014 +0800 @@ -20,6 +20,12 @@ #include "structmember.h" #include "hashlib.h" +/*[clinic input] +module _sha512 +class SHA512Type +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + #ifdef PY_LONG_LONG /* If no PY_LONG_LONG, don't compile anything! */ /* Some useful types */ @@ -528,18 +534,29 @@ return retval; } -PyDoc_STRVAR(SHA512_update__doc__, -"Update this hash object's state with the provided string."); +/*[clinic input] +SHA512Type.update + + self: self(type="SHAobject *") + obj: object + / + +Update this hash object's state with the provided string. +[clinic start generated code]*/ + +PyDoc_STRVAR(SHA512Type_update__doc__, +"update(obj)\n" +"Update this hash object\'s state with the provided string."); + +#define SHA512TYPE_UPDATE_METHODDEF \ + {"update", (PyCFunction)SHA512Type_update, METH_O, SHA512Type_update__doc__}, static PyObject * -SHA512_update(SHAobject *self, PyObject *args) +SHA512Type_update(SHAobject *self, PyObject *obj) +/*[clinic end generated code: checksum=3398a2ae867e49490fa7c77257b44d464ecc18c1]*/ { - PyObject *obj; Py_buffer buf; - if (!PyArg_ParseTuple(args, "O:update", &obj)) - return NULL; - GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); sha512_update(self, buf.buf, buf.len); @@ -553,7 +570,7 @@ {"copy", (PyCFunction)SHA512_copy, METH_NOARGS, SHA512_copy__doc__}, {"digest", (PyCFunction)SHA512_digest, METH_NOARGS, SHA512_digest__doc__}, {"hexdigest", (PyCFunction)SHA512_hexdigest, METH_NOARGS, SHA512_hexdigest__doc__}, - {"update", (PyCFunction)SHA512_update, METH_VARARGS, SHA512_update__doc__}, + SHA512TYPE_UPDATE_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -660,27 +677,53 @@ /* The single module-level function: new() */ -PyDoc_STRVAR(SHA512_new__doc__, +/*[clinic input] +_sha512.sha512 + + string: object = NULL + +Return a new SHA-512 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha512_sha512__doc__, +"sha512(string=None)\n" "Return a new SHA-512 hash object; optionally initialized with a string."); +#define _SHA512_SHA512_METHODDEF \ + {"sha512", (PyCFunction)_sha512_sha512, METH_VARARGS|METH_KEYWORDS, _sha512_sha512__doc__}, + static PyObject * -SHA512_new(PyObject *self, PyObject *args, PyObject *kwdict) +_sha512_sha512_impl(PyModuleDef *module, PyObject *string); + +static PyObject * +_sha512_sha512(PyModuleDef *module, 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:sha512", _keywords, + &string)) + goto exit; + return_value = _sha512_sha512_impl(module, string); + +exit: + return return_value; +} + +static PyObject * +_sha512_sha512_impl(PyModuleDef *module, PyObject *string) +/*[clinic end generated code: checksum=cd734ee8a70639143c0b88ecb979c3647bebe49a]*/ +{ SHAobject *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 = newSHA512object()) == NULL) { - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } @@ -689,11 +732,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } - if (data_obj) { + if (string) { sha512_update(new, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -701,27 +744,53 @@ return (PyObject *)new; } -PyDoc_STRVAR(SHA384_new__doc__, +/*[clinic input] +_sha512.sha384 + + string: object = NULL + +Return a new SHA-384 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha512_sha384__doc__, +"sha384(string=None)\n" "Return a new SHA-384 hash object; optionally initialized with a string."); +#define _SHA512_SHA384_METHODDEF \ + {"sha384", (PyCFunction)_sha512_sha384, METH_VARARGS|METH_KEYWORDS, _sha512_sha384__doc__}, + static PyObject * -SHA384_new(PyObject *self, PyObject *args, PyObject *kwdict) +_sha512_sha384_impl(PyModuleDef *module, PyObject *string); + +static PyObject * +_sha512_sha384(PyModuleDef *module, 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:sha384", _keywords, + &string)) + goto exit; + return_value = _sha512_sha384_impl(module, string); + +exit: + return return_value; +} + +static PyObject * +_sha512_sha384_impl(PyModuleDef *module, PyObject *string) +/*[clinic end generated code: checksum=748409bc16e378058261c650e1d338f07681a671]*/ +{ SHAobject *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 = newSHA384object()) == NULL) { - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } @@ -730,11 +799,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (data_obj) + if (string) PyBuffer_Release(&buf); return NULL; } - if (data_obj) { + if (string) { sha512_update(new, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -746,8 +815,8 @@ /* List of functions exported by this module */ static struct PyMethodDef SHA_functions[] = { - {"sha512", (PyCFunction)SHA512_new, METH_VARARGS|METH_KEYWORDS, SHA512_new__doc__}, - {"sha384", (PyCFunction)SHA384_new, METH_VARARGS|METH_KEYWORDS, SHA384_new__doc__}, + _SHA512_SHA512_METHODDEF + _SHA512_SHA384_METHODDEF {NULL, NULL} /* Sentinel */ };