ó
øÐLac           @   sO  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 j j Z d d g Z d	 Z d
 Z d Z d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 f Z d6 Z e d „ Z d e j e j f d „  ƒ  YZ d e j e f d „  ƒ  YZ  d e f d  „  ƒ  YZ! d S(7   s0   passlib.handlers.md5_crypt - md5-crypt algorithmiÿÿÿÿ(   t   md5N(   t
   safe_cryptt
   test_cryptt   repeat_string(   t   h64(   t   unicodet   ut	   md5_cryptt   apr_md5_crypts    s   $1$s   $apr1$i    i   i   i   i   i   i   i   i   i   i   i   i   i	   i
   i   c         C   s|  t  |  t ƒ r! |  j d ƒ }  n  t  |  t ƒ s< t d ƒ ‚ t |  k r] t j j t	 ƒ ‚ n  t
 |  ƒ } t  | t ƒ s„ t d ƒ ‚ | j d ƒ } t
 | ƒ d k  s± t d ƒ ‚ | rÀ t } n t } t |  | |  ƒ j ƒ  } t |  | | ƒ } | j } | t | | ƒ ƒ | } |  d  }	 x. | rP| | d @r<t n |	 ƒ | d L} q#W| j ƒ  }
 |  |  } |  | } |  | | | |  | |  | | g } g  t D]  \ } } | | | | f ^ qœ} |
 } d } xQ | r!x: | D]2 \ } } t | t | | ƒ j ƒ  ƒ j ƒ  } qÞW| d 8} qÑWx> | d	  D]2 \ } } t | t | | ƒ j ƒ  ƒ j ƒ  } q-Wt j | t ƒ j d ƒ S(
   s†  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
    s   utf-8s   pwd not unicode or bytess   salt not unicodet   asciii	   s   salt too largei   i   i   (   t
   isinstanceR   t   encodet   bytest   AssertionErrort   _BNULLt   uht   exct   NullPasswordErrorR   t   lent
   _APR_MAGICt
   _MD5_MAGICR    t   digestt   updateR   t   _c_digest_offsetsR   t   encode_transposed_bytest   _transpose_mapt   decode(   t   pwdt   saltt   use_aprt   pwd_lent   magict   dbt   a_ctxt   a_ctx_updatet   it   evenchart   dat   pwd_pwdt   pwd_saltt   permst   event   oddt   datat   dct   blocks(    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyt   _raw_md5_crypt,   sF    		
	.

$-	**t   _MD5_Commonc           B   sJ   e  Z d  Z d Z d Z e j Z d Z e j Z	 e
 d „  ƒ Z d „  Z RS(   s+   common code for md5_crypt and apr_md5_cryptR   t	   salt_sizei   i   c         C   s4   t  j | |  j d |  ƒ\ } } |  d | d | ƒ S(   Nt   handlerR   t   checksum(   R   t	   parse_mc2t   ident(   t   clst   hashR   t   chk(    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyt   from_stringÒ   s    !c         C   s   t  j |  j |  j |  j ƒ S(   N(   R   t
   render_mc2R4   R   R2   (   t   self(    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyt	   to_string×   s    (   R   R0   (   t   __name__t
   __module__t   __doc__t   setting_kwdst   checksum_sizeR   t   HASH64_CHARSt   checksum_charst   max_salt_sizet
   salt_charst   classmethodR8   R;   (    (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyR/   À   s   		c           B   sV   e  Z d  Z d Z e d ƒ Z d	 Z e d „  ƒ Z d „  Z	 e d „  ƒ Z
 d „  Z RS(
   s•  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
    R   s   $1$t   os_cryptt   builtinc         C   s+   t  d d ƒ r# |  j |  j ƒ t St Sd  S(   Nt   tests   $1$test$pi/xDtU5WFVRqYS6BMU8X/(   R   t   _set_calc_checksum_backendt   _calc_checksum_os_cryptt   Truet   False(   R5   (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyt   _load_backend_os_crypt  s    c         C   s‡   |  j  |  j } t | | ƒ } | d  k r8 |  j | ƒ S| j | ƒ sd t | ƒ t | ƒ d k r t j j	 |  | | ƒ ‚ n  | d S(   Ni   iêÿÿÿ(
   R4   R   R   t   Nonet   _calc_checksum_builtint
   startswithR   R   R   t   CryptBackendError(   R:   t   secrett   configR6   (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyRJ     s    ,c         C   s   |  j  |  j ƒ t S(   N(   RI   RO   RK   (   R5   (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyt   _load_backend_builtin%  s    c         C   s   t  | |  j ƒ S(   N(   R.   R   (   R:   RR   (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyRO   *  s    (   RF   RG   (   R<   R=   R>   t   nameR   R4   t   backendsRE   RM   RJ   RT   RO   (    (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyR   à   s   	c           B   s)   e  Z d  Z d Z e d ƒ Z d „  Z RS(   sp  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
    R   s   $apr1$c         C   s   t  | |  j d t ƒS(   NR   (   R.   R   RK   (   R:   RR   (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyt   _calc_checksumQ  s    (   R<   R=   R>   RU   R   R4   RW   (    (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyR   1  s   (   i    i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i    (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   i    i   i   i   i   i   i   i   i	   i   i   i
   i   i   ("   R>   t   hashlibR    t   loggingt	   getLoggerR<   t   logt   passlib.utilsR   R   R   t   passlib.utils.binaryR   t   passlib.utils.compatR   R   t   passlib.utils.handlerst   utilst   handlersR   t   __all__R   R   R   R   R   RL   R.   t   HasSaltt   GenericHandlerR/   t   HasManyBackendsR   R   (    (    (    sU   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/handlers/md5_crypt.pyt   <module>   s(    	” Q