
    XR_                         d Z ddlmZ ddlZ ej        e          ZddlmZ ddl	m
Z
mZmZ ddlmc mZ dgZ G d dej        ej        ej        ej                  ZdS )zpasslib.handlers.phpass - PHPass Portable Crypt

phppass located - http://www.openwall.com/phpass/
algorithm described - http://www.openwall.com/articles/PHP-Users-Passwords

phpass context - blowfish, bsdi_crypt, phpass
    )md5N)h64)uuascii_to_strunicodephpassc                      e Zd ZdZd ZdZej        ZdxZ	Z
ej        ZdZdZdZdZ ed          Z ed           ed	          fZ ed
           ed           ed           ed	          iZed             Zd Zd ZdS )r   a  This class implements the PHPass Portable Hash, and follows the :ref:`password-hash-api`.

    It supports a fixed-length salt, and a variable number of rounds.

    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 8 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 19, must be between 7 and 30, inclusive.
        This value is logarithmic, the actual number of iterations used will be :samp:`2**{rounds}`.

    :type ident: str
    :param ident:
        phpBB3 uses ``H`` instead of ``P`` for its identifier,
        this may be set to ``H`` in order to generate phpBB3 compatible hashes.
        it defaults to ``P``.

    :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 ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    )saltroundsident            log2z$P$z$H$PHc                     |                      |          \  }}|d         |dd         |dd          }}} | |t          j        |                    d                    ||pd           S )Nr      	   ascii)r   r   r
   checksum)_parse_identr   decode_int6encode)clshashr   datar   r
   chks          9/usr/lib/python3/dist-packages/passlib/handlers/phpass.pyfrom_stringzphpass.from_string`   sy    &&t,,t GT!A#YQRRcs?6==#9#9::[D	
 
 
 	
    c                     t          d          | j        t          j        | j                                      d          | j        | j        pt          d          fz  }t          |          S )Nz%s%s%s%sr    )	r   r   r   encode_int6r   decoder
   r   r   )selfr   s     r    	to_stringzphpass.to_stringk   s]    }}
!odk::AA'JJ"i"m4quu 6 6 T"""r"   c                    t          |t                    r|                    d          }d| j        z  }t	          | j                            d          |z                                             }d}||k     r/t	          ||z                                             }|dz  }||k     /t          j        |          	                    d          S )Nzutf-8r   r   r   )

isinstancer   r   r   r   r
   digestr   encode_bytesr&   )r'   secretreal_roundsresultrs        r    _calc_checksumzphpass._calc_checksumu   s    fg&& 	,]]7++FnTY%%g..788??AA+oo&))0022FFA +oo ''..w777r"   N)__name__
__module____qualname____doc__namesetting_kwdsuhHASH64_CHARSchecksum_charsmin_salt_sizemax_salt_size
salt_charsdefault_rounds
min_rounds
max_roundsrounds_costr   default_identident_valuesident_aliasesclassmethodr!   r(   r1    r"   r    r   r      s        ! !N D.L_N %&%MMJ NJJK AeHHMAeHHaahh'LQsVVAAeHHaaffQQuXX6M 
 
 [
# # #
8 
8 
8 
8 
8r"   )r5   hashlibr   logging	getLoggerr2   logpasslib.utils.binaryr   passlib.utils.compatr   r   r   passlib.utils.handlersutilshandlersr8   __all__HasManyIdents	HasRoundsHasSaltGenericHandlerr   rF   r"   r    <module>rU      s           'g'11 % $ $ $ $ $ : : : : : : : : : : # # # # # # # # # d8 d8 d8 d8 d8Rr|RZ9J d8 d8 d8 d8 d8r"   