a DOg@s6dZddlZz ddlZWn.eyFejdkr:ednedYn0ddlZddlZ ddl m Z ddl mZe je jdZe ZGd d d ed d Zd&dd d dZd'ddZgZdd ddZeddddedddddD](Zeddeddeedd rqqedd d!d"ed#dd$d%[[dS)(zEWrapper to the POSIX crypt library call and associated functionality.NZwin32z,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*/opt/alt/python39/lib64/python3.9/crypt.py__repr__sz_Method.__repr__N)__name__ __module__ __qualname____doc__r rrrr rsrz name ident salt_chars total_sizeroundscCsB|durtd}|dur4t|ts4t|jjd|js@d}nd|jd}|jr|jddkr|durpd}n@t|d}|d|>krtd d |krd ksntd ||d d7}n^|jdvr|dur d|krdksntd|d|d7}n|dur t|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**31Z02d)56iiɚ;z+rounds out of the range 1000 to 999_999_999zrounds=z$ doesn't support the rounds argumentcss|]}ttVqdS)N)_srZchoice _saltchars).0charrrr Bzmksalt..) methods isinstanceint TypeError __class__r Zident bit_length ValueErrorjoinrangeZ salt_chars)methodrsZ log_roundsrrr mksalt s2    r+cCs&|dust|trt|}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!rr+_cryptcrypt)Zwordsaltrrr r-Fs r-c Gst|g|R}|td|<t||d}d}ztd|}Wn@ty|}z(|jtjkrfWYd}~dSWYd}~n d}~00|rt||jkrt |dSdS)NZMETHOD_rrFT) rglobalsr+r-OSErrorerrnoZEINVALlenZ total_sizer append)rrargsr)r.resulterrr _add_methodXs   r7ZSHA512rjZSHA256r?)byarZBLOWFISHr;ZMD51"ZCRYPT )N)N)rsys_sysr,ModuleNotFoundErrorplatform ImportErrorr1stringZ_stringZrandomrZ _SystemRandom collectionsrZ _namedtupleZ ascii_lettersZdigitsrrrr+r-r r7Z_vr2rrrr s4       &