Debian Codegraph @

Modules/clinic/sha2module.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_modsupport.h" // _PyArg_UnpackKeywords()
10
11 PyDoc_STRVAR(SHA256Type_copy__doc__,
12 "copy($self, /)\n"
13 "--\n"
14 "\n"
15 "Return a copy of the hash object.");
16
17 #define SHA256TYPE_COPY_METHODDEF \
18 {"copy", _PyCFunction_CAST(SHA256Type_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, SHA256Type_copy__doc__},
19
20 static PyObject *
21 SHA256Type_copy_impl(SHA256object *self, PyTypeObject *cls);
22
23 static PyObject *
24 SHA256Type_copy(SHA256object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
25 {
26 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
27 PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
28 return NULL;
29 }
30 return SHA256Type_copy_impl(self, cls);
31 }
32
33 PyDoc_STRVAR(SHA512Type_copy__doc__,
34 "copy($self, /)\n"
35 "--\n"
36 "\n"
37 "Return a copy of the hash object.");
38
39 #define SHA512TYPE_COPY_METHODDEF \
40 {"copy", _PyCFunction_CAST(SHA512Type_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, SHA512Type_copy__doc__},
41
42 static PyObject *
43 SHA512Type_copy_impl(SHA512object *self, PyTypeObject *cls);
44
45 static PyObject *
46 SHA512Type_copy(SHA512object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
47 {
48 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
49 PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
50 return NULL;
51 }
52 return SHA512Type_copy_impl(self, cls);
53 }
54
55 PyDoc_STRVAR(SHA256Type_digest__doc__,
56 "digest($self, /)\n"
57 "--\n"
58 "\n"
59 "Return the digest value as a bytes object.");
60
61 #define SHA256TYPE_DIGEST_METHODDEF \
62 {"digest", (PyCFunction)SHA256Type_digest, METH_NOARGS, SHA256Type_digest__doc__},
63
64 static PyObject *
65 SHA256Type_digest_impl(SHA256object *self);
66
67 static PyObject *
68 SHA256Type_digest(SHA256object *self, PyObject *Py_UNUSED(ignored))
69 {
70 return SHA256Type_digest_impl(self);
71 }
72
73 PyDoc_STRVAR(SHA512Type_digest__doc__,
74 "digest($self, /)\n"
75 "--\n"
76 "\n"
77 "Return the digest value as a bytes object.");
78
79 #define SHA512TYPE_DIGEST_METHODDEF \
80 {"digest", (PyCFunction)SHA512Type_digest, METH_NOARGS, SHA512Type_digest__doc__},
81
82 static PyObject *
83 SHA512Type_digest_impl(SHA512object *self);
84
85 static PyObject *
86 SHA512Type_digest(SHA512object *self, PyObject *Py_UNUSED(ignored))
87 {
88 return SHA512Type_digest_impl(self);
89 }
90
91 PyDoc_STRVAR(SHA256Type_hexdigest__doc__,
92 "hexdigest($self, /)\n"
93 "--\n"
94 "\n"
95 "Return the digest value as a string of hexadecimal digits.");
96
97 #define SHA256TYPE_HEXDIGEST_METHODDEF \
98 {"hexdigest", (PyCFunction)SHA256Type_hexdigest, METH_NOARGS, SHA256Type_hexdigest__doc__},
99
100 static PyObject *
101 SHA256Type_hexdigest_impl(SHA256object *self);
102
103 static PyObject *
104 SHA256Type_hexdigest(SHA256object *self, PyObject *Py_UNUSED(ignored))
105 {
106 return SHA256Type_hexdigest_impl(self);
107 }
108
109 PyDoc_STRVAR(SHA512Type_hexdigest__doc__,
110 "hexdigest($self, /)\n"
111 "--\n"
112 "\n"
113 "Return the digest value as a string of hexadecimal digits.");
114
115 #define SHA512TYPE_HEXDIGEST_METHODDEF \
116 {"hexdigest", (PyCFunction)SHA512Type_hexdigest, METH_NOARGS, SHA512Type_hexdigest__doc__},
117
118 static PyObject *
119 SHA512Type_hexdigest_impl(SHA512object *self);
120
121 static PyObject *
122 SHA512Type_hexdigest(SHA512object *self, PyObject *Py_UNUSED(ignored))
123 {
124 return SHA512Type_hexdigest_impl(self);
125 }
126
127 PyDoc_STRVAR(SHA256Type_update__doc__,
128 "update($self, obj, /)\n"
129 "--\n"
130 "\n"
131 "Update this hash object\'s state with the provided string.");
132
133 #define SHA256TYPE_UPDATE_METHODDEF \
134 {"update", (PyCFunction)SHA256Type_update, METH_O, SHA256Type_update__doc__},
135
136 PyDoc_STRVAR(SHA512Type_update__doc__,
137 "update($self, obj, /)\n"
138 "--\n"
139 "\n"
140 "Update this hash object\'s state with the provided string.");
141
142 #define SHA512TYPE_UPDATE_METHODDEF \
143 {"update", (PyCFunction)SHA512Type_update, METH_O, SHA512Type_update__doc__},
144
145 PyDoc_STRVAR(_sha2_sha256__doc__,
146 "sha256($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
147 "--\n"
148 "\n"
149 "Return a new SHA-256 hash object; optionally initialized with a string.");
150
151 #define _SHA2_SHA256_METHODDEF \
152 {"sha256", _PyCFunction_CAST(_sha2_sha256), METH_FASTCALL|METH_KEYWORDS, _sha2_sha256__doc__},
153
154 static PyObject *
155 _sha2_sha256_impl(PyObject *module, PyObject *data, int usedforsecurity,
156 PyObject *string_obj);
157
158 static PyObject *
159 _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
160 {
161 PyObject *return_value = NULL;
162 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
163
164 #define NUM_KEYWORDS 3
165 static struct {
166 PyGC_Head _this_is_not_used;
167 PyObject_VAR_HEAD
168 PyObject *ob_item[NUM_KEYWORDS];
169 } _kwtuple = {
170 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
171 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
172 };
173 #undef NUM_KEYWORDS
174 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
175
176 #else // !Py_BUILD_CORE
177 # define KWTUPLE NULL
178 #endif // !Py_BUILD_CORE
179
180 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
181 static _PyArg_Parser _parser = {
182 .keywords = _keywords,
183 .fname = "sha256",
184 .kwtuple = KWTUPLE,
185 };
186 #undef KWTUPLE
187 PyObject *argsbuf[3];
188 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
189 PyObject *data = NULL;
190 int usedforsecurity = 1;
191 PyObject *string_obj = NULL;
192
193 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
194 if (!args) {
195 goto exit;
196 }
197 if (!noptargs) {
198 goto skip_optional_pos;
199 }
200 if (args[0]) {
201 data = args[0];
202 if (!--noptargs) {
203 goto skip_optional_pos;
204 }
205 }
206 skip_optional_pos:
207 if (!noptargs) {
208 goto skip_optional_kwonly;
209 }
210 if (args[1]) {
211 usedforsecurity = PyObject_IsTrue(args[1]);
212 if (usedforsecurity < 0) {
213 goto exit;
214 }
215 if (!--noptargs) {
216 goto skip_optional_kwonly;
217 }
218 }
219 string_obj = args[2];
220 skip_optional_kwonly:
221 return_value = _sha2_sha256_impl(module, data, usedforsecurity, string_obj);
222
223 exit:
224 return return_value;
225 }
226
227 PyDoc_STRVAR(_sha2_sha224__doc__,
228 "sha224($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
229 "--\n"
230 "\n"
231 "Return a new SHA-224 hash object; optionally initialized with a string.");
232
233 #define _SHA2_SHA224_METHODDEF \
234 {"sha224", _PyCFunction_CAST(_sha2_sha224), METH_FASTCALL|METH_KEYWORDS, _sha2_sha224__doc__},
235
236 static PyObject *
237 _sha2_sha224_impl(PyObject *module, PyObject *data, int usedforsecurity,
238 PyObject *string_obj);
239
240 static PyObject *
241 _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
242 {
243 PyObject *return_value = NULL;
244 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
245
246 #define NUM_KEYWORDS 3
247 static struct {
248 PyGC_Head _this_is_not_used;
249 PyObject_VAR_HEAD
250 PyObject *ob_item[NUM_KEYWORDS];
251 } _kwtuple = {
252 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
253 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
254 };
255 #undef NUM_KEYWORDS
256 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
257
258 #else // !Py_BUILD_CORE
259 # define KWTUPLE NULL
260 #endif // !Py_BUILD_CORE
261
262 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
263 static _PyArg_Parser _parser = {
264 .keywords = _keywords,
265 .fname = "sha224",
266 .kwtuple = KWTUPLE,
267 };
268 #undef KWTUPLE
269 PyObject *argsbuf[3];
270 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
271 PyObject *data = NULL;
272 int usedforsecurity = 1;
273 PyObject *string_obj = NULL;
274
275 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
276 if (!args) {
277 goto exit;
278 }
279 if (!noptargs) {
280 goto skip_optional_pos;
281 }
282 if (args[0]) {
283 data = args[0];
284 if (!--noptargs) {
285 goto skip_optional_pos;
286 }
287 }
288 skip_optional_pos:
289 if (!noptargs) {
290 goto skip_optional_kwonly;
291 }
292 if (args[1]) {
293 usedforsecurity = PyObject_IsTrue(args[1]);
294 if (usedforsecurity < 0) {
295 goto exit;
296 }
297 if (!--noptargs) {
298 goto skip_optional_kwonly;
299 }
300 }
301 string_obj = args[2];
302 skip_optional_kwonly:
303 return_value = _sha2_sha224_impl(module, data, usedforsecurity, string_obj);
304
305 exit:
306 return return_value;
307 }
308
309 PyDoc_STRVAR(_sha2_sha512__doc__,
310 "sha512($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
311 "--\n"
312 "\n"
313 "Return a new SHA-512 hash object; optionally initialized with a string.");
314
315 #define _SHA2_SHA512_METHODDEF \
316 {"sha512", _PyCFunction_CAST(_sha2_sha512), METH_FASTCALL|METH_KEYWORDS, _sha2_sha512__doc__},
317
318 static PyObject *
319 _sha2_sha512_impl(PyObject *module, PyObject *data, int usedforsecurity,
320 PyObject *string_obj);
321
322 static PyObject *
323 _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
324 {
325 PyObject *return_value = NULL;
326 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
327
328 #define NUM_KEYWORDS 3
329 static struct {
330 PyGC_Head _this_is_not_used;
331 PyObject_VAR_HEAD
332 PyObject *ob_item[NUM_KEYWORDS];
333 } _kwtuple = {
334 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
335 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
336 };
337 #undef NUM_KEYWORDS
338 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
339
340 #else // !Py_BUILD_CORE
341 # define KWTUPLE NULL
342 #endif // !Py_BUILD_CORE
343
344 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
345 static _PyArg_Parser _parser = {
346 .keywords = _keywords,
347 .fname = "sha512",
348 .kwtuple = KWTUPLE,
349 };
350 #undef KWTUPLE
351 PyObject *argsbuf[3];
352 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
353 PyObject *data = NULL;
354 int usedforsecurity = 1;
355 PyObject *string_obj = NULL;
356
357 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
358 if (!args) {
359 goto exit;
360 }
361 if (!noptargs) {
362 goto skip_optional_pos;
363 }
364 if (args[0]) {
365 data = args[0];
366 if (!--noptargs) {
367 goto skip_optional_pos;
368 }
369 }
370 skip_optional_pos:
371 if (!noptargs) {
372 goto skip_optional_kwonly;
373 }
374 if (args[1]) {
375 usedforsecurity = PyObject_IsTrue(args[1]);
376 if (usedforsecurity < 0) {
377 goto exit;
378 }
379 if (!--noptargs) {
380 goto skip_optional_kwonly;
381 }
382 }
383 string_obj = args[2];
384 skip_optional_kwonly:
385 return_value = _sha2_sha512_impl(module, data, usedforsecurity, string_obj);
386
387 exit:
388 return return_value;
389 }
390
391 PyDoc_STRVAR(_sha2_sha384__doc__,
392 "sha384($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
393 "--\n"
394 "\n"
395 "Return a new SHA-384 hash object; optionally initialized with a string.");
396
397 #define _SHA2_SHA384_METHODDEF \
398 {"sha384", _PyCFunction_CAST(_sha2_sha384), METH_FASTCALL|METH_KEYWORDS, _sha2_sha384__doc__},
399
400 static PyObject *
401 _sha2_sha384_impl(PyObject *module, PyObject *data, int usedforsecurity,
402 PyObject *string_obj);
403
404 static PyObject *
405 _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
406 {
407 PyObject *return_value = NULL;
408 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
409
410 #define NUM_KEYWORDS 3
411 static struct {
412 PyGC_Head _this_is_not_used;
413 PyObject_VAR_HEAD
414 PyObject *ob_item[NUM_KEYWORDS];
415 } _kwtuple = {
416 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
417 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
418 };
419 #undef NUM_KEYWORDS
420 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
421
422 #else // !Py_BUILD_CORE
423 # define KWTUPLE NULL
424 #endif // !Py_BUILD_CORE
425
426 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
427 static _PyArg_Parser _parser = {
428 .keywords = _keywords,
429 .fname = "sha384",
430 .kwtuple = KWTUPLE,
431 };
432 #undef KWTUPLE
433 PyObject *argsbuf[3];
434 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
435 PyObject *data = NULL;
436 int usedforsecurity = 1;
437 PyObject *string_obj = NULL;
438
439 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
440 if (!args) {
441 goto exit;
442 }
443 if (!noptargs) {
444 goto skip_optional_pos;
445 }
446 if (args[0]) {
447 data = args[0];
448 if (!--noptargs) {
449 goto skip_optional_pos;
450 }
451 }
452 skip_optional_pos:
453 if (!noptargs) {
454 goto skip_optional_kwonly;
455 }
456 if (args[1]) {
457 usedforsecurity = PyObject_IsTrue(args[1]);
458 if (usedforsecurity < 0) {
459 goto exit;
460 }
461 if (!--noptargs) {
462 goto skip_optional_kwonly;
463 }
464 }
465 string_obj = args[2];
466 skip_optional_kwonly:
467 return_value = _sha2_sha384_impl(module, data, usedforsecurity, string_obj);
468
469 exit:
470 return return_value;
471 }
472 /*[clinic end generated code: output=ca66b727f1868930 input=a9049054013a1b77]*/