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