diff -r 8d572bf526e6 Modules/sha512module.c --- a/Modules/sha512module.c Sun Jan 26 21:35:22 2014 -0500 +++ b/Modules/sha512module.c Mon Jan 27 16:10:32 2014 +0800 @@ -20,6 +20,12 @@ #include "structmember.h" #include "hashlib.h" +/*[clinic input] +module _sha512 +class SHA512Type "SHAobject *" "&PyType_Type" +[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 */ @@ -459,10 +465,31 @@ /* External methods for a hash object */ -PyDoc_STRVAR(SHA512_copy__doc__, "Return a copy of the hash object."); +/*[clinic input] +SHA512Type.copy + +Return a copy of the hash object. +[clinic start generated code]*/ + +PyDoc_STRVAR(SHA512Type_copy__doc__, +"copy(self)\n" +"Return a copy of the hash object."); + +#define SHA512TYPE_COPY_METHODDEF \ + {"copy", (PyCFunction)SHA512Type_copy, METH_NOARGS, SHA512Type_copy__doc__}, static PyObject * -SHA512_copy(SHAobject *self, PyObject *unused) +SHA512Type_copy_impl(SHAobject *self); + +static PyObject * +SHA512Type_copy(SHAobject *self, PyObject *Py_UNUSED(ignored)) +{ + return SHA512Type_copy_impl(self); +} + +static PyObject * +SHA512Type_copy_impl(SHAobject *self) +/*[clinic end generated code: checksum=476e9920d178b33a33c4530ffac0615a3eacf05f]*/ { SHAobject *newobj; @@ -478,11 +505,31 @@ return (PyObject *)newobj; } -PyDoc_STRVAR(SHA512_digest__doc__, +/*[clinic input] +SHA512Type.digest + +Return the digest value as a string of binary data. +[clinic start generated code]*/ + +PyDoc_STRVAR(SHA512Type_digest__doc__, +"digest(self)\n" "Return the digest value as a string of binary data."); +#define SHA512TYPE_DIGEST_METHODDEF \ + {"digest", (PyCFunction)SHA512Type_digest, METH_NOARGS, SHA512Type_digest__doc__}, + static PyObject * -SHA512_digest(SHAobject *self, PyObject *unused) +SHA512Type_digest_impl(SHAobject *self); + +static PyObject * +SHA512Type_digest(SHAobject *self, PyObject *Py_UNUSED(ignored)) +{ + return SHA512Type_digest_impl(self); +} + +static PyObject * +SHA512Type_digest_impl(SHAobject *self) +/*[clinic end generated code: checksum=f3176ab43b4074e2fac1344309b8d38ba5eb93a9]*/ { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -492,11 +539,31 @@ return PyBytes_FromStringAndSize((const char *)digest, self->digestsize); } -PyDoc_STRVAR(SHA512_hexdigest__doc__, +/*[clinic input] +SHA512Type.hexdigest + +Return the digest value as a string of hexadecimal digits. +[clinic start generated code]*/ + +PyDoc_STRVAR(SHA512Type_hexdigest__doc__, +"hexdigest(self)\n" "Return the digest value as a string of hexadecimal digits."); +#define SHA512TYPE_HEXDIGEST_METHODDEF \ + {"hexdigest", (PyCFunction)SHA512Type_hexdigest, METH_NOARGS, SHA512Type_hexdigest__doc__}, + static PyObject * -SHA512_hexdigest(SHAobject *self, PyObject *unused) +SHA512Type_hexdigest_impl(SHAobject *self); + +static PyObject * +SHA512Type_hexdigest(SHAobject *self, PyObject *Py_UNUSED(ignored)) +{ + return SHA512Type_hexdigest_impl(self); +} + +static PyObject * +SHA512Type_hexdigest_impl(SHAobject *self) +/*[clinic end generated code: checksum=7b2d452581851d07d792b34a71238e6e9610bc6e]*/ { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -528,18 +595,28 @@ return retval; } -PyDoc_STRVAR(SHA512_update__doc__, -"Update this hash object's state with the provided string."); +/*[clinic input] +SHA512Type.update + + obj: object + / + +Update this hash object's state with the provided string. +[clinic start generated code]*/ + +PyDoc_STRVAR(SHA512Type_update__doc__, +"update(self, 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=2248f5b2f57532c6b8d3b3b3501913d621d810e9]*/ { - 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); @@ -550,10 +627,10 @@ } static PyMethodDef SHA_methods[] = { - {"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_COPY_METHODDEF + SHA512TYPE_DIGEST_METHODDEF + SHA512TYPE_HEXDIGEST_METHODDEF + SHA512TYPE_UPDATE_METHODDEF {NULL, NULL} /* sentinel */ }; @@ -660,27 +737,53 @@ /* The single module-level function: new() */ -PyDoc_STRVAR(SHA512_new__doc__, +/*[clinic input] +_sha512.sha512 + + string: object(c_default="NULL") = b'' + +Return a new SHA-512 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha512_sha512__doc__, +"sha512(module, string=b\'\')\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=4e8dc8d779b19f2d57067523c63ebc86b525aee8]*/ +{ 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 +792,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 +804,53 @@ return (PyObject *)new; } -PyDoc_STRVAR(SHA384_new__doc__, +/*[clinic input] +_sha512.sha384 + + string: object(c_default="NULL") = b'' + +Return a new SHA-384 hash object; optionally initialized with a string. +[clinic start generated code]*/ + +PyDoc_STRVAR(_sha512_sha384__doc__, +"sha384(module, string=b\'\')\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=75048339481e23c45342e72daad0d4b4bd4c839a]*/ +{ 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 +859,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 +875,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 */ };