%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__/argon2.cpython-39.pyc

a

f�Wc��	@s�dZddlmZmZddlZe�e�ZddlZddl	Z	ddl
mZdZda
ddlmZddlmZddlmZmZmZddlmZmZdd	lmZmZmZmZmZddlm m!Z"d
gZ#ed�Z$ed�Z%ed
�Z&e&e$e%fZ'e(e'�Z)dZ*zddl+ZWne,�ydZYn,0e-ed��s$dZ*dZne-ed��s8dZ*dZe-ed��rVe�.�Z/ej0j1Z2nGdd�d�Z3e3�Z/dZ2Gdd�de"j4e"j5e"j6e"j7e"j8e"j9�Z:Gdd�de:�Z;Gdd�de:�Z<Gdd�de:�Z=Gdd
�d
e;e:�Z+dS)a�passlib.handlers.argon2 -- argon2 password hash wrapper

References
==========
* argon2
    - home: https://github.com/P-H-C/phc-winner-argon2
    - whitepaper: https://github.com/P-H-C/phc-winner-argon2/blob/master/argon2-specs.pdf
* argon2 cffi wrapper
    - pypi: https://pypi.python.org/pypi/argon2_cffi
    - home: https://github.com/hynek/argon2_cffi
* argon2 pure python
    - pypi: https://pypi.python.org/pypi/argon2pure
    - home: https://github.com/bwesterb/argon2pure
�)�with_statement�absolute_importN)�warn)�exc)�
MAX_UINT32)�
classproperty�to_bytes�render_bytes)�b64s_encode�b64s_decode)�u�unicode�
bascii_to_str�
uascii_to_str�PY2�argon2�i�d�id�Typezb'argon2' module points to unsupported 'argon2' pypi package; please install 'argon2-cffi' instead.�	low_levelz@'argon2-cffi' is too old, please update to argon2_cffi >= 18.2.0�PasswordHasherc@s$eZdZdZdZdZdZdZdZdS)�_DummyCffiHashera
        dummy object to use as source of defaults when argon2_cffi isn't present.
        this tries to mimic the attributes of ``argon2.PasswordHasher()`` which the rest of
        this module reads.

        .. note:: values last synced w/ argon2 19.2 as of 2019-11-09
        �i�N)	�__name__�
__module__�__qualname__�__doc__�	time_cost�memory_cost�parallelism�salt_len�hash_len�r$r$�;/usr/lib/python3.9/site-packages/passlib/handlers/argon2.pyr]sr�c	sfeZdZdZdZdZejZe	j
jdZe	j
jdZej
ZdZeZejZdZeZdZd	ZeZd
ZdZdZdZiZed
d��Z e!Z"ej#Z#eZ$ej%Z%e&dd��Z'd
Z(e)d.�fdd�	�Z*e)dd��Z+e,�-d�Z.e)dd��Z/e,�-de,j0�Z1e)dd��Z2dd�Z3d/�fdd�	Z4e)dd ��Z5e)d!d"��Z6e)d0d#d$��Z7e)d%d&��Z8�fd'd(�Z9d)Z:e)d*d+��Z;e)d1d,d-��Z<�Z=S)2�
_Argon2Commona&
    Base class which implements brunt of Argon2 code.
    This is then subclassed by the various backends,
    to override w/ backend-specific methods.

    When a backend is loaded, the bases of the 'argon2' class proper
    are modified to prepend the correct backend-specific subclass.
    r)
�salt�	salt_sizer"�roundsrr r!�digest_sizer#�type)r,)r"rr#r+��Zlineari���N���FcCs|��t|j�S)zj
        return tuple of types supported by this backend
        
        .. versionadded:: 1.7.2
        )�get_backend�tuple�_backend_type_map)�clsr$r$r%�type_values�sz_Argon2Common.type_valuescCs
|jtkS)zn
        flag indicating a Type D hash

        .. deprecated:: 1.7.2; will be removed in passlib 2.0
        )r,�TYPE_D��selfr$r$r%�type_d�sz_Argon2Common.type_dc	sj|dur d|	vrtd��||	d<|dur@d|	vr8td��||	d<|dur\|durXtd��|}|durx|durttd��|}tt|�jfi|	��}
|dur�|
�|�|
_|	�d�}|dur�t|tj	�r�t
|�}tj|
|dtd	|d
�|
_
|du�rt|tj	�r�t
|�}|
j||d�|
_|
�|
j|
j�|du�rft|tj	��r>t
|�}|dk�r`|d
k�r`td|f��||
_|
S)Nr*z/'time_cost' and 'rounds' are mutually exclusiver)z1'salt_len' and 'salt_size' are mutually exclusivez3'hash_len' and 'digest_size' are mutually exclusivez8'checksum_size' and 'digest_size' are mutually exclusive�relaxedrr+)�min�max�paramr9)r9r.r/z7max_threads (%d) must be -1 (unlimited), or at least 1.)�	TypeError�superr'�using�
_norm_typer,�get�
isinstance�uhZnative_string_types�int�norm_integerr�
checksum_size�_norm_memory_costr �_validate_constraintsr!�
ValueError�max_threads)r3r,r r"rr+rFr#rJ�kwds�subclsr9��	__class__r$r%r?sP
�

�z_Argon2Common.usingcCs*d|}||kr&td|j|||f��dS)Nr-zO%s: memory_cost (%d) is too low, must be at least 8 * parallelism (8 * %d = %d))rI�name)r3r r!�min_memory_costr$r$r%rHBs��z#_Argon2Common._validate_constraintsz^\$argon2[a-z]+\$cCst�|�}|j�|�duS�N)rCZto_unicode_for_identify�_ident_regex�match)r3�hashr$r$r%�identifyTs
z_Argon2Common.identifys�
        ^
        \$argon2(?P<type>[a-z]+)\$
        (?:
            v=(?P<version>\d+)
            \$
        )?
        m=(?P<memory_cost>\d+)
        ,
        t=(?P<time_cost>\d+)
        ,
        p=(?P<parallelism>\d+)
        (?:
            ,keyid=(?P<keyid>[^,$]+)
        )?
        (?:
            ,data=(?P<data>[^,$]+)
        )?
        (?:
            \$
            (?P<salt>[^$]+)
            (?:
                \$
                (?P<digest>.+)
            )?
        )?
        $
    cCs�t|t�r|�d�}t|t�s*t�|d��|j�|�}|sDt�|��|�	ddddddd	d
d�	\	}}}}}}}	}
}|r|t
d��||�d
�|r�t|�ndt|�t|�t|�|
r�t
|
�nd|	r�t
|	�nd|r�t
|�ndd�S)N�utf-8rTr,�versionr rr!�keyid�datar(�digestz&argon2 'keyid' parameter not supported�asciir)r,rWr r*r!r(rY�checksum)rBr
�encode�bytesrZExpectedStringError�_hash_regexrS�MalformedHashError�group�NotImplementedError�decoderDr)r3rT�mr,rWr rr!rXrYr(rZr$r$r%�from_string�s.



���z_Argon2Common.from_stringcCsv|j}|dkrd}nd|}|j}|r:dtt|j��}nd}dt|j�||j|j|j|tt|j	��tt|j
��fS)Nr�zv=%d$z,data=z"$argon2%s$%sm=%d,t=%d,p=%d%s$%s$%s)rWrYrr
rr,r r*r!r(r\)r7rWZvstrrYZkdstrr$r$r%�	to_string�s$�z_Argon2Common.to_stringcs|rtd�|dusJ�t}|�d�}|dur8t|�|_tt|�jfi|��|durrtj	||j
|jdd�s~J�n|�|�|_
|dur�tj	||j|j
dd�s�J�n|�
|�|_|dur�tj	||j|jdd�s�J�n|�|�|_|dur�|jdus�J�n"t|t��stj�|dd��||_dS)	Nzoargon2 `type_d=True` keyword is deprecated, and will be removed in passlib 2.0; please use ``type="d"`` insteadr\r,)r<rWr r^rY)rr5rA�lenrFr>r'�__init__rCZvalidate_default_valuer,r@rW�
_norm_versionr rGrYrBr^r�ExpectedTypeError)r7r,r8rWr rYrKr\rMr$r%ri�s4

��z_Argon2Common.__init__cCsft|t�s4tr$t|t�r$|�d�}ntj�|dd��|tvr@|S|�	�}|tvrT|St
d|f��dS)Nr[�strr,zunknown argon2 hash type: %r)rBr
rr^rcrCrrk�
ALL_TYPES_SET�lowerrI)r3�valueZtempr$r$r%r@�s
z_Argon2Common._norm_typecCsht|tj�stj�|dd��|dkr:|dkr:td|f��|��}||jkrdtd|j|||jf��|S)NZintegerrWr&rzinvalid argon2 hash version: %dzk%s: hash version 0x%X not supported by %r backend (max version is 0x%X); try updating or switching backends)	rBrCZ	int_typesrrkrIr0�max_versionrO)r3rW�backendr$r$r%rj	s
�z_Argon2Common._norm_versioncCstj|||jd|d�S)Nr )r:r<r9)rCrErP)r3r r9r$r$r%rGs�z_Argon2Common._norm_memory_costcCs<z|j|WStyYn0d||��f}t|��dS)z>
        helper to resolve backend constant from type
        z=unsupported argon2 hash (type %r not supported by %s backend)N)r2�KeyErrorr0rI)r3ro�msgr$r$r%�_get_backend_type%s
�z_Argon2Common._get_backend_typecszt|�}|j|jkrdS|j}|dus0||jkr6|j}|j|krDdS|j|jkrTdS|j|jkrddStt|�jfi|��S)NT)	r,�min_desired_versionrprWr rFr>r'�_calc_needs_update)r7rKr3ZminverrMr$r%rv7s
z _Argon2Common._calc_needs_updatez> -- recommend you install one (e.g. 'pip install argon2_cffi')cCsp|j}t|t�r|dksJ�|dkr6td|tjj�tD]}||jvr:||_	qlq:td|tjj
�t|_	dS)z�
        helper called by from backend mixin classes' _load_backend_mixin() --
        invoked after backend imports have been loaded, and performs
        feature detection & testing common to all backends.
        rr&z6%r doesn't support argon2 v1.3, and should be upgradedz)%r lacks support for all known hash typesT)rprBrDrrCr�PasslibSecurityWarning�	ALL_TYPESr2r,ZPasslibRuntimeWarning�TYPE_ID)�	mixin_clsrO�dryrunrpr,r$r$r%�_finalize_backend_mixinMs�
z%_Argon2Common._finalize_backend_mixincCs�|��}|dur"|dur"|�|�}|durT|�|j|j�|dkrT|jdurTtd��t|�}|dvrtd|||f}nt|�}t	j
||d��dS)z}
        internal helper invoked when backend has hash/verification error;
        used to adapt to passlib message.
        N�argon2_cffiz8argon2_cffi backend doesn't support the 'data' parameter)zDecoding failedz%s reported: %s: hash=%r)�reason)r0rerHr r!rYrbrl�reprrr`)r3�errrTr7rq�textr~r$r$r%�_adapt_backend_errorgs
z"_Argon2Common._adapt_backend_error)NNNNNNNN)NFNNN)F)NN)>rrrrrOZsetting_kwds�_default_settingsr#rFrC�GenericHandlerZ_always_parse_settingsZ_unparsed_settingsr"Zdefault_salt_sizeZ
min_salt_sizerZ
max_salt_sizer�default_roundsZ
min_roundsZ
max_roundsZrounds_costZmax_parallelism�_default_versionrprurPrJ�pure_use_threadsr2rr4ryr,r!rWr �propertyr8rY�classmethodr?rH�re�compilerRrU�Xr_rergrir@rjrGrtrvZ_no_backend_suggestionr|r��
__classcell__r$r$rMr%r'ss~��

	�;


�
2




r'csReZdZdZedd��Zedd��Zejddd�ed	d
���Z	�fdd�Z
�ZS)
�
_NoBackendz�
    mixin used before any backend has been loaded.
    contains stubs that force loading of one of the available backends.
    cCs|��|�|�SrQ)�_stub_requires_backendrT)r3�secretr$r$r%rT�sz_NoBackend.hashcCs|��|�||�SrQ)r��verify)r3r�rTr$r$r%r��sz_NoBackend.verifyz1.7z2.0)Z
deprecatedZremovedcCs|��|�||�SrQ)r��genhash)r3r��configr$r$r%r��sz_NoBackend.genhashcs|��tt|��|�SrQ)r�r>r�_calc_checksum�r7r�rMr$r%r��sz_NoBackend._calc_checksum)rrrrr�rTr�rCZdeprecated_methodr�r�r�r$r$rMr%r��s

r�c@sZeZdZdZedd��Zedd��Zedd�eD��Z	edd	��Z
ed
d��Zdd
�ZdS)�_CffiBackendz
    argon2_cffi backend
    c	Cs�|tusJ�tdur&tr"t�t��dStjj}t�dtj	|�tj
}i}tD]F}zt||�
��||<WqLty�|ttfvs�Jd|��YqL0qL||_||_|_|�||�S)NFzOdetected 'argon2_cffi' backend, version %r, with support for 0x%x argon2 hashes�unexpected missing type: %r)r��_argon2_cffi�_argon2_cffi_errorrZPasslibSecurityErrorr�ARGON2_VERSION�log�debug�__version__rrx�getattr�upper�AttributeError�TYPE_Ir5r2rWrpr|)rzrOr{rpZTypeEnum�type_mapr,r$r$r%�_load_backend_mixin�s&
� z _CffiBackend._load_backend_mixinc
Cs�t�|�t|d�}z8ttjj|�|j�|j	|j
|jt|���|j
|d��WStjjy~}z|�|��WYd}~n
d}~00dS)NrV)r,r rr!r(r#r�)rC�validate_secretrrr�r�hash_secretrtr,r r�r!Z_generate_saltrF�
exceptions�HashingErrorr�)r3r�r�r$r$r%rT�s



�
	z_CffiBackend.hashccs"|]}td|�d��|fVqdS)s
$argon2%s$r[N)r	r])�.0r,r$r$r%�	<genexpr>�s�z_CffiBackend.<genexpr>c
Cs�t�|�t|d�}t|d�}|j�|dd|�dd��t�}|�|�}z"tj	�
|||�}|dushJ�WdStjjy�YdStjj
y�}z|j||d��WYd}~n
d}~00dS)NrVr[r.�$TF�rT)rCr�r�_byte_ident_maprA�findr�rtr�rZ
verify_secretr�ZVerifyMismatchErrorZVerificationErrorr�)r3r�rTr,�	type_code�resultr�r$r$r%r��s


"
z_CffiBackend.verifycCs�t�|�t|d�}|�|�}z<ttjj|�|j	�|j
|j|jt|j
�|j||jd��}Wn6tjjy�}z|j||d��WYd}~n
d}~00|jdkr�|�dd�}|S)NrV)r,r rr!r(r#r�rWr�rz$v=16$�$)rCr�rrerr�rr�rtr,r r*r!r(rFrWr�r�r��replace)r3r�r�r7r�r�r$r$r%r�s&



�
$
z_CffiBackend.genhashcCstd��dS)Nz-shouldn't be called under argon2_cffi backend)�AssertionErrorr�r$r$r%r�*sz_CffiBackend._calc_checksumN)
rrrrr�r�rT�dictrxr�r�r�r�r$r$r$r%r��s

�

r�c@s$eZdZdZedd��Zdd�ZdS)�_PureBackendz
    argon2pure backend
    c	Cs�|tusJ�zddlaWnty,YdS0zddlm}Wnty\t�d�YdS0t�d|�|sztdt	j
�i}tD]J}zttd|�
��||<Wq�ty�|ttfvs�Jd|��Yq�0q�||_||_|_|�||�S)	NrF)�ARGON2_DEFAULT_VERSIONz\detected 'argon2pure' backend, but package is too old (passlib requires argon2pure >= 1.2.3)zBdetected 'argon2pure' backend, with support for 0x%x argon2 hashesz�Using argon2pure backend, which is 100x+ slower than is required for adequate security. Installing argon2_cffi (via 'pip install argon2_cffi') is strongly recommendedZARGON2r�)r��
argon2pure�_argon2pure�ImportErrorr�r�Zwarningr�rrrwrxr�r�r�r�r5r2rWrpr|)rzrOr{rpr�r,r$r$r%r�<s4
�� z _PureBackend._load_backend_mixinc
Cs�t�|�t|d�}t||j|j|j|j|j|�	|j
�|jd�}|jdkrT|j|d<|j
rbd|d<|jrr|j|d<ztjfi|��WStjy�}z|j||d��WYd}~n
d}~00dS)	NrV)�passwordr(rr r!Z
tag_lengthr�rWr�threadsTZuse_threadsZassociated_datar6)rCr�rr�r(r*r r!rFrtr,rWrJr�rYr�rZArgon2Errorr�)r7r�rKr�r$r$r%r�ns,


�



z_PureBackend._calc_checksumN)rrrrr�r�r�r$r$r$r%r�4s
1r�c@s$eZdZdZdZdZeeed�Z	dS)ra�	
    This class implements the Argon2 password hash [#argon2-home]_, and follows the :ref:`password-hash-api`.

    Argon2 supports a variable-length salt, and variable time & memory cost,
    and a number of other configurable parameters.

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

    :type type: str
    :param type:
        Specify the type of argon2 hash to generate.
        Can be one of "ID", "I", "D".

        This defaults to "ID" if supported by the backend, otherwise "I".

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

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        This corresponds linearly to the amount of time hashing will take.

    :type time_cost: int
    :param time_cost:
        An alias for **rounds**, for compatibility with underlying argon2 library.

    :param int memory_cost:
        Defines the memory usage in kibibytes.
        This corresponds linearly to the amount of memory hashing will take.

    :param int parallelism:
        Defines the parallelization factor.
        *NOTE: this will affect the resulting hash value.*

    :param int digest_size:
        Length of the digest in bytes.

    :param int max_threads:
        Maximum number of threads that will be used.
        -1 means unlimited; otherwise hashing will use ``min(parallelism, max_threads)`` threads.

        .. note::

            This option is currently only honored by the argon2pure backend.

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

    .. versionchanged:: 1.7.2

        Added the "type" keyword, and support for type "D" and "ID" hashes.
        (Prior versions could verify type "D" hashes, but not generate them).

    .. todo::

        * Support configurable threading limits.
    )r}r�T)Nr}r�N)
rrrrZbackendsZ_backend_mixin_targetr�r�r�Z_backend_mixin_mapr$r$r$r%r�sP�)>rZ
__future__rrZloggingZ	getLoggerrr�r��types�warningsrr�r�ZpasslibrZpasslib.crypto.digestrZ
passlib.utilsrrr	Zpasslib.utils.binaryr
rZpasslib.utils.compatrr
rrrZpasslib.utils.handlersZutils�handlersrC�__all__r�r5ryrx�setrmr�rr��hasattrrr�rr�r�rZSubclassBackendMixinZParallelismMixinZ	HasRoundsZ
HasRawSaltZHasRawChecksumr�r'r�r�r�r$r$r$r%�<module>sf
�
	
�
�*|Z

Zerion Mini Shell 1.0