|
7 | 7 |
|
8 | 8 | /* Module crypt */ |
9 | 9 |
|
| 10 | +/*[clinic input] |
| 11 | +module crypt |
| 12 | +[clinic start generated code]*/ |
| 13 | +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ |
10 | 14 |
|
11 | | -static PyObject *crypt_crypt(PyObject *self, PyObject *args) |
| 15 | + |
| 16 | +/*[clinic input] |
| 17 | +crypt.crypt |
| 18 | +
|
| 19 | + word: 's' |
| 20 | + salt: 's' |
| 21 | + / |
| 22 | +
|
| 23 | +Hash a *word* with the given *salt* and return the hashed password. |
| 24 | +
|
| 25 | +*word* will usually be a user's password. *salt* (either a random 2 or 16 |
| 26 | +character string, possibly prefixed with $digit$ to indicate the method) |
| 27 | +will be used to perturb the encryption algorithm and produce distinct |
| 28 | +results for a given *word*. |
| 29 | +
|
| 30 | +[clinic start generated code]*/ |
| 31 | + |
| 32 | +PyDoc_STRVAR(crypt_crypt__doc__, |
| 33 | +"crypt(word, salt)\n" |
| 34 | +"Hash a *word* with the given *salt* and return the hashed password.\n" |
| 35 | +"\n" |
| 36 | +"*word* will usually be a user\'s password. *salt* (either a random 2 or 16\n" |
| 37 | +"character string, possibly prefixed with $digit$ to indicate the method)\n" |
| 38 | +"will be used to perturb the encryption algorithm and produce distinct\n" |
| 39 | +"results for a given *word*."); |
| 40 | + |
| 41 | +#define CRYPT_CRYPT_METHODDEF \ |
| 42 | + {"crypt", (PyCFunction)crypt_crypt, METH_VARARGS, crypt_crypt__doc__}, |
| 43 | + |
| 44 | +static PyObject * |
| 45 | +crypt_crypt_impl(PyModuleDef *module, const char *word, const char *salt); |
| 46 | + |
| 47 | +static PyObject * |
| 48 | +crypt_crypt(PyModuleDef *module, PyObject *args) |
12 | 49 | { |
13 | | - char *word, *salt; |
| 50 | + PyObject *return_value = NULL; |
| 51 | + const char *word; |
| 52 | + const char *salt; |
| 53 | + |
| 54 | + if (!PyArg_ParseTuple(args, |
| 55 | + "ss:crypt", |
| 56 | + &word, &salt)) |
| 57 | + goto exit; |
| 58 | + return_value = crypt_crypt_impl(module, word, salt); |
| 59 | + |
| 60 | +exit: |
| 61 | + return return_value; |
| 62 | +} |
14 | 63 |
|
15 | | - if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) { |
16 | | - return NULL; |
17 | | - } |
| 64 | +static PyObject * |
| 65 | +crypt_crypt_impl(PyModuleDef *module, const char *word, const char *salt) |
| 66 | +/*[clinic end generated code: checksum=a137540bf6862f9935fc112b8bb1d62d6dd1ad02]*/ |
| 67 | +{ |
18 | 68 | /* On some platforms (AtheOS) crypt returns NULL for an invalid |
19 | 69 | salt. Return None in that case. XXX Maybe raise an exception? */ |
20 | 70 | return Py_BuildValue("s", crypt(word, salt)); |
21 | | - |
22 | 71 | } |
23 | 72 |
|
24 | | -PyDoc_STRVAR(crypt_crypt__doc__, |
25 | | -"crypt(word, salt) -> string\n\ |
26 | | -word will usually be a user's password. salt is a 2-character string\n\ |
27 | | -which will be used to select one of 4096 variations of DES. The characters\n\ |
28 | | -in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\ |
29 | | -the hashed password as a string, which will be composed of characters from\n\ |
30 | | -the same alphabet as the salt."); |
31 | | - |
32 | 73 |
|
33 | 74 | static PyMethodDef crypt_methods[] = { |
34 | | - {"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__}, |
| 75 | + CRYPT_CRYPT_METHODDEF |
35 | 76 | {NULL, NULL} /* sentinel */ |
36 | 77 | }; |
37 | 78 |
|
|
0 commit comments