
     h5                     (   d Z ddlmZ ddlZ ej                  e      ZddlmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmc mZ ddgZd	Zd
ZdZdZdZddZ G d dej6                  ej8                        Z G d dej<                  e      Z G d de      Z y)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                 p   t        | t              r| j                  d      } t        | t              sJ d       t        | v r#t
        j                  j                  t              t        |       }t        |t              sJ d       |j                  d      }t        |      dk  sJ d       |rt        }nt        }t        | |z   | z         j                         }t        | |z   |z         }|j                  } |t        ||             |}| dd }	|r ||dz  rt        n|	       |dz  }|r|j                         }
| | z   }| |z   }| |||| z   || z   ||z   g}t         D cg c]  \  }}||   ||   f }}}|
}d	}|rH|D ];  \  }}t        |t        ||z         j                         z         j                         }= |dz  }|rH|dd
 D ];  \  }}t        |t        ||z         j                         z         j                         }= t#        j$                  |t&              j)                  d      S c c}}w )a  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                      \/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/passlib/handlers/md5_crypt.py_raw_md5_cryptrG   ,   sD   4 #wjj!c5!=#==}ff&&y11#hG dG$8&88;;wDt9q=*** 
 
S4Z#		%	%	'B ed"#E<<L r7+, 	A2AwH
q1uV(3	a 
 
B\ #gG4xH'8Xc\48T'\JE 9JJ94eDk5:&JDJ 
BF
 	=ID#S3rDy>00223::<B	=!  #2Y 9	cs29~,,../6689 &&r>:AA'JJ# Ks   !H2c                   b    e Zd ZdZdZdZej                  ZdZ	ej                  Z
ed        Zd Zy)_MD5_Commonz+common code for md5_crypt and apr_md5_crypt)r4   	salt_size   r   c                 `    t        j                  || j                  |       \  }} | ||      S )N)handler)r4   checksum)r'   	parse_mc2ident)clshashr4   chks       rF   from_stringz_MD5_Common.from_string   s)    LLsyy#>	cs++    c                 l    t        j                  | j                  | j                  | j                        S N)r'   
render_mc2rP   r4   rN   )selfs    rF   	to_stringz_MD5_Common.to_string   s!    }}TZZDMMBBrU   N)__name__
__module____qualname____doc__setting_kwdschecksum_sizer'   HASH64_CHARSchecksum_charsmax_salt_size
salt_charsclassmethodrT   rZ    rU   rF   rI   rI      sB    5
 )LM__NMJ , ,CrU   rI   c                   T    e Zd ZdZd Z ed      ZdZed        Z	d Z
ed        Zd Zy)	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                 T    t        dd      r| j                  | j                         yy)Ntestz$1$test$pi/xDtU5WFVRqYS6BMU8X/TF)r   _set_calc_checksum_backend_calc_checksum_os_cryptrQ   s    rF   _load_backend_os_cryptz md5_crypt._load_backend_os_crypt  s'    f>?**3+F+FGrU   c                    | j                   | j                  z   }t        ||      }|| j                  |      S |j	                  |      rt        |      t        |      dz   k7  r!t        j                  j                  | ||      |dd  S )Nr!   i)	rP   r4   r   _calc_checksum_builtin
startswithr*   r'   r(   CryptBackendError)rY   secretconfigrR   s       rF   rm   z!md5_crypt._calc_checksum_os_crypt  s}    dii'&&)< ..v66v&#d)s6{R7G*G&&**4>>CDzrU   c                 :    | j                  | j                         y)NT)rl   rq   rn   s    rF   _load_backend_builtinzmd5_crypt._load_backend_builtin%  s    &&s'A'ABrU   c                 .    t        || j                        S rW   rG   r4   rY   rt   s     rF   rq   z md5_crypt._calc_checksum_builtin*  s    fdii00rU   N)r[   r\   r]   r^   namer	   rP   backendsre   ro   rm   rw   rq   rf   rU   rF   r
   r
      sQ    @ DeHE 'H
  	  1rU   c                   *    e Zd ZdZd Z ed      Zd Zy)r   ap  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                 2    t        || j                  d      S )NT)r5   ry   rz   s     rF   _calc_checksumzapr_md5_crypt._calc_checksumQ  s    fdii>>rU   N)r[   r\   r]   r^   r{   r	   rP   r   rf   rU   rF   r   r   1  s    2 DhKE
?rU   )F)!r^   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   rf   rU   rF   <module>r      s    6
  'g''1 @ ? $ + # #  


  HOKhC"**b// C@K1""K K1b!?K !?rU   