ยปCore Development>Code coverage>Modules/_cryptmodule.c

Python code coverage for Modules/_cryptmodule.c

#countcontent
1n/a/* cryptmodule.c - by Steve Majewski
2n/a */
3n/a
4n/a#include "Python.h"
5n/a
6n/a#include <sys/types.h>
7n/a
8n/a/* Module crypt */
9n/a
10n/a/*[clinic input]
11n/amodule crypt
12n/a[clinic start generated code]*/
13n/a/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c6252cf4f2f2ae81]*/
14n/a
15n/a#include "clinic/_cryptmodule.c.h"
16n/a
17n/a/*[clinic input]
18n/acrypt.crypt
19n/a
20n/a word: str
21n/a salt: str
22n/a /
23n/a
24n/aHash a *word* with the given *salt* and return the hashed password.
25n/a
26n/a*word* will usually be a user's password. *salt* (either a random 2 or 16
27n/acharacter string, possibly prefixed with $digit$ to indicate the method)
28n/awill be used to perturb the encryption algorithm and produce distinct
29n/aresults for a given *word*.
30n/a
31n/a[clinic start generated code]*/
32n/a
33n/astatic PyObject *
34n/acrypt_crypt_impl(PyObject *module, const char *word, const char *salt)
35n/a/*[clinic end generated code: output=0512284a03d2803c input=0e8edec9c364352b]*/
36n/a{
37n/a /* On some platforms (AtheOS) crypt returns NULL for an invalid
38n/a salt. Return None in that case. XXX Maybe raise an exception? */
39n/a return Py_BuildValue("s", crypt(word, salt));
40n/a}
41n/a
42n/a
43n/astatic PyMethodDef crypt_methods[] = {
44n/a CRYPT_CRYPT_METHODDEF
45n/a {NULL, NULL} /* sentinel */
46n/a};
47n/a
48n/a
49n/astatic struct PyModuleDef cryptmodule = {
50n/a PyModuleDef_HEAD_INIT,
51n/a "_crypt",
52n/a NULL,
53n/a -1,
54n/a crypt_methods,
55n/a NULL,
56n/a NULL,
57n/a NULL,
58n/a NULL
59n/a};
60n/a
61n/aPyMODINIT_FUNC
62n/aPyInit__crypt(void)
63n/a{
64n/a return PyModule_Create(&cryptmodule);
65n/a}