2015-04-03 17:53:51 -03:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2022-08-11 18:25:49 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
# include "pycore_gc.h" // PyGC_Head
|
|
|
|
# include "pycore_runtime.h" // _Py_ID()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-04-03 17:53:51 -03:00
|
|
|
PyDoc_STRVAR(crypt_crypt__doc__,
|
|
|
|
"crypt($module, word, salt, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Hash a *word* with the given *salt* and return the hashed password.\n"
|
|
|
|
"\n"
|
|
|
|
"*word* will usually be a user\'s password. *salt* (either a random 2 or 16\n"
|
|
|
|
"character string, possibly prefixed with $digit$ to indicate the method)\n"
|
|
|
|
"will be used to perturb the encryption algorithm and produce distinct\n"
|
|
|
|
"results for a given *word*.");
|
|
|
|
|
|
|
|
#define CRYPT_CRYPT_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"crypt", _PyCFunction_CAST(crypt_crypt), METH_FASTCALL, crypt_crypt__doc__},
|
2015-04-03 17:53:51 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
crypt_crypt_impl(PyObject *module, const char *word, const char *salt);
|
2015-04-03 17:53:51 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
crypt_crypt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-04-03 17:53:51 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
const char *word;
|
|
|
|
const char *salt;
|
|
|
|
|
2019-01-11 10:01:14 -04:00
|
|
|
if (!_PyArg_CheckPositional("crypt", nargs, 2, 2)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!PyUnicode_Check(args[0])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("crypt", "argument 1", "str", args[0]);
|
2019-01-11 10:01:14 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
Py_ssize_t word_length;
|
|
|
|
word = PyUnicode_AsUTF8AndSize(args[0], &word_length);
|
|
|
|
if (word == NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (strlen(word) != (size_t)word_length) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!PyUnicode_Check(args[1])) {
|
2019-08-29 11:49:08 -03:00
|
|
|
_PyArg_BadArgument("crypt", "argument 2", "str", args[1]);
|
2019-01-11 10:01:14 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
Py_ssize_t salt_length;
|
|
|
|
salt = PyUnicode_AsUTF8AndSize(args[1], &salt_length);
|
|
|
|
if (salt == NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (strlen(salt) != (size_t)salt_length) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-04-03 17:53:51 -03:00
|
|
|
return_value = crypt_crypt_impl(module, word, salt);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2022-08-11 18:25:49 -03:00
|
|
|
/*[clinic end generated code: output=235ccef9211184f4 input=a9049054013a1b77]*/
|