Branch data Line data Source code
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 : :
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 : 0 : SHA256Type_copy(SHA256object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
25 : : {
26 [ # # ]: 0 : if (nargs) {
27 : 0 : PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
28 : 0 : return NULL;
29 : : }
30 : 0 : 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 : 0 : SHA512Type_copy(SHA512object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
47 : : {
48 [ # # ]: 0 : if (nargs) {
49 : 0 : PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
50 : 0 : return NULL;
51 : : }
52 : 0 : 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 : 0 : SHA256Type_digest(SHA256object *self, PyObject *Py_UNUSED(ignored))
69 : : {
70 : 0 : 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 : 0 : SHA512Type_digest(SHA512object *self, PyObject *Py_UNUSED(ignored))
87 : : {
88 : 0 : 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 : 0 : SHA256Type_hexdigest(SHA256object *self, PyObject *Py_UNUSED(ignored))
105 : : {
106 : 0 : 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 : 0 : SHA512Type_hexdigest(SHA512object *self, PyObject *Py_UNUSED(ignored))
123 : : {
124 : 0 : 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, /, string=b\'\', *, usedforsecurity=True)\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 *string, int usedforsecurity);
156 : :
157 : : static PyObject *
158 : 0 : _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
159 : : {
160 : 0 : PyObject *return_value = NULL;
161 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
162 : :
163 : : #define NUM_KEYWORDS 2
164 : : static struct {
165 : : PyGC_Head _this_is_not_used;
166 : : PyObject_VAR_HEAD
167 : : PyObject *ob_item[NUM_KEYWORDS];
168 : : } _kwtuple = {
169 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
170 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
171 : : };
172 : : #undef NUM_KEYWORDS
173 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
174 : :
175 : : #else // !Py_BUILD_CORE
176 : : # define KWTUPLE NULL
177 : : #endif // !Py_BUILD_CORE
178 : :
179 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
180 : : static _PyArg_Parser _parser = {
181 : : .keywords = _keywords,
182 : : .fname = "sha256",
183 : : .kwtuple = KWTUPLE,
184 : : };
185 : : #undef KWTUPLE
186 : : PyObject *argsbuf[2];
187 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
188 : 0 : PyObject *string = NULL;
189 : 0 : int usedforsecurity = 1;
190 : :
191 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
192 [ # # ]: 0 : if (!args) {
193 : 0 : goto exit;
194 : : }
195 [ # # ]: 0 : if (!noptargs) {
196 : 0 : goto skip_optional_pos;
197 : : }
198 [ # # ]: 0 : if (args[0]) {
199 : 0 : string = args[0];
200 [ # # ]: 0 : if (!--noptargs) {
201 : 0 : goto skip_optional_pos;
202 : : }
203 : : }
204 : 0 : skip_optional_pos:
205 [ # # ]: 0 : if (!noptargs) {
206 : 0 : goto skip_optional_kwonly;
207 : : }
208 : 0 : usedforsecurity = PyObject_IsTrue(args[1]);
209 [ # # ]: 0 : if (usedforsecurity < 0) {
210 : 0 : goto exit;
211 : : }
212 : 0 : skip_optional_kwonly:
213 : 0 : return_value = _sha2_sha256_impl(module, string, usedforsecurity);
214 : :
215 : 0 : exit:
216 : 0 : return return_value;
217 : : }
218 : :
219 : : PyDoc_STRVAR(_sha2_sha224__doc__,
220 : : "sha224($module, /, string=b\'\', *, usedforsecurity=True)\n"
221 : : "--\n"
222 : : "\n"
223 : : "Return a new SHA-224 hash object; optionally initialized with a string.");
224 : :
225 : : #define _SHA2_SHA224_METHODDEF \
226 : : {"sha224", _PyCFunction_CAST(_sha2_sha224), METH_FASTCALL|METH_KEYWORDS, _sha2_sha224__doc__},
227 : :
228 : : static PyObject *
229 : : _sha2_sha224_impl(PyObject *module, PyObject *string, int usedforsecurity);
230 : :
231 : : static PyObject *
232 : 0 : _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
233 : : {
234 : 0 : PyObject *return_value = NULL;
235 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
236 : :
237 : : #define NUM_KEYWORDS 2
238 : : static struct {
239 : : PyGC_Head _this_is_not_used;
240 : : PyObject_VAR_HEAD
241 : : PyObject *ob_item[NUM_KEYWORDS];
242 : : } _kwtuple = {
243 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
244 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
245 : : };
246 : : #undef NUM_KEYWORDS
247 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
248 : :
249 : : #else // !Py_BUILD_CORE
250 : : # define KWTUPLE NULL
251 : : #endif // !Py_BUILD_CORE
252 : :
253 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
254 : : static _PyArg_Parser _parser = {
255 : : .keywords = _keywords,
256 : : .fname = "sha224",
257 : : .kwtuple = KWTUPLE,
258 : : };
259 : : #undef KWTUPLE
260 : : PyObject *argsbuf[2];
261 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
262 : 0 : PyObject *string = NULL;
263 : 0 : int usedforsecurity = 1;
264 : :
265 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
266 [ # # ]: 0 : if (!args) {
267 : 0 : goto exit;
268 : : }
269 [ # # ]: 0 : if (!noptargs) {
270 : 0 : goto skip_optional_pos;
271 : : }
272 [ # # ]: 0 : if (args[0]) {
273 : 0 : string = args[0];
274 [ # # ]: 0 : if (!--noptargs) {
275 : 0 : goto skip_optional_pos;
276 : : }
277 : : }
278 : 0 : skip_optional_pos:
279 [ # # ]: 0 : if (!noptargs) {
280 : 0 : goto skip_optional_kwonly;
281 : : }
282 : 0 : usedforsecurity = PyObject_IsTrue(args[1]);
283 [ # # ]: 0 : if (usedforsecurity < 0) {
284 : 0 : goto exit;
285 : : }
286 : 0 : skip_optional_kwonly:
287 : 0 : return_value = _sha2_sha224_impl(module, string, usedforsecurity);
288 : :
289 : 0 : exit:
290 : 0 : return return_value;
291 : : }
292 : :
293 : : PyDoc_STRVAR(_sha2_sha512__doc__,
294 : : "sha512($module, /, string=b\'\', *, usedforsecurity=True)\n"
295 : : "--\n"
296 : : "\n"
297 : : "Return a new SHA-512 hash object; optionally initialized with a string.");
298 : :
299 : : #define _SHA2_SHA512_METHODDEF \
300 : : {"sha512", _PyCFunction_CAST(_sha2_sha512), METH_FASTCALL|METH_KEYWORDS, _sha2_sha512__doc__},
301 : :
302 : : static PyObject *
303 : : _sha2_sha512_impl(PyObject *module, PyObject *string, int usedforsecurity);
304 : :
305 : : static PyObject *
306 : 0 : _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
307 : : {
308 : 0 : PyObject *return_value = NULL;
309 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
310 : :
311 : : #define NUM_KEYWORDS 2
312 : : static struct {
313 : : PyGC_Head _this_is_not_used;
314 : : PyObject_VAR_HEAD
315 : : PyObject *ob_item[NUM_KEYWORDS];
316 : : } _kwtuple = {
317 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
318 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
319 : : };
320 : : #undef NUM_KEYWORDS
321 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
322 : :
323 : : #else // !Py_BUILD_CORE
324 : : # define KWTUPLE NULL
325 : : #endif // !Py_BUILD_CORE
326 : :
327 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
328 : : static _PyArg_Parser _parser = {
329 : : .keywords = _keywords,
330 : : .fname = "sha512",
331 : : .kwtuple = KWTUPLE,
332 : : };
333 : : #undef KWTUPLE
334 : : PyObject *argsbuf[2];
335 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
336 : 0 : PyObject *string = NULL;
337 : 0 : int usedforsecurity = 1;
338 : :
339 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
340 [ # # ]: 0 : if (!args) {
341 : 0 : goto exit;
342 : : }
343 [ # # ]: 0 : if (!noptargs) {
344 : 0 : goto skip_optional_pos;
345 : : }
346 [ # # ]: 0 : if (args[0]) {
347 : 0 : string = args[0];
348 [ # # ]: 0 : if (!--noptargs) {
349 : 0 : goto skip_optional_pos;
350 : : }
351 : : }
352 : 0 : skip_optional_pos:
353 [ # # ]: 0 : if (!noptargs) {
354 : 0 : goto skip_optional_kwonly;
355 : : }
356 : 0 : usedforsecurity = PyObject_IsTrue(args[1]);
357 [ # # ]: 0 : if (usedforsecurity < 0) {
358 : 0 : goto exit;
359 : : }
360 : 0 : skip_optional_kwonly:
361 : 0 : return_value = _sha2_sha512_impl(module, string, usedforsecurity);
362 : :
363 : 0 : exit:
364 : 0 : return return_value;
365 : : }
366 : :
367 : : PyDoc_STRVAR(_sha2_sha384__doc__,
368 : : "sha384($module, /, string=b\'\', *, usedforsecurity=True)\n"
369 : : "--\n"
370 : : "\n"
371 : : "Return a new SHA-384 hash object; optionally initialized with a string.");
372 : :
373 : : #define _SHA2_SHA384_METHODDEF \
374 : : {"sha384", _PyCFunction_CAST(_sha2_sha384), METH_FASTCALL|METH_KEYWORDS, _sha2_sha384__doc__},
375 : :
376 : : static PyObject *
377 : : _sha2_sha384_impl(PyObject *module, PyObject *string, int usedforsecurity);
378 : :
379 : : static PyObject *
380 : 0 : _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
381 : : {
382 : 0 : PyObject *return_value = NULL;
383 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
384 : :
385 : : #define NUM_KEYWORDS 2
386 : : static struct {
387 : : PyGC_Head _this_is_not_used;
388 : : PyObject_VAR_HEAD
389 : : PyObject *ob_item[NUM_KEYWORDS];
390 : : } _kwtuple = {
391 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
392 : : .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
393 : : };
394 : : #undef NUM_KEYWORDS
395 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
396 : :
397 : : #else // !Py_BUILD_CORE
398 : : # define KWTUPLE NULL
399 : : #endif // !Py_BUILD_CORE
400 : :
401 : : static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
402 : : static _PyArg_Parser _parser = {
403 : : .keywords = _keywords,
404 : : .fname = "sha384",
405 : : .kwtuple = KWTUPLE,
406 : : };
407 : : #undef KWTUPLE
408 : : PyObject *argsbuf[2];
409 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
410 : 0 : PyObject *string = NULL;
411 : 0 : int usedforsecurity = 1;
412 : :
413 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
414 [ # # ]: 0 : if (!args) {
415 : 0 : goto exit;
416 : : }
417 [ # # ]: 0 : if (!noptargs) {
418 : 0 : goto skip_optional_pos;
419 : : }
420 [ # # ]: 0 : if (args[0]) {
421 : 0 : string = args[0];
422 [ # # ]: 0 : if (!--noptargs) {
423 : 0 : goto skip_optional_pos;
424 : : }
425 : : }
426 : 0 : skip_optional_pos:
427 [ # # ]: 0 : if (!noptargs) {
428 : 0 : goto skip_optional_kwonly;
429 : : }
430 : 0 : usedforsecurity = PyObject_IsTrue(args[1]);
431 [ # # ]: 0 : if (usedforsecurity < 0) {
432 : 0 : goto exit;
433 : : }
434 : 0 : skip_optional_kwonly:
435 : 0 : return_value = _sha2_sha384_impl(module, string, usedforsecurity);
436 : :
437 : 0 : exit:
438 : 0 : return return_value;
439 : : }
440 : : /*[clinic end generated code: output=f81dacb48f3fee72 input=a9049054013a1b77]*/
|