
    RhI              
          d Z ddlZ	 ddlZddlZddlZ	ddl
Z
ddlmZ ddlmZ  e
j"                  ed	       e	j&                  e	j(                  z   d
z   Z e       Z G d d edd            Zd%dddZd%dZg ZdddZ edddd        edddd       dD ]  Z eddez   dd ee      z   d      s n  eddd d!        ed"dd#d$       [[y# e$ r  ej
                  dk(  r ed       ed      w xY w)&zEWrapper to the POSIX crypt library call and associated functionality.    Nwin32z,The crypt module is not supported on Windowsz;The required _crypt module was not built as part of CPython)SystemRandom)
namedtuple)      )removez./c                       e Zd ZdZd Zy)_MethodziClass representing a salt method per the Modular Crypt Format or the
    legacy 2-character crypt method.c                 8    dj                  | j                        S )Nz<crypt.METHOD_{}>)formatname)selfs    /usr/lib/python3.12/crypt.py__repr__z_Method.__repr__    s    "))$))44    N)__name__
__module____qualname____doc__r    r   r   r
   r
      s    (5r   r
   z name ident salt_chars total_sizeroundsc                   | 	t         d   } |2t        |t              s"t        |j                  j
                   d      | j                  sd}nd| j                   d}| j                  rn| j                  d   dk(  r\|d}nMt        j                  |dz
        }|d|z  k7  rt        d      d	|cxk  rd
k  st        d       t        d      ||ddz  }nL| j                  dv r.|<d|cxk  rdk  st        d       t        d      |d| dz  }n|t        |  d      |dj                  d t        | j                        D              z  }|S )zsGenerate a salt for the specified method.

    If not specified, the strongest available method will be used.

    r   z+ object cannot be interpreted as an integer $2      zrounds must be a power of 2      z%rounds out of the range 2**4 to 2**3102d)56i  iɚ;z+rounds out of the range 1000 to 999_999_999zrounds=z$ doesn't support the rounds argumentc              3   N   K   | ]  }t         j                  t                y wN)_srchoice
_saltchars).0chars     r   	<genexpr>zmksalt.<locals>.<genexpr>F   s     MDJ'Ms   #%)methods
isinstanceint	TypeError	__class__r   ident
bit_length
ValueErrorjoinrange
salt_chars)methodr   s
log_roundss       r   mksaltr:   $   s    ~*VS"96++445 64 5 6 	6<<~Q||Q3.>Jq1Jj( !>??
(b( !HII ) !HII	
3q!!		#60[0 !NOO 1 !NOO76(!$$A		F8#GHIIME&:K:K4LM	MMAHr   c                 h    |t        |t              rt        |      }t        j                  | |      S )aR  Return 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()``.

    )r-   r
   r:   _cryptcrypt)wordsalts     r   r=   r=   J   s,     |z$0d|<<d##r   c                x   t        | g| }|t               d| z   <   t        ||      }d }	 t        d|      }|r.t        |      |j                  k(  rt        j                  |       yy# t        $ rF}|j
                  t
        j                  t
        j                  t
        j                  hv rY d }~y d }~ww xY w)NMETHOD_r   r   FT)r
   globalsr:   r=   OSErrorerrnoEINVALEPERMENOSYSlen
total_sizer,   append)r   r   argsr7   r?   resultes          r   _add_methodrN   \   s    T!D!F"(GIi$&(DFr4 #f+!2!22v  77u||U[[%,,??	s   A* *	B93;B43B44B9SHA512r#      j   SHA256r"   ?   )byar   BLOWFISHr      ;   MD51   "   CRYPT   r   r%   )r   sys_sysr<   ModuleNotFoundErrorplatformImportErrorrD   string_stringwarningsrandomr   _SystemRandomcollectionsr   _namedtuple_deprecatedr   ascii_lettersdigitsr(   r&   r
   r:   r=   r,   rN   _vrH   r   r   r   <module>rp      s9   K Y    0 1   Xg . ""W^^3d:
o5k)%GH 5#$ #L$  $( " Hc2s # Hc2r "  B:sRxR#b'\$G E32  GT1b !k  Y}}HIIWXX	Ys   C %C6