1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(py_blake2s_new__doc__,
6 "blake2s(data=b\'\', /, *, digest_size=_blake2.blake2s.MAX_DIGEST_SIZE,\n"
7 "        key=b\'\', salt=b\'\', person=b\'\', fanout=1, depth=1, leaf_size=0,\n"
8 "        node_offset=0, node_depth=0, inner_size=0, last_node=False,\n"
9 "        usedforsecurity=True)\n"
10 "--\n"
11 "\n"
12 "Return a new BLAKE2s hash object.");
13 
14 static PyObject *
15 py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
16                     Py_buffer *key, Py_buffer *salt, Py_buffer *person,
17                     int fanout, int depth, unsigned long leaf_size,
18                     unsigned long long node_offset, int node_depth,
19                     int inner_size, int last_node, int usedforsecurity);
20 
21 static PyObject *
py_blake2s_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)22 py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
23 {
24     PyObject *return_value = NULL;
25     static const char * const _keywords[] = {"", "digest_size", "key", "salt", "person", "fanout", "depth", "leaf_size", "node_offset", "node_depth", "inner_size", "last_node", "usedforsecurity", NULL};
26     static _PyArg_Parser _parser = {NULL, _keywords, "blake2s", 0};
27     PyObject *argsbuf[13];
28     PyObject * const *fastargs;
29     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
30     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
31     PyObject *data = NULL;
32     int digest_size = BLAKE2S_OUTBYTES;
33     Py_buffer key = {NULL, NULL};
34     Py_buffer salt = {NULL, NULL};
35     Py_buffer person = {NULL, NULL};
36     int fanout = 1;
37     int depth = 1;
38     unsigned long leaf_size = 0;
39     unsigned long long node_offset = 0;
40     int node_depth = 0;
41     int inner_size = 0;
42     int last_node = 0;
43     int usedforsecurity = 1;
44 
45     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
46     if (!fastargs) {
47         goto exit;
48     }
49     if (nargs < 1) {
50         goto skip_optional_posonly;
51     }
52     noptargs--;
53     data = fastargs[0];
54 skip_optional_posonly:
55     if (!noptargs) {
56         goto skip_optional_kwonly;
57     }
58     if (fastargs[1]) {
59         if (PyFloat_Check(fastargs[1])) {
60             PyErr_SetString(PyExc_TypeError,
61                             "integer argument expected, got float" );
62             goto exit;
63         }
64         digest_size = _PyLong_AsInt(fastargs[1]);
65         if (digest_size == -1 && PyErr_Occurred()) {
66             goto exit;
67         }
68         if (!--noptargs) {
69             goto skip_optional_kwonly;
70         }
71     }
72     if (fastargs[2]) {
73         if (PyObject_GetBuffer(fastargs[2], &key, PyBUF_SIMPLE) != 0) {
74             goto exit;
75         }
76         if (!PyBuffer_IsContiguous(&key, 'C')) {
77             _PyArg_BadArgument("blake2s", "argument 'key'", "contiguous buffer", fastargs[2]);
78             goto exit;
79         }
80         if (!--noptargs) {
81             goto skip_optional_kwonly;
82         }
83     }
84     if (fastargs[3]) {
85         if (PyObject_GetBuffer(fastargs[3], &salt, PyBUF_SIMPLE) != 0) {
86             goto exit;
87         }
88         if (!PyBuffer_IsContiguous(&salt, 'C')) {
89             _PyArg_BadArgument("blake2s", "argument 'salt'", "contiguous buffer", fastargs[3]);
90             goto exit;
91         }
92         if (!--noptargs) {
93             goto skip_optional_kwonly;
94         }
95     }
96     if (fastargs[4]) {
97         if (PyObject_GetBuffer(fastargs[4], &person, PyBUF_SIMPLE) != 0) {
98             goto exit;
99         }
100         if (!PyBuffer_IsContiguous(&person, 'C')) {
101             _PyArg_BadArgument("blake2s", "argument 'person'", "contiguous buffer", fastargs[4]);
102             goto exit;
103         }
104         if (!--noptargs) {
105             goto skip_optional_kwonly;
106         }
107     }
108     if (fastargs[5]) {
109         if (PyFloat_Check(fastargs[5])) {
110             PyErr_SetString(PyExc_TypeError,
111                             "integer argument expected, got float" );
112             goto exit;
113         }
114         fanout = _PyLong_AsInt(fastargs[5]);
115         if (fanout == -1 && PyErr_Occurred()) {
116             goto exit;
117         }
118         if (!--noptargs) {
119             goto skip_optional_kwonly;
120         }
121     }
122     if (fastargs[6]) {
123         if (PyFloat_Check(fastargs[6])) {
124             PyErr_SetString(PyExc_TypeError,
125                             "integer argument expected, got float" );
126             goto exit;
127         }
128         depth = _PyLong_AsInt(fastargs[6]);
129         if (depth == -1 && PyErr_Occurred()) {
130             goto exit;
131         }
132         if (!--noptargs) {
133             goto skip_optional_kwonly;
134         }
135     }
136     if (fastargs[7]) {
137         if (!_PyLong_UnsignedLong_Converter(fastargs[7], &leaf_size)) {
138             goto exit;
139         }
140         if (!--noptargs) {
141             goto skip_optional_kwonly;
142         }
143     }
144     if (fastargs[8]) {
145         if (!_PyLong_UnsignedLongLong_Converter(fastargs[8], &node_offset)) {
146             goto exit;
147         }
148         if (!--noptargs) {
149             goto skip_optional_kwonly;
150         }
151     }
152     if (fastargs[9]) {
153         if (PyFloat_Check(fastargs[9])) {
154             PyErr_SetString(PyExc_TypeError,
155                             "integer argument expected, got float" );
156             goto exit;
157         }
158         node_depth = _PyLong_AsInt(fastargs[9]);
159         if (node_depth == -1 && PyErr_Occurred()) {
160             goto exit;
161         }
162         if (!--noptargs) {
163             goto skip_optional_kwonly;
164         }
165     }
166     if (fastargs[10]) {
167         if (PyFloat_Check(fastargs[10])) {
168             PyErr_SetString(PyExc_TypeError,
169                             "integer argument expected, got float" );
170             goto exit;
171         }
172         inner_size = _PyLong_AsInt(fastargs[10]);
173         if (inner_size == -1 && PyErr_Occurred()) {
174             goto exit;
175         }
176         if (!--noptargs) {
177             goto skip_optional_kwonly;
178         }
179     }
180     if (fastargs[11]) {
181         last_node = PyObject_IsTrue(fastargs[11]);
182         if (last_node < 0) {
183             goto exit;
184         }
185         if (!--noptargs) {
186             goto skip_optional_kwonly;
187         }
188     }
189     usedforsecurity = PyObject_IsTrue(fastargs[12]);
190     if (usedforsecurity < 0) {
191         goto exit;
192     }
193 skip_optional_kwonly:
194     return_value = py_blake2s_new_impl(type, data, digest_size, &key, &salt, &person, fanout, depth, leaf_size, node_offset, node_depth, inner_size, last_node, usedforsecurity);
195 
196 exit:
197     /* Cleanup for key */
198     if (key.obj) {
199        PyBuffer_Release(&key);
200     }
201     /* Cleanup for salt */
202     if (salt.obj) {
203        PyBuffer_Release(&salt);
204     }
205     /* Cleanup for person */
206     if (person.obj) {
207        PyBuffer_Release(&person);
208     }
209 
210     return return_value;
211 }
212 
213 PyDoc_STRVAR(_blake2_blake2s_copy__doc__,
214 "copy($self, /)\n"
215 "--\n"
216 "\n"
217 "Return a copy of the hash object.");
218 
219 #define _BLAKE2_BLAKE2S_COPY_METHODDEF    \
220     {"copy", (PyCFunction)_blake2_blake2s_copy, METH_NOARGS, _blake2_blake2s_copy__doc__},
221 
222 static PyObject *
223 _blake2_blake2s_copy_impl(BLAKE2sObject *self);
224 
225 static PyObject *
_blake2_blake2s_copy(BLAKE2sObject * self,PyObject * Py_UNUSED (ignored))226 _blake2_blake2s_copy(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
227 {
228     return _blake2_blake2s_copy_impl(self);
229 }
230 
231 PyDoc_STRVAR(_blake2_blake2s_update__doc__,
232 "update($self, data, /)\n"
233 "--\n"
234 "\n"
235 "Update this hash object\'s state with the provided bytes-like object.");
236 
237 #define _BLAKE2_BLAKE2S_UPDATE_METHODDEF    \
238     {"update", (PyCFunction)_blake2_blake2s_update, METH_O, _blake2_blake2s_update__doc__},
239 
240 PyDoc_STRVAR(_blake2_blake2s_digest__doc__,
241 "digest($self, /)\n"
242 "--\n"
243 "\n"
244 "Return the digest value as a bytes object.");
245 
246 #define _BLAKE2_BLAKE2S_DIGEST_METHODDEF    \
247     {"digest", (PyCFunction)_blake2_blake2s_digest, METH_NOARGS, _blake2_blake2s_digest__doc__},
248 
249 static PyObject *
250 _blake2_blake2s_digest_impl(BLAKE2sObject *self);
251 
252 static PyObject *
_blake2_blake2s_digest(BLAKE2sObject * self,PyObject * Py_UNUSED (ignored))253 _blake2_blake2s_digest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
254 {
255     return _blake2_blake2s_digest_impl(self);
256 }
257 
258 PyDoc_STRVAR(_blake2_blake2s_hexdigest__doc__,
259 "hexdigest($self, /)\n"
260 "--\n"
261 "\n"
262 "Return the digest value as a string of hexadecimal digits.");
263 
264 #define _BLAKE2_BLAKE2S_HEXDIGEST_METHODDEF    \
265     {"hexdigest", (PyCFunction)_blake2_blake2s_hexdigest, METH_NOARGS, _blake2_blake2s_hexdigest__doc__},
266 
267 static PyObject *
268 _blake2_blake2s_hexdigest_impl(BLAKE2sObject *self);
269 
270 static PyObject *
_blake2_blake2s_hexdigest(BLAKE2sObject * self,PyObject * Py_UNUSED (ignored))271 _blake2_blake2s_hexdigest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
272 {
273     return _blake2_blake2s_hexdigest_impl(self);
274 }
275 /*[clinic end generated code: output=c80d8d06ce40a192 input=a9049054013a1b77]*/
276