Ë
    3ýj‡"  ã                  ó  — d dl mZ d dlZd dlmZmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZmZ ddlmZ  e«       Zej(                  Zej,                  Zej0                  Zej4                  Zej8                  Zdd	„Z G d
„ d«      Zy)é    )ÚannotationsN)ÚClassVarÚLiteralé   )Ú
ParametersÚ_check_typesÚextract_parametersÚvalidate_params_for_platform)ÚInvalidHashError)ÚTypeÚhash_secretÚverify_secret)Úget_default_parametersc                óH   — t        | t        «      r| S | j                  |«      S )zM
    Ensure *s* is a bytes string.  Encode using *encoding* if it isn't.
    )Ú
isinstanceÚbytesÚencode)ÚsÚencodings     úQ/root/telegram-saas/.venv/lib/python3.12/site-packages/argon2/_password_hasher.pyÚ_ensure_bytesr      s"   € ô �!”UÔØˆØ�8‰8�HÓÐó    c                  ón  — e Zd ZU dZddgZded<   ded<   eeee	e
dej                  f	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zedd„«       Zedd	„«       Zedd
„«       Zedd„«       Zedd„«       Zedd„«       Zedd„«       Zddœdd„Zej0                  ej2                  ej                  dœZded<   	 	 	 	 	 	 dd„Zdd„Zy)ÚPasswordHashera¯  
    High level class to hash passwords with sensible defaults.

    Uses Argon2\ **id** by default and uses a random salt_ for hashing. But it
    can verify any type of Argon2 as long as the hash is correctly encoded.

    The reason for this being a class is both for convenience to carry
    parameters and to verify the parameters only *once*.  Any unnecessary
    slowdown when hashing is a tangible advantage for a brute-force attacker.

    Args:
        time_cost:
            Defines the amount of computation realized and therefore the
            execution time, given in number of iterations.

        memory_cost: Defines the memory usage, given in kibibytes_.

        parallelism:
            Defines the number of parallel threads (*changes* the resulting
            hash value).

        hash_len: Length of the hash in bytes.

        salt_len: Length of random salt to be generated for each password.

        encoding:
            The Argon2 C library expects bytes.  So if :meth:`hash` or
            :meth:`verify` are passed a ``str``, it will be encoded using this
            encoding.

        type:
            Argon2 type to use.  Only change for interoperability with legacy
            systems.

    .. versionadded:: 16.0.0
    .. versionchanged:: 18.2.0
       Switch from Argon2i to Argon2id based on the recommendation by the
       current RFC draft. See also :doc:`parameters`.
    .. versionchanged:: 18.2.0
       Changed default *memory_cost* to 100 MiB and default *parallelism* to 8.
    .. versionchanged:: 18.2.0 ``verify`` now will determine the type of hash.
    .. versionchanged:: 18.3.0 The Argon2 type is configurable now.
    .. versionadded:: 21.2.0 :meth:`from_parameters`
    .. versionchanged:: 21.2.0
       Changed defaults to :data:`argon2.profiles.RFC_9106_LOW_MEMORY`.

    .. _salt: https://en.wikipedia.org/wiki/Salt_(cryptography)
    .. _kibibytes: https://en.wikipedia.org/wiki/Binary_prefix#kibi
    Ú_parametersr   r   Ústrzutf-8c           
     óì   — t        |t        f|t        f|t        f|t        f|t        f|t        f|t        f¬«      }|rt	        |«      ‚t        |d|||||¬«      }	t        |	«       |	| _        || _        y )N)Ú	time_costÚmemory_costÚparallelismÚhash_lenÚsalt_lenr   Útypeé   )r#   Úversionr"   r!   r   r   r    )	r   Úintr   r   Ú	TypeErrorr   r
   r   r   )
Úselfr   r   r    r!   r"   r   r#   ÚeÚparamss
             r   Ú__init__zPasswordHasher.__init__^   s‹   € ô Ø ¤#Ð&Ø$¤cÐ*Ø$¤cÐ*Ø¤�_Ø¤�_Ø¤�_Øœ�ô
ˆñ Ü˜A“,ÐäØØØØØØ#Ø#ô
ˆô 	% VÔ,ð "ˆÔØ ˆ�r   c                ó–   —  | |j                   |j                  |j                  |j                  |j                  |j
                  ¬«      S )z¼
        Construct a `PasswordHasher` from *params*.

        Returns:
            A `PasswordHasher` instance with the parameters from *params*.

        .. versionadded:: 21.2.0
        ©r   r   r    r!   r"   r#   r-   )Úclsr*   s     r   Úfrom_parameterszPasswordHasher.from_parameters„   sA   € ñ Ø×&Ñ&Ø×*Ñ*Ø×*Ñ*Ø—_‘_Ø—_‘_Ø—‘ô
ð 	
r   c                ó.   — | j                   j                  S ©N)r   r   ©r(   s    r   r   zPasswordHasher.time_cost˜   s   € à×Ñ×)Ñ)Ð)r   c                ó.   — | j                   j                  S r1   )r   r   r2   s    r   r   zPasswordHasher.memory_costœ   ó   € à×Ñ×+Ñ+Ð+r   c                ó.   — | j                   j                  S r1   )r   r    r2   s    r   r    zPasswordHasher.parallelism    r4   r   c                ó.   — | j                   j                  S r1   )r   r!   r2   s    r   r!   zPasswordHasher.hash_len¤   ó   € à×Ñ×(Ñ(Ð(r   c                ó.   — | j                   j                  S r1   )r   r"   r2   s    r   r"   zPasswordHasher.salt_len¨   r7   r   c                ó.   — | j                   j                  S r1   )r   r#   r2   s    r   r#   zPasswordHasher.type¬   s   € à×Ñ×$Ñ$Ð$r   N)Úsaltc          	     ó  — t        t        || j                  «      |xs t        j                  | j
                  «      | j                  | j                  | j                  | j                  | j                  ¬«      j                  d«      S )a  
        Hash *password* and return an encoded hash.

        Args:
            password: Password to hash.

            salt:
                If None, a random salt is securely created.

                .. danger::

                    You should **not** pass a salt unless you really know what
                    you are doing.

        Raises:
            argon2.exceptions.HashingError: If hashing fails.

        Returns:
            Hashed *password*.

        .. versionadded:: 23.1.0 *salt* parameter
        )Úsecretr:   r   r   r    r!   r#   Úascii)r   r   r   ÚosÚurandomr"   r   r   r    r!   r#   Údecode)r(   Úpasswordr:   s      r   ÚhashzPasswordHasher.hash°   sf   € ô. Ü  ¨4¯=©=Ó9ØÒ2œŸ™ D§M¡MÓ2Ø—n‘nØ×(Ñ(Ø×(Ñ(Ø—]‘]Ø—‘ô
÷ ‰&�‹/ð	r   )s	   $argon2i$s	   $argon2d$s	   $argon2idzClassVar[dict[bytes, Type]]Ú_header_to_typec                óª   — t        |d«      }	 | j                  |dd    }t	        |t        || j
                  «      |«      S # t        $ r t        d‚w xY w)ak  
        Verify that *password* matches *hash*.

        .. warning::

            It is assumed that the caller is in full control of the hash.  No
            other parsing than the determination of the hash type is done by
            *argon2-cffi*.

        Args:
            hash: An encoded hash as returned from :meth:`PasswordHasher.hash`.

            password: The password to verify.

        Raises:
            argon2.exceptions.VerifyMismatchError:
                If verification fails because *hash* is not valid for
                *password*.

            argon2.exceptions.VerificationError:
                If verification fails for other reasons.

            argon2.exceptions.InvalidHashError:
                If *hash* is so clearly invalid, that it couldn't be passed to
                Argon2.

        Returns:
            ``True`` on success, otherwise an exception is raised.

        .. versionchanged:: 16.1.0
            Raise :exc:`~argon2.exceptions.VerifyMismatchError` on mismatches
            instead of its more generic superclass.
        .. versionadded:: 18.2.0 Hash type agility.
        r=   Né	   )r   rC   ÚLookupErrorr   r   r   )r(   rB   rA   Ú	hash_types       r   ÚverifyzPasswordHasher.verify×   sf   € ôJ ˜T 7Ó+ˆð	-Ø×,Ñ,¨T°"°1¨XÑ6ˆIô Ø”- ¨$¯-©-Ó8¸)ó
ð 	
øô ò 	-Ü"¨Ð,ð	-ús   ŽA ÁAc                ót   — t        |t        «      r|j                  d«      }| j                  t	        |«      k7  S )a  
        Check whether *hash* was created using the instance's parameters.

        Whenever your Argon2 parameters -- or *argon2-cffi*'s defaults! --
        change, you should rehash your passwords at the next opportunity.  The
        common approach is to do that whenever a user logs in, since that
        should be the only time when you have access to the cleartext
        password.

        Therefore it's best practice to check -- and if necessary rehash --
        passwords after each successful authentication.

        Args:
            hash: An encoded Argon2 password hash.

        Returns:
            Whether *hash* was created using the instance's parameters.

        .. versionadded:: 18.2.0
        .. versionchanged:: 24.1.0 Accepts bytes for *hash*.
        r=   )r   r   r@   r   r	   )r(   rB   s     r   Úcheck_needs_rehashz!PasswordHasher.check_needs_rehash  s3   € ô, �dœEÔ"Ø—;‘;˜wÓ'ˆDà×ÑÔ#5°dÓ#;Ñ;Ð;r   )r   r&   r   r&   r    r&   r!   r&   r"   r&   r   r   r#   r   )r*   r   Úreturnr   )rK   r&   )rK   r   )rA   ústr | bytesr:   zbytes | NonerK   r   )rB   rL   rA   rL   rK   zLiteral[True])rB   rL   rK   Úbool)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__Ú__annotations__ÚDEFAULT_TIME_COSTÚDEFAULT_MEMORY_COSTÚDEFAULT_PARALLELISMÚDEFAULT_HASH_LENGTHÚDEFAULT_RANDOM_SALT_LENGTHr   ÚIDr+   Úclassmethodr/   Úpropertyr   r   r    r!   r"   r#   rB   ÚIÚDrC   rH   rJ   © r   r   r   r   &   sf  … ñ0ðd  
Ð+€IàÓØƒMð +Ø.Ø.Ø+Ø2ØØ—W‘Wð$!àð$!ð ð$!ð ð	$!ð
 ð$!ð ð$!ð ð$!ð ó$!ðL ò
ó ð
ð& ò*ó ð*ð ò,ó ð,ð ò,ó ð,ð ò)ó ð)ð ò)ó ð)ð ò%ó ð%ð CGõ ðD —f‘fØ—f‘fØ—g‘gñ4€OÐ0ó ð-
Øð-
Ø+6ð-
à	ó-
ô^<r   r   )r   zbytes | strr   r   rK   r   ) Ú
__future__r   r>   Útypingr   r   Ú_utilsr   r   r	   r
   Ú
exceptionsr   Ú	low_levelr   r   r   Úprofilesr   Údefault_paramsr"   rX   r!   rW   r   rT   r   rU   r    rV   r   r   r^   r   r   ú<module>rf      s   ðõ #ã 	ç $÷ó õ )ß 7Ñ 7Ý ,ñ (Ó)€à+×4Ñ4Ð Ø$×-Ñ-Ð Ø"×,Ñ,Ð Ø$×0Ñ0Ð Ø$×0Ñ0Ð ó÷y<ò y<r   