(root)/
Python-3.12.0/
Modules/
clinic/
sha2module.c.h
       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  SHA256Type_copy(SHA256object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      25  {
      26      if (nargs) {
      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) {
      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, /, 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  _sha2_sha256(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     159  {
     160      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      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     188      PyObject *string = NULL;
     189      int usedforsecurity = 1;
     190  
     191      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     192      if (!args) {
     193          goto exit;
     194      }
     195      if (!noptargs) {
     196          goto skip_optional_pos;
     197      }
     198      if (args[0]) {
     199          string = args[0];
     200          if (!--noptargs) {
     201              goto skip_optional_pos;
     202          }
     203      }
     204  skip_optional_pos:
     205      if (!noptargs) {
     206          goto skip_optional_kwonly;
     207      }
     208      usedforsecurity = PyObject_IsTrue(args[1]);
     209      if (usedforsecurity < 0) {
     210          goto exit;
     211      }
     212  skip_optional_kwonly:
     213      return_value = _sha2_sha256_impl(module, string, usedforsecurity);
     214  
     215  exit:
     216      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  _sha2_sha224(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     233  {
     234      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      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     262      PyObject *string = NULL;
     263      int usedforsecurity = 1;
     264  
     265      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     266      if (!args) {
     267          goto exit;
     268      }
     269      if (!noptargs) {
     270          goto skip_optional_pos;
     271      }
     272      if (args[0]) {
     273          string = args[0];
     274          if (!--noptargs) {
     275              goto skip_optional_pos;
     276          }
     277      }
     278  skip_optional_pos:
     279      if (!noptargs) {
     280          goto skip_optional_kwonly;
     281      }
     282      usedforsecurity = PyObject_IsTrue(args[1]);
     283      if (usedforsecurity < 0) {
     284          goto exit;
     285      }
     286  skip_optional_kwonly:
     287      return_value = _sha2_sha224_impl(module, string, usedforsecurity);
     288  
     289  exit:
     290      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  _sha2_sha512(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     307  {
     308      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      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     336      PyObject *string = NULL;
     337      int usedforsecurity = 1;
     338  
     339      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     340      if (!args) {
     341          goto exit;
     342      }
     343      if (!noptargs) {
     344          goto skip_optional_pos;
     345      }
     346      if (args[0]) {
     347          string = args[0];
     348          if (!--noptargs) {
     349              goto skip_optional_pos;
     350          }
     351      }
     352  skip_optional_pos:
     353      if (!noptargs) {
     354          goto skip_optional_kwonly;
     355      }
     356      usedforsecurity = PyObject_IsTrue(args[1]);
     357      if (usedforsecurity < 0) {
     358          goto exit;
     359      }
     360  skip_optional_kwonly:
     361      return_value = _sha2_sha512_impl(module, string, usedforsecurity);
     362  
     363  exit:
     364      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  _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     381  {
     382      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      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     410      PyObject *string = NULL;
     411      int usedforsecurity = 1;
     412  
     413      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     414      if (!args) {
     415          goto exit;
     416      }
     417      if (!noptargs) {
     418          goto skip_optional_pos;
     419      }
     420      if (args[0]) {
     421          string = args[0];
     422          if (!--noptargs) {
     423              goto skip_optional_pos;
     424          }
     425      }
     426  skip_optional_pos:
     427      if (!noptargs) {
     428          goto skip_optional_kwonly;
     429      }
     430      usedforsecurity = PyObject_IsTrue(args[1]);
     431      if (usedforsecurity < 0) {
     432          goto exit;
     433      }
     434  skip_optional_kwonly:
     435      return_value = _sha2_sha384_impl(module, string, usedforsecurity);
     436  
     437  exit:
     438      return return_value;
     439  }
     440  /*[clinic end generated code: output=f81dacb48f3fee72 input=a9049054013a1b77]*/