cryptmodule.c 1.29 KB
Newer Older
1 2 3
/* cryptmodule.c - by Steve Majewski
 */

Roger E. Masse's avatar
Roger E. Masse committed
4
#include "Python.h"
5 6 7

#include <sys/types.h>

8 9 10
#ifdef __VMS
#include <openssl/des.h>
#endif
11 12 13 14

/* Module crypt */


Peter Schneider-Kamp's avatar
Peter Schneider-Kamp committed
15
static PyObject *crypt_crypt(PyObject *self, PyObject *args)
16 17
{
	char *word, *salt; 
18
#ifndef __VMS
19
	extern char * crypt(const char *, const char *);
20
#endif
21

Neal Norwitz's avatar
Neal Norwitz committed
22
	if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
23 24
		return NULL;
	}
25 26 27
	/* On some platforms (AtheOS) crypt returns NULL for an invalid
	   salt. Return None in that case. XXX Maybe raise an exception?  */
	return Py_BuildValue("s", crypt(word, salt));
28 29 30

}

31 32
PyDoc_STRVAR(crypt_crypt__doc__,
"crypt(word, salt) -> string\n\
33 34 35 36
word will usually be a user's password. salt is a 2-character string\n\
which will be used to select one of 4096 variations of DES. The characters\n\
in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
the hashed password as a string, which will be composed of characters from\n\
37
the same alphabet as the salt.");
38 39


Roger E. Masse's avatar
Roger E. Masse committed
40
static PyMethodDef crypt_methods[] = {
Neal Norwitz's avatar
Neal Norwitz committed
41
	{"crypt",	crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
42 43 44
	{NULL,		NULL}		/* sentinel */
};

45 46 47 48 49 50 51 52 53 54 55 56 57

static struct PyModuleDef cryptmodule = {
	PyModuleDef_HEAD_INIT,
	"crypt",
	NULL,
	-1,
	crypt_methods,
	NULL,
	NULL,
	NULL,
	NULL
};

58
PyMODINIT_FUNC
59
PyInit_crypt(void)
60
{
61
	return PyModule_Create(&cryptmodule);
62
}