o w[e@s.dZddlZzddlZWney ejdkrededwddlZddlZ ddl m Z ddl mZe je jdZe ZGd d d ed d Zd&dd d dZd&ddZgZdd ddZeddddedddddD]Zeddeddeedd rnqqedd d!d"ed#dd$d%[[dS)'zEWrapper to the POSIX crypt library call and associated functionality.Nwin32z,The crypt module is not supported on Windowsz;The required _crypt module was not built as part of CPython) SystemRandom) namedtuplez./c@seZdZdZddZdS)_MethodziClass representing a salt method per the Modular Crypt Format or the legacy 2-character crypt method.cCs d|jS)Nz)formatname)selfr /usr/lib/python3.10/crypt.py__repr__s z_Method.__repr__N)__name__ __module__ __qualname____doc__r r r r r rs rz name ident salt_chars total_sizeroundscCsH|durtd}|durt|tst|jjd|js d}nd|jd}|jrd|jddkrd|dur8d}n#t|d}|d|>krItd d |krVd ks[td td ||d d7}n/|jdvr|durd|krzdkstdtd|d|d7}n |durt|d|d ddt |j D7}|S)zsGenerate a salt for the specified method. If not specified, the strongest available method will be used. Nrz+ object cannot be interpreted as an integer$2 zrounds must be a power of 2z%rounds out of the range 2**4 to 2**3102d)56iiɚ;z+rounds out of the range 1000 to 999_999_999zrounds=z$ doesn't support the rounds argumentcss|]}ttVqdSN)_srchoice _saltchars).0charr r r Bszmksalt..) methods isinstanceint TypeError __class__r ident bit_length ValueErrorjoinrange salt_chars)methodrs log_roundsr r r mksalt s<  r1cCs&|dus t|tr t|}t||S)aRReturn a string representing the one-way hash of a password, with a salt prepended. If ``salt`` is not specified or is ``None``, the strongest available method will be selected and a salt generated. Otherwise, ``salt`` may be one of the ``crypt.METHOD_*`` values, or a string as returned by ``crypt.mksalt()``. N)r$rr1_cryptcrypt)wordsaltr r r r3Fs  r3c Gst|g|R}|td|<t||d}d}ztd|}Wnty=}z|jtjtjtjhvr8WYd}~dSd}~ww|rNt ||j krNt |dSdS)NMETHOD_rrFT) rglobalsr1r3OSErrorerrnoEINVALEPERMENOSYSlen total_sizer#append)rrargsr.r5resulter r r _add_methodXs   rCSHA512rjSHA256r?)byarBLOWFISHr;MD51"CRYPT r)rsys_sysr2ModuleNotFoundErrorplatform ImportErrorr9string_stringrandomr _SystemRandom collectionsr _namedtuple ascii_lettersdigitsrrrr1r3r#rC_vr=r r r r s:      &