/Modules/cryptmodule.c

http://unladen-swallow.googlecode.com/ · C · 49 lines · 32 code · 12 blank · 5 comment · 1 complexity · 52f8a3419ccd3257f1faf14714be1261 MD5 · raw file

  1. /* cryptmodule.c - by Steve Majewski
  2. */
  3. #include "Python.h"
  4. #include <sys/types.h>
  5. #ifdef __VMS
  6. #include <openssl/des.h>
  7. #endif
  8. /* Module crypt */
  9. static PyObject *crypt_crypt(PyObject *self, PyObject *args)
  10. {
  11. char *word, *salt;
  12. #ifndef __VMS
  13. extern char * crypt(const char *, const char *);
  14. #endif
  15. if (!PyArg_ParseTuple(args, "ss:crypt", &word, &salt)) {
  16. return NULL;
  17. }
  18. /* On some platforms (AtheOS) crypt returns NULL for an invalid
  19. salt. Return None in that case. XXX Maybe raise an exception? */
  20. return Py_BuildValue("s", crypt(word, salt));
  21. }
  22. PyDoc_STRVAR(crypt_crypt__doc__,
  23. "crypt(word, salt) -> string\n\
  24. word will usually be a user's password. salt is a 2-character string\n\
  25. which will be used to select one of 4096 variations of DES. The characters\n\
  26. in salt must be either \".\", \"/\", or an alphanumeric character. Returns\n\
  27. the hashed password as a string, which will be composed of characters from\n\
  28. the same alphabet as the salt.");
  29. static PyMethodDef crypt_methods[] = {
  30. {"crypt", crypt_crypt, METH_VARARGS, crypt_crypt__doc__},
  31. {NULL, NULL} /* sentinel */
  32. };
  33. PyMODINIT_FUNC
  34. initcrypt(void)
  35. {
  36. Py_InitModule("crypt", crypt_methods);
  37. }