Debian Codegraph @

Modules/_blake2/clinic/blake2b_impl.c.h

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