_cryptmodule.c.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(crypt_crypt__doc__,
  9. "crypt($module, word, salt, /)\n"
  10. "--\n"
  11. "\n"
  12. "Hash a *word* with the given *salt* and return the hashed password.\n"
  13. "\n"
  14. "*word* will usually be a user\'s password. *salt* (either a random 2 or 16\n"
  15. "character string, possibly prefixed with $digit$ to indicate the method)\n"
  16. "will be used to perturb the encryption algorithm and produce distinct\n"
  17. "results for a given *word*.");
  18. #define CRYPT_CRYPT_METHODDEF \
  19. {"crypt", _PyCFunction_CAST(crypt_crypt), METH_FASTCALL, crypt_crypt__doc__},
  20. static PyObject *
  21. crypt_crypt_impl(PyObject *module, const char *word, const char *salt);
  22. static PyObject *
  23. crypt_crypt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  24. {
  25. PyObject *return_value = NULL;
  26. const char *word;
  27. const char *salt;
  28. if (!_PyArg_CheckPositional("crypt", nargs, 2, 2)) {
  29. goto exit;
  30. }
  31. if (!PyUnicode_Check(args[0])) {
  32. _PyArg_BadArgument("crypt", "argument 1", "str", args[0]);
  33. goto exit;
  34. }
  35. Py_ssize_t word_length;
  36. word = PyUnicode_AsUTF8AndSize(args[0], &word_length);
  37. if (word == NULL) {
  38. goto exit;
  39. }
  40. if (strlen(word) != (size_t)word_length) {
  41. PyErr_SetString(PyExc_ValueError, "embedded null character");
  42. goto exit;
  43. }
  44. if (!PyUnicode_Check(args[1])) {
  45. _PyArg_BadArgument("crypt", "argument 2", "str", args[1]);
  46. goto exit;
  47. }
  48. Py_ssize_t salt_length;
  49. salt = PyUnicode_AsUTF8AndSize(args[1], &salt_length);
  50. if (salt == NULL) {
  51. goto exit;
  52. }
  53. if (strlen(salt) != (size_t)salt_length) {
  54. PyErr_SetString(PyExc_ValueError, "embedded null character");
  55. goto exit;
  56. }
  57. return_value = crypt_crypt_impl(module, word, salt);
  58. exit:
  59. return return_value;
  60. }
  61. /*[clinic end generated code: output=235ccef9211184f4 input=a9049054013a1b77]*/