Debian Codegraph @

pypy/module/crypt/interp_crypt.py

raw symbols SCIP
1 from pypy.interpreter.gateway import unwrap_spec
2 from rpython.rtyper.lltypesystem import rffi
3 from rpython.translator.tool.cbuild import ExternalCompilationInfo
4 import sys
5
6 if sys.platform.startswith('darwin'):
7 eci = ExternalCompilationInfo()
8 elif sys.platform.startswith('linux'):
9 # crypt() is defined only in crypt.h on some Linux variants (eg. Fedora 28)
10 eci = ExternalCompilationInfo(libraries=['crypt'], includes=["crypt.h"])
11 else:
12 eci = ExternalCompilationInfo(libraries=['crypt'])
13 c_crypt = rffi.llexternal('crypt', [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP,
14 compilation_info=eci, releasegil=False)
15
16 @unwrap_spec(word='text', salt='text')
17 def crypt(space, word, salt):
18 """word will usually be a user's password. salt is a 2-character string
19 which will be used to select one of 4096 variations of DES. The characters
20 in salt must be either ".", "/", or an alphanumeric character. Returns
21 the hashed password as a string, which will be composed of characters from
22 the same alphabet as the salt."""
23 res = c_crypt(word, salt)
24 if not res:
25 return space.w_None
26 str_res = rffi.charp2str(res)
27 return space.newtext(str_res)