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