
    g5                     *   S r SSKJr  SSKr\R                  " \5      rSSKJrJ	r	J
r
  SSKJr  SSKJrJr  SSKJs  Jr  SS/rS	rS
rSrSrSrSS jr " S S\R6                  \R8                  5      r " S S\R<                  \5      r " S S\5      r g)z0passlib.handlers.md5_crypt - md5-crypt algorithm    )md5N)
safe_crypt
test_cryptrepeat_string)h64)unicodeu	md5_cryptapr_md5_crypt    s   $1$s   $apr1$))r            r   r   )r      r   r   r   r   )   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )      r         r         r      	   r   r   
   r      c                    [        U [        5      (       a  U R                  S5      n [        U [        5      (       d   S5       e[        U ;   a#  [
        R                  R                  [        5      e[        U 5      n[        U[        5      (       d   S5       eUR                  S5      n[        U5      S:  d   S5       eU(       a  [        nO[        n[        X-   U -   5      R                  5       n[        X-   U-   5      nUR                  nU" [        XS5      5        UnU SS n	U(       a&  U" US-  (       a  [        OU	5        US-  nU(       a  M&  UR                  5       n
X -   nX-   nXXU -   X-   X-   /n[          VVs/ s H  u  pX   X   4PM     nnnU
nS	nU(       aO  U H;  u  p[        U[        UU-   5      R                  5       -   5      R                  5       nM=     US-  nU(       a  MO  USS
  H;  u  p[        U[        UU-   5      R                  5       -   5      R                  5       nM=     ["        R$                  " U[&        5      R)                  S5      $ s  snnf )ab  perform raw md5-crypt calculation

this function provides a pure-python implementation of the internals
for the MD5-Crypt algorithms; it doesn't handle any of the
parsing/validation of the hash strings themselves.

:arg pwd: password chars/bytes to hash
:arg salt: salt chars to use
:arg use_apr: use apache variant

:returns:
    encoded checksum chars
zutf-8zpwd not unicode or byteszsalt not unicodeasciir   zsalt too largeNr         )
isinstancer   encodebytes_BNULLuhexcNullPasswordErrorr
   len
_APR_MAGIC
_MD5_MAGICr   digestupdater   _c_digest_offsetsr   encode_transposed_bytes_transpose_mapdecode)pwdsaltuse_aprpwd_lenmagicdba_ctxa_ctx_updateievenchardapwd_pwdpwd_saltpermsevenodddatadcblockss                      S/home/matz/Project1/venv/lib/python3.13/site-packages/passlib/handlers/md5_crypt.py_raw_md5_cryptrG   ,   s6   4 #wjj!c5!!=#==!}ff&&y11#hG dG$$8&88$;;wDt9q=***= 
 
SZ#		%	%	'B d"#E<<L r+, 	A2AwH
q1uV(3	a !
 
B\ gGxH8c\48T\JE 9JJ8I94ek5:&8IDJ 
BF
IDS3rDy>00223::<B ! & #2Y	s29~,,../668  &&r>:AA'JJ# Ks   ?Ic                   j    \ rS rSrSrSrSr\R                  r	Sr
\R                  r\S 5       rS rSrg	)
_MD5_Common   z+common code for md5_crypt and apr_md5_crypt)r4   	salt_size   r   c                 P    [         R                  " XR                  U S9u  p#U " X#S9$ )N)handler)r4   checksum)r'   	parse_mc2ident)clshashr4   chks       rF   from_string_MD5_Common.from_string   s#    LLyy#>	++    c                 n    [         R                  " U R                  U R                  U R                  5      $ N)r'   
render_mc2rQ   r4   rO   )selfs    rF   	to_string_MD5_Common.to_string   s!    }}TZZDMMBBrW    N)__name__
__module____qualname____firstlineno____doc__setting_kwdschecksum_sizer'   HASH64_CHARSchecksum_charsmax_salt_size
salt_charsclassmethodrU   r\   __static_attributes__r^   rW   rF   rI   rI      sB    5
 )LM__NMJ , ,CrW   rI   c                   \    \ rS rSrSrS r\" S5      rSr\	S 5       r
S r\	S 5       rS rS	rg
)r
      a=  This class implements the MD5-Crypt password hash, and follows the :ref:`password-hash-api`.

It supports a variable-length salt.

The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

:type salt: str
:param salt:
    Optional salt string.
    If not specified, one will be autogenerated (this is recommended).
    If specified, it must be 0-8 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

:type salt_size: int
:param salt_size:
    Optional number of characters to use when autogenerating new salts.
    Defaults to 8, but can be any value between 0 and 8.
    (This is mainly needed when generating Cisco-compatible hashes,
    which require ``salt_size=4``).

:type relaxed: bool
:param relaxed:
    By default, providing an invalid value for one of the other
    keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
    and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
    will be issued instead. Correctable errors include
    ``salt`` strings that are too long.

    .. versionadded:: 1.6
z$1$)os_cryptbuiltinc                 ^    [        SS5      (       a  U R                  U R                  5        gg)Ntestz$1$test$pi/xDtU5WFVRqYS6BMU8X/TF)r   _set_calc_checksum_backend_calc_checksum_os_cryptrR   s    rF   _load_backend_os_crypt md5_crypt._load_backend_os_crypt  s*    f>??**3+F+FGrW   c                    U R                   U R                  -   n[        X5      nUc  U R                  U5      $ UR	                  U5      (       a  [        U5      [        U5      S-   :w  a   [        R                  R                  XU5      eUSS  $ )Nr!   i)	rQ   r4   r   _calc_checksum_builtin
startswithr*   r'   r(   CryptBackendError)r[   secretconfigrS   s       rF   rs   !md5_crypt._calc_checksum_os_crypt  s|    dii'&)< ..v66v&&#d)s6{R7G*G&&**4>>CDzrW   c                 :    U R                  U R                  5        g)NT)rr   rx   rt   s    rF   _load_backend_builtinmd5_crypt._load_backend_builtin%  s    &&s'A'ABrW   c                 ,    [        XR                  5      $ rY   rG   r4   r[   r{   s     rF   rx    md5_crypt._calc_checksum_builtin*  s    fii00rW   r^   N)r_   r`   ra   rb   rc   namer	   rQ   backendsrj   ru   rs   r   rx   rk   r^   rW   rF   r
   r
      sQ    @ DeHE 'H
  	  1rW   c                   2    \ rS rSrSrS r\" S5      rS rSr	g)r   i1  a0  This class implements the Apr-MD5-Crypt password hash, and follows the :ref:`password-hash-api`.

It supports a variable-length salt.

The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

:type salt: str
:param salt:
    Optional salt string.
    If not specified, one will be autogenerated (this is recommended).
    If specified, it must be 0-8 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

:type relaxed: bool
:param relaxed:
    By default, providing an invalid value for one of the other
    keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
    and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
    will be issued instead. Correctable errors include
    ``salt`` strings that are too long.

    .. versionadded:: 1.6
z$apr1$c                 *    [        XR                  SS9$ )NT)r5   r   r   s     rF   _calc_checksumapr_md5_crypt._calc_checksumQ  s    fii>>rW   r^   N)
r_   r`   ra   rb   rc   r   r	   rQ   r   rk   r^   rW   rF   r   r   1  s    2 DhKE
?rW   )F)!rc   hashlibr   logging	getLoggerr_   logpasslib.utilsr   r   r   passlib.utils.binaryr   passlib.utils.compatr   r	   passlib.utils.handlersutilshandlersr'   __all__r&   r,   r+   r/   r1   rG   HasSaltGenericHandlerrI   HasManyBackendsr
   r   r^   rW   rF   <module>r      s    6
  g''1 @ ? $ + # #  


  HOKhC"**b// C@K1""K K1b!?K !?rW   