
    ^h"                       S SK Jr  S SKrS SKJrJr  SSKJrJrJ	r	J
r
  SSKJr  SSKJrJrJr  SSKJr  \" 5       r\R(                  r\R,                  r\R0                  r\R4                  r\R8                  rSS	 jr " S
 S5      rg)    )annotationsN)ClassVarLiteral   )
Parameters_check_typesextract_parametersvalidate_params_for_platform)InvalidHashError)Typehash_secretverify_secret)get_default_parametersc                R    [        U [        5      (       a  U $ U R                  U5      $ )zE
Ensure *s* is a bytes string.  Encode using *encoding* if it isn't.
)
isinstancebytesencode)sencodings     Q/home/james-whalen/.local/lib/python3.13/site-packages/argon2/_password_hasher.py_ensure_bytesr      s%     !U88H    c                     \ rS rSr% SrSS/rS\S'   S\S'   \\\	\
\S\R                  4             SS jjr\SS	 j5       r\SS
 j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       r\SS j5       rSS.SS jjr\R2                  \R4                  \R                  S.rS\S'         SS jrSS jrSrg) PasswordHasher&   a  
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           
         [        U[        4U[        4U[        4U[        4U[        4U[        4U[        4S9nU(       a  [	        U5      e[        USUUUUUS9n	[        U	5        Xl        X`l        g )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__PasswordHasher.__init__^   s      #&$c*$c*___
 A,##
 	%V, " r   c           	         U " UR                   UR                  UR                  UR                  UR                  UR
                  S9$ )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_parametersPasswordHasher.from_parameters   sA     &&****____
 	
r   c                .    U R                   R                  $ N)r   r   r)   s    r   r   PasswordHasher.time_cost   s    )))r   c                .    U R                   R                  $ r4   )r   r    r5   s    r   r    PasswordHasher.memory_cost       +++r   c                .    U R                   R                  $ r4   )r   r!   r5   s    r   r!   PasswordHasher.parallelism   r9   r   c                .    U R                   R                  $ r4   )r   r"   r5   s    r   r"   PasswordHasher.hash_len       (((r   c                .    U R                   R                  $ r4   )r   r#   r5   s    r   r#   PasswordHasher.salt_len   r>   r   c                .    U R                   R                  $ r4   )r   r$   r5   s    r   r$   PasswordHasher.type   s    $$$r   N)saltc          
        [        [        XR                  5      U=(       d     [        R                  " U R
                  5      U R                  U R                  U R                  U R                  U R                  S9R                  S5      $ )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
)secretrC   r   r    r!   r"   r$   ascii)r   r   r   osurandomr#   r   r    r!   r"   r$   decode)r)   passwordrC   s      r   hashPasswordHasher.hash   sd    .  ==92DMM2nn((((]]
 &/	r   )s	   $argon2i$s	   $argon2d$s	   $argon2idzClassVar[dict[bytes, Type]]_header_to_typec                    [        US5      n U R                  USS    n[	        U[        X R
                  5      U5      $ ! [         a    [        Sef = f)a  
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.
rF   N	   )r   rM   LookupErrorr   r   r   )r)   rK   rJ   	hash_types       r   verifyPasswordHasher.verify   sd    J T7+	-,,T"1X6I ---8)
 	
  	-",	-s   A   Ac                ~    [        U[        5      (       a  UR                  S5      nU R                  [	        U5      :g  $ )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*.
rF   )r   r   rI   r   r	   )r)   rK   s     r   check_needs_rehash!PasswordHasher.check_needs_rehash  s6    , dE"";;w'D#5d#;;;r   )r   r   )r   r'   r    r'   r!   r'   r"   r'   r#   r'   r   r   r$   r   )r+   r   returnr   )rW   r'   )rW   r   )rJ   str | bytesrC   zbytes | NonerW   r   )rK   rX   rJ   rX   rW   zLiteral[True])rK   rX   rW   bool)__name__
__module____qualname____firstlineno____doc__	__slots____annotations__DEFAULT_TIME_COSTDEFAULT_MEMORY_COSTDEFAULT_PARALLELISMDEFAULT_HASH_LENGTHDEFAULT_RANDOM_SALT_LENGTHr   IDr,   classmethodr1   propertyr   r    r!   r"   r#   r$   rK   IDrM   rR   rU   __static_attributes__ r   r   r   r   &   sf   0d 
+IM +..+2WW$!$! $! 	$!
 $! $! $! $!L 
 
& * * , , , , ) ) ) ) % % CG D ffffgg4O0 -
-
+6-
	-
^<r   r   )r   zbytes | strr   r   rW   r   ) 
__future__r   rG   typingr   r   _utilsr   r   r	   r
   
exceptionsr   	low_levelr   r   r   profilesr   default_paramsr#   re   r"   rd   r   ra   r    rb   r!   rc   r   r   rl   r   r   <module>rt      s    # 	 $  ) 7 7 , ()+44 $-- ",, $00 $00 y< y<r   