sha1module.c.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(SHA1Type_copy__doc__,
  9. "copy($self, /)\n"
  10. "--\n"
  11. "\n"
  12. "Return a copy of the hash object.");
  13. #define SHA1TYPE_COPY_METHODDEF \
  14. {"copy", _PyCFunction_CAST(SHA1Type_copy), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, SHA1Type_copy__doc__},
  15. static PyObject *
  16. SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls);
  17. static PyObject *
  18. SHA1Type_copy(SHA1object *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  19. {
  20. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  21. PyErr_SetString(PyExc_TypeError, "copy() takes no arguments");
  22. return NULL;
  23. }
  24. return SHA1Type_copy_impl(self, cls);
  25. }
  26. PyDoc_STRVAR(SHA1Type_digest__doc__,
  27. "digest($self, /)\n"
  28. "--\n"
  29. "\n"
  30. "Return the digest value as a bytes object.");
  31. #define SHA1TYPE_DIGEST_METHODDEF \
  32. {"digest", (PyCFunction)SHA1Type_digest, METH_NOARGS, SHA1Type_digest__doc__},
  33. static PyObject *
  34. SHA1Type_digest_impl(SHA1object *self);
  35. static PyObject *
  36. SHA1Type_digest(SHA1object *self, PyObject *Py_UNUSED(ignored))
  37. {
  38. return SHA1Type_digest_impl(self);
  39. }
  40. PyDoc_STRVAR(SHA1Type_hexdigest__doc__,
  41. "hexdigest($self, /)\n"
  42. "--\n"
  43. "\n"
  44. "Return the digest value as a string of hexadecimal digits.");
  45. #define SHA1TYPE_HEXDIGEST_METHODDEF \
  46. {"hexdigest", (PyCFunction)SHA1Type_hexdigest, METH_NOARGS, SHA1Type_hexdigest__doc__},
  47. static PyObject *
  48. SHA1Type_hexdigest_impl(SHA1object *self);
  49. static PyObject *
  50. SHA1Type_hexdigest(SHA1object *self, PyObject *Py_UNUSED(ignored))
  51. {
  52. return SHA1Type_hexdigest_impl(self);
  53. }
  54. PyDoc_STRVAR(SHA1Type_update__doc__,
  55. "update($self, obj, /)\n"
  56. "--\n"
  57. "\n"
  58. "Update this hash object\'s state with the provided string.");
  59. #define SHA1TYPE_UPDATE_METHODDEF \
  60. {"update", (PyCFunction)SHA1Type_update, METH_O, SHA1Type_update__doc__},
  61. PyDoc_STRVAR(_sha1_sha1__doc__,
  62. "sha1($module, /, string=b\'\', *, usedforsecurity=True)\n"
  63. "--\n"
  64. "\n"
  65. "Return a new SHA1 hash object; optionally initialized with a string.");
  66. #define _SHA1_SHA1_METHODDEF \
  67. {"sha1", _PyCFunction_CAST(_sha1_sha1), METH_FASTCALL|METH_KEYWORDS, _sha1_sha1__doc__},
  68. static PyObject *
  69. _sha1_sha1_impl(PyObject *module, PyObject *string, int usedforsecurity);
  70. static PyObject *
  71. _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  72. {
  73. PyObject *return_value = NULL;
  74. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  75. #define NUM_KEYWORDS 2
  76. static struct {
  77. PyGC_Head _this_is_not_used;
  78. PyObject_VAR_HEAD
  79. PyObject *ob_item[NUM_KEYWORDS];
  80. } _kwtuple = {
  81. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  82. .ob_item = { &_Py_ID(string), &_Py_ID(usedforsecurity), },
  83. };
  84. #undef NUM_KEYWORDS
  85. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  86. #else // !Py_BUILD_CORE
  87. # define KWTUPLE NULL
  88. #endif // !Py_BUILD_CORE
  89. static const char * const _keywords[] = {"string", "usedforsecurity", NULL};
  90. static _PyArg_Parser _parser = {
  91. .keywords = _keywords,
  92. .fname = "sha1",
  93. .kwtuple = KWTUPLE,
  94. };
  95. #undef KWTUPLE
  96. PyObject *argsbuf[2];
  97. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  98. PyObject *string = NULL;
  99. int usedforsecurity = 1;
  100. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  101. if (!args) {
  102. goto exit;
  103. }
  104. if (!noptargs) {
  105. goto skip_optional_pos;
  106. }
  107. if (args[0]) {
  108. string = args[0];
  109. if (!--noptargs) {
  110. goto skip_optional_pos;
  111. }
  112. }
  113. skip_optional_pos:
  114. if (!noptargs) {
  115. goto skip_optional_kwonly;
  116. }
  117. usedforsecurity = PyObject_IsTrue(args[1]);
  118. if (usedforsecurity < 0) {
  119. goto exit;
  120. }
  121. skip_optional_kwonly:
  122. return_value = _sha1_sha1_impl(module, string, usedforsecurity);
  123. exit:
  124. return return_value;
  125. }
  126. /*[clinic end generated code: output=ffe267896009b5ed input=a9049054013a1b77]*/