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(PyObject *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((SHA256object *)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(PyObject *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((SHA512object *)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(PyObject *self, PyObject *Py_UNUSED(ignored))
69 {
70 return SHA256Type_digest_impl((SHA256object *)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(PyObject *self, PyObject *Py_UNUSED(ignored))
87 {
88 return SHA512Type_digest_impl((SHA512object *)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(PyObject *self, PyObject *Py_UNUSED(ignored))
105 {
106 return SHA256Type_hexdigest_impl((SHA256object *)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(PyObject *self, PyObject *Py_UNUSED(ignored))
123 {
124 return SHA512Type_hexdigest_impl((SHA512object *)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 static PyObject *
137 SHA256Type_update_impl(SHA256object *self, PyObject *obj);
138
139 static PyObject *
140 SHA256Type_update(PyObject *self, PyObject *obj)
141 {
142 PyObject *return_value = NULL;
143
144 return_value = SHA256Type_update_impl((SHA256object *)self, obj);
145
146 return return_value;
147 }
148
149 PyDoc_STRVAR(SHA512Type_update__doc__,
150 "update($self, obj, /)\n"
151 "--\n"
152 "\n"
153 "Update this hash object\'s state with the provided string.");
154
155 #define SHA512TYPE_UPDATE_METHODDEF \
156 {"update", (PyCFunction)SHA512Type_update, METH_O, SHA512Type_update__doc__},
157
158 static PyObject *
159 SHA512Type_update_impl(SHA512object *self, PyObject *obj);
160
161 static PyObject *
162 SHA512Type_update(PyObject *self, PyObject *obj)
163 {
164 PyObject *return_value = NULL;
165
166 return_value = SHA512Type_update_impl((SHA512object *)self, obj);
167
168 return return_value;
169 }
170
171 PyDoc_STRVAR(_sha2_sha256__doc__,
172 "sha256($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
173 "--\n"
174 "\n"
175 "Return a new SHA-256 hash object; optionally initialized with a string.");
176
177 #define _SHA2_SHA256_METHODDEF \
178 {"sha256", _PyCFunction_CAST(_sha2_sha256), METH_FASTCALL|METH_KEYWORDS, _sha2_sha256__doc__},
179
180 static PyObject *
181 _sha2_sha256_impl(PyObject *module, PyObject *data, int usedforsecurity,
182 PyObject *string_obj);
183
184 static PyObject *
185 _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
186 {
187 PyObject *return_value = NULL;
188 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
189
190 #define NUM_KEYWORDS 3
191 static struct {
192 PyGC_Head _this_is_not_used;
193 PyObject_VAR_HEAD
194 Py_hash_t ob_hash;
195 PyObject *ob_item[NUM_KEYWORDS];
196 } _kwtuple = {
197 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
198 .ob_hash = -1,
199 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
200 };
201 #undef NUM_KEYWORDS
202 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
203
204 #else // !Py_BUILD_CORE
205 # define KWTUPLE NULL
206 #endif // !Py_BUILD_CORE
207
208 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
209 static _PyArg_Parser _parser = {
210 .keywords = _keywords,
211 .fname = "sha256",
212 .kwtuple = KWTUPLE,
213 };
214 #undef KWTUPLE
215 PyObject *argsbuf[3];
216 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
217 PyObject *data = NULL;
218 int usedforsecurity = 1;
219 PyObject *string_obj = NULL;
220
221 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
222 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
223 if (!args) {
224 goto exit;
225 }
226 if (!noptargs) {
227 goto skip_optional_pos;
228 }
229 if (args[0]) {
230 data = args[0];
231 if (!--noptargs) {
232 goto skip_optional_pos;
233 }
234 }
235 skip_optional_pos:
236 if (!noptargs) {
237 goto skip_optional_kwonly;
238 }
239 if (args[1]) {
240 usedforsecurity = PyObject_IsTrue(args[1]);
241 if (usedforsecurity < 0) {
242 goto exit;
243 }
244 if (!--noptargs) {
245 goto skip_optional_kwonly;
246 }
247 }
248 string_obj = args[2];
249 skip_optional_kwonly:
250 return_value = _sha2_sha256_impl(module, data, usedforsecurity, string_obj);
251
252 exit:
253 return return_value;
254 }
255
256 PyDoc_STRVAR(_sha2_sha224__doc__,
257 "sha224($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
258 "--\n"
259 "\n"
260 "Return a new SHA-224 hash object; optionally initialized with a string.");
261
262 #define _SHA2_SHA224_METHODDEF \
263 {"sha224", _PyCFunction_CAST(_sha2_sha224), METH_FASTCALL|METH_KEYWORDS, _sha2_sha224__doc__},
264
265 static PyObject *
266 _sha2_sha224_impl(PyObject *module, PyObject *data, int usedforsecurity,
267 PyObject *string_obj);
268
269 static PyObject *
270 _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
271 {
272 PyObject *return_value = NULL;
273 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
274
275 #define NUM_KEYWORDS 3
276 static struct {
277 PyGC_Head _this_is_not_used;
278 PyObject_VAR_HEAD
279 Py_hash_t ob_hash;
280 PyObject *ob_item[NUM_KEYWORDS];
281 } _kwtuple = {
282 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
283 .ob_hash = -1,
284 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
285 };
286 #undef NUM_KEYWORDS
287 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
288
289 #else // !Py_BUILD_CORE
290 # define KWTUPLE NULL
291 #endif // !Py_BUILD_CORE
292
293 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
294 static _PyArg_Parser _parser = {
295 .keywords = _keywords,
296 .fname = "sha224",
297 .kwtuple = KWTUPLE,
298 };
299 #undef KWTUPLE
300 PyObject *argsbuf[3];
301 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
302 PyObject *data = NULL;
303 int usedforsecurity = 1;
304 PyObject *string_obj = NULL;
305
306 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
307 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
308 if (!args) {
309 goto exit;
310 }
311 if (!noptargs) {
312 goto skip_optional_pos;
313 }
314 if (args[0]) {
315 data = args[0];
316 if (!--noptargs) {
317 goto skip_optional_pos;
318 }
319 }
320 skip_optional_pos:
321 if (!noptargs) {
322 goto skip_optional_kwonly;
323 }
324 if (args[1]) {
325 usedforsecurity = PyObject_IsTrue(args[1]);
326 if (usedforsecurity < 0) {
327 goto exit;
328 }
329 if (!--noptargs) {
330 goto skip_optional_kwonly;
331 }
332 }
333 string_obj = args[2];
334 skip_optional_kwonly:
335 return_value = _sha2_sha224_impl(module, data, usedforsecurity, string_obj);
336
337 exit:
338 return return_value;
339 }
340
341 PyDoc_STRVAR(_sha2_sha512__doc__,
342 "sha512($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
343 "--\n"
344 "\n"
345 "Return a new SHA-512 hash object; optionally initialized with a string.");
346
347 #define _SHA2_SHA512_METHODDEF \
348 {"sha512", _PyCFunction_CAST(_sha2_sha512), METH_FASTCALL|METH_KEYWORDS, _sha2_sha512__doc__},
349
350 static PyObject *
351 _sha2_sha512_impl(PyObject *module, PyObject *data, int usedforsecurity,
352 PyObject *string_obj);
353
354 static PyObject *
355 _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
356 {
357 PyObject *return_value = NULL;
358 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
359
360 #define NUM_KEYWORDS 3
361 static struct {
362 PyGC_Head _this_is_not_used;
363 PyObject_VAR_HEAD
364 Py_hash_t ob_hash;
365 PyObject *ob_item[NUM_KEYWORDS];
366 } _kwtuple = {
367 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
368 .ob_hash = -1,
369 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
370 };
371 #undef NUM_KEYWORDS
372 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
373
374 #else // !Py_BUILD_CORE
375 # define KWTUPLE NULL
376 #endif // !Py_BUILD_CORE
377
378 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
379 static _PyArg_Parser _parser = {
380 .keywords = _keywords,
381 .fname = "sha512",
382 .kwtuple = KWTUPLE,
383 };
384 #undef KWTUPLE
385 PyObject *argsbuf[3];
386 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
387 PyObject *data = NULL;
388 int usedforsecurity = 1;
389 PyObject *string_obj = NULL;
390
391 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
392 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
393 if (!args) {
394 goto exit;
395 }
396 if (!noptargs) {
397 goto skip_optional_pos;
398 }
399 if (args[0]) {
400 data = args[0];
401 if (!--noptargs) {
402 goto skip_optional_pos;
403 }
404 }
405 skip_optional_pos:
406 if (!noptargs) {
407 goto skip_optional_kwonly;
408 }
409 if (args[1]) {
410 usedforsecurity = PyObject_IsTrue(args[1]);
411 if (usedforsecurity < 0) {
412 goto exit;
413 }
414 if (!--noptargs) {
415 goto skip_optional_kwonly;
416 }
417 }
418 string_obj = args[2];
419 skip_optional_kwonly:
420 return_value = _sha2_sha512_impl(module, data, usedforsecurity, string_obj);
421
422 exit:
423 return return_value;
424 }
425
426 PyDoc_STRVAR(_sha2_sha384__doc__,
427 "sha384($module, /, data=b\'\', *, usedforsecurity=True, string=None)\n"
428 "--\n"
429 "\n"
430 "Return a new SHA-384 hash object; optionally initialized with a string.");
431
432 #define _SHA2_SHA384_METHODDEF \
433 {"sha384", _PyCFunction_CAST(_sha2_sha384), METH_FASTCALL|METH_KEYWORDS, _sha2_sha384__doc__},
434
435 static PyObject *
436 _sha2_sha384_impl(PyObject *module, PyObject *data, int usedforsecurity,
437 PyObject *string_obj);
438
439 static PyObject *
440 _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
441 {
442 PyObject *return_value = NULL;
443 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
444
445 #define NUM_KEYWORDS 3
446 static struct {
447 PyGC_Head _this_is_not_used;
448 PyObject_VAR_HEAD
449 Py_hash_t ob_hash;
450 PyObject *ob_item[NUM_KEYWORDS];
451 } _kwtuple = {
452 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
453 .ob_hash = -1,
454 .ob_item = { &_Py_ID(data), &_Py_ID(usedforsecurity), &_Py_ID(string), },
455 };
456 #undef NUM_KEYWORDS
457 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
458
459 #else // !Py_BUILD_CORE
460 # define KWTUPLE NULL
461 #endif // !Py_BUILD_CORE
462
463 static const char * const _keywords[] = {"data", "usedforsecurity", "string", NULL};
464 static _PyArg_Parser _parser = {
465 .keywords = _keywords,
466 .fname = "sha384",
467 .kwtuple = KWTUPLE,
468 };
469 #undef KWTUPLE
470 PyObject *argsbuf[3];
471 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
472 PyObject *data = NULL;
473 int usedforsecurity = 1;
474 PyObject *string_obj = NULL;
475
476 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
477 /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
478 if (!args) {
479 goto exit;
480 }
481 if (!noptargs) {
482 goto skip_optional_pos;
483 }
484 if (args[0]) {
485 data = args[0];
486 if (!--noptargs) {
487 goto skip_optional_pos;
488 }
489 }
490 skip_optional_pos:
491 if (!noptargs) {
492 goto skip_optional_kwonly;
493 }
494 if (args[1]) {
495 usedforsecurity = PyObject_IsTrue(args[1]);
496 if (usedforsecurity < 0) {
497 goto exit;
498 }
499 if (!--noptargs) {
500 goto skip_optional_kwonly;
501 }
502 }
503 string_obj = args[2];
504 skip_optional_kwonly:
505 return_value = _sha2_sha384_impl(module, data, usedforsecurity, string_obj);
506
507 exit:
508 return return_value;
509 }
510 /*[clinic end generated code: output=90625b237c774a9f input=a9049054013a1b77]*/