%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/passlib/handlers/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/passlib/handlers/__pycache__/scrypt.cpython-39.pyc

a

f�WcB7�	@s�dZddlmZmZddlZe�e�Zddlm	Z
ddlmZm
Z
ddlmZmZmZddlmZmZmZddlmZddlmmZd	gZed
�Zed�Zed�ZGd
d	�d	ejej ej!ej"ej#ej$�Z	dS)z/passlib.handlers.scrypt -- scrypt password hash�)�with_statement�absolute_importN)�scrypt)�h64�to_bytes)r�b64s_decode�b64s_encode)�u�
bascii_to_str�suppress_cause)�
classpropertyrz$scrypt$z$7$�$cseZdZdZdZdZdZeZee	fZ
dZdZdZ
dZdZdZdZd	Zed+�fdd�	�Zed
d��Zedd��Zedd��Zedd��Zdd�Zd,�fdd�	Zed-dd��Z�fdd�Zedd��Zed d!��Zed.d#d$��Z ed/d%d&��Z!d'd(�Z"�fd)d*�Z#�Z$S)0ra�	This class implements an SCrypt-based password [#scrypt-home]_ hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, a variable number of rounds,
    as well as some custom tuning parameters unique to scrypt (see below).

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

    :type salt: str
    :param salt:
        Optional salt string.
        If specified, the length must be between 0-1024 bytes.
        If not specified, one will be auto-generated (this is recommended).

    :type salt_size: int
    :param salt_size:
        Optional number of bytes to use when autogenerating new salts.
        Defaults to 16 bytes, but can be any value between 0 and 1024.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 16, but must be within ``range(1,32)``.

        .. warning::

            Unlike many hash algorithms, increasing the rounds value
            will increase both the time *and memory* required to hash a password.

    :type block_size: int
    :param block_size:
        Optional block size to pass to scrypt hash function (the ``r`` parameter).
        Useful for tuning scrypt to optimal performance for your CPU architecture.
        Defaults to 8.

    :type parallelism: int
    :param parallelism:
        Optional parallelism to pass to scrypt hash function (the ``p`` parameter).
        Defaults to 1.

    :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.

    .. note::

        The underlying scrypt hash function has a number of limitations
        on it's parameter values, which forbids certain combinations of settings.
        The requirements are:

        * ``linear_rounds = 2**<some positive integer>``
        * ``linear_rounds < 2**(16 * block_size)``
        * ``block_size * parallelism <= 2**30-1``

    .. todo::

        This class currently does not support configuring default values
        for ``block_size`` or ``parallelism`` via a :class:`~passlib.context.CryptContext`
        configuration.
    )�ident�saltZ	salt_size�rounds�
block_size�parallelism� �i��Zlog2�Nc
s�tt|�jfi|��}|durHt|tj�r2t|�}|j||�d�d�|_	zt
�d|j>|j	|j
�Wn8ty�}z ttdt|����WYd}~n
d}~00|S)N�relaxed)rrz&scrypt: invalid settings combination: )�superr�using�
isinstance�uhZnative_string_types�int�_norm_block_size�getr�_scryptZvalidate�default_roundsr�
ValueErrorr�str)�clsr�kwds�subcls�err��	__class__��;/usr/lib/python3.9/site-packages/passlib/handlers/scrypt.pyr�s*zscrypt.usingcCs|fi|�|���S�N)�parse)r$�hashr*r*r+�from_string�szscrypt.from_stringcCs@|�|�\}}t|d|�t�d�}|r0||�Stj�|��dS)Nz_parse_%s_string)Z_parse_ident�getattr�strip�_UDOLLARr�excZInvalidHashError)r$r.r�suffix�funcr*r*r+r-�s
zscrypt.parsec	
Cs�|�d�}t|�dkr"|\}}}n(t|�dkr<|\}}d}ntj�|d��|�d�}t|�dkr�|\}}}|�d�sxJ�|�d�s�J�|�d�s�J�ntj�|d	��ttt|dd��t|dd��t|dd��t	|�
d
��|r�t	|�
d
��ndd�S)Nr
��zmalformed hash�,zln=zr=zp=zmalformed settings field�ascii�rrrrr�checksum)�split�lenrr3�MalformedHashError�
startswith�dict�IDENT_SCRYPTrr�encode)	r$r4�parts�paramsr�digestZnstrZbstrZpstrr*r*r+�_parse_scrypt_string�s,


�zscrypt._parse_scrypt_stringc	Cs�|�d��d�}t|�dkr&|\}}n"t|�dkr>|\}d}n
tj���t|�dkrbtj�|d��ttt�	|dd��t�
|dd��t�
|dd��|dd�|r�t�|�ndd�S)	Nr9�$r7r�zparams field too short�r:)rBr<r=rr3r>r@�IDENT_7rZdecode_int6Zdecode_int30Zdecode_bytes)r$r4rCrDrEr*r*r+�_parse_7_string�s"


�zscrypt._parse_7_stringcCs�|j}|tkr:d|j|j|jtt|j��tt|j��fS|t	ksFJ�|j}z|�
d�Wntyxtt
d���Yn0td�dt�|j�t�|j�t�|j�|jdt�|j�g��SdS)Nz$scrypt$ln=%d,r=%d,p=%d$%s$%sr9z.scrypt $7$ hashes dont support non-ascii salts�s$7$rG)rrArrrr
rrr;rJ�decode�UnicodeDecodeErrorr�NotImplementedError�joinrZencode_int6Zencode_int30Zencode_bytes)�selfrrr*r*r+�	to_strings0�



�zscrypt.to_stringcsJtt|�jfi|��|dur:tj||j|jdd�sFJ�n|�|�|_dS)Nr��param)rr�__init__rZvalidate_default_valuerr)rQrr%r(r*r+rU1s�zscrypt.__init__FcCstj||dd|d�S)Nrr)�minrTr)rZnorm_integer)r$rrr*r*r+r>szscrypt._norm_block_sizecs$tt|���}|jtkr t|�}|Sr,)rr�_generate_saltrrJr)rQrr(r*r+rWBs
zscrypt._generate_saltcCstjSr,)r Zbackend_values�r$r*r*r+�backendsPszscrypt.backendscCstjSr,)r ZbackendrXr*r*r+�get_backendTszscrypt.get_backend�anycCs2z|j|dd�WdStjjy,YdS0dS)NT��dryrunF)�set_backendrr3ZMissingBackendError)r$�namer*r*r+�has_backendXs
zscrypt.has_backendcCstj||d�dS)Nr\)r Z_set_backend)r$r_r]r*r*r+r^`szscrypt.set_backendcCs0t|dd�}tj||jd|j>|j|j|jd�S)N�secretrSr)�n�r�pZkeylen)rr rrrrr�
checksum_size)rQrar*r*r+�_calc_checksumgs�zscrypt._calc_checksumcs*|jt|�jkrdStt|�jfi|��S)zR
        mark hash as needing update if rounds is outside desired bounds.
        T)r�typerr�_calc_needs_update)rQr%r(r*r+rhpszscrypt._calc_needs_update)N)N)F)r[)r[F)%�__name__�
__module__�__qualname__�__doc__r_Zsetting_kwdsrerAZ
default_identrJZident_valuesZdefault_salt_sizeZ
max_salt_sizer!Z
min_roundsZ
max_roundsZrounds_costrr�classmethodrr/r-rFrKrRrUrrWrrYrZr`r^rfrh�
__classcell__r*r*r(r+r!sNG		


-



	)%rlZ
__future__rrZloggingZ	getLoggerri�logZpasslib.cryptorr Z
passlib.utilsrrZpasslib.utils.binaryrrZpasslib.utils.compatr	r
rZpasslib.utils.decorrZpasslib.utils.handlersZutils�handlersr�__all__rArJr2ZParallelismMixinZ	HasRoundsZ
HasRawSaltZHasRawChecksumZ
HasManyIdentsZGenericHandlerr*r*r*r+�<module>s ��

Zerion Mini Shell 1.0