
    =b                     .   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZmZmZ g dZej        Z	  G d	 d
e          ZefdededededededededefdZefdededededededededefdZdededede	d         fdZdededefdZdedefdZdS )u@  
Low-level functions if you want to build your own higher level abstractions.

.. warning::
    This is a "Hazardous Materials" module.  You should **ONLY** use it if
    you're 100% absolutely sure that you know what you’re doing because this
    module is full of land mines, dragons, and dinosaurs with laser guns.
    )Enum)Any)ffilib   )Literal)HashingErrorVerificationErrorVerifyMismatchError)ARGON2_VERSIONTyper   hash_secrethash_secret_rawverify_secretc                   @    e Zd ZdZej        Z	 ej        Z	 ej	        Z
dS )r   zX
    Enum of Argon2 variants.

    Please see :doc:`parameters` on how to pick one.
    N)__name__
__module____qualname____doc__r   Argon2_dDArgon2_iI	Argon2_idID     0lib/python3.11/site-packages/argon2/low_level.pyr   r   '   sC          	A
 	A 
B
 
r   r   secretsalt	time_costmemory_costparallelismhash_lentypeversionreturnc                    t          j        |||t          |          ||j                  dz   }t	          j        d|          }	t          j        |||t	          j        d|           t          |           t	          j        d|          t          |          t          j        ||	||j        |          }
|
t           j        k    rt          t          |
                    t	          j        |	          S )a  
    Hash *secret* and return an **encoded** hash.

    An encoded hash can be directly passed into :func:`verify_secret` as it
    contains all parameters and the salt.

    :param bytes secret: Secret to hash.
    :param bytes salt: A salt_.  Should be random and different for each
        secret.
    :param Type type: Which Argon2 variant to use.
    :param int version: Which Argon2 version to use.

    For an explanation of the Argon2 parameters see :class:`PasswordHasher`.

    :rtype: bytes

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

    .. versionadded:: 16.0.0

    .. _salt: https://en.wikipedia.org/wiki/Salt_(cryptography)
    .. _kibibytes: https://en.wikipedia.org/wiki/Binary_prefix#kibi
    r   char[]	uint8_t[])r   argon2_encodedlenlenvaluer   newargon2_hashNULL	ARGON2_OKr	   error_to_strstring)r   r    r!   r"   r#   r$   r%   r&   sizebufrvs              r   r   r   G   s    D 	IIJ	
 	
 	 	 '(D
!
!C	V$$FT""D		

 
B 
S]<++,,,:c??r   c                    t          j        d|          }t          j        |||t          j        d|           t	          |           t          j        d|          t	          |          ||t           j        d|j        |          }	|	t          j        k    rt          t          |	                    t          t          j        ||                    S )z
    Hash *password* and return a **raw** hash.

    This function takes the same parameters as :func:`hash_secret`.

    .. versionadded:: 16.0.0
    r*   r   )r   r.   r   r/   r,   r0   r-   r1   r	   r2   bytesbuffer)
r   r    r!   r"   r#   r$   r%   r&   r5   r6   s
             r   r   r      s    " '+x
(
(C	V$$FT""D			

 
B 
S]<++,,,C**+++r   hashTc                 T   t          j        t          j        d|           t          j        d|          t	          |          |j                  }|t           j        k    rdS |t           j        k    rt          t          |                    t          t          |                    )a8  
    Verify whether *secret* is correct for *hash* of *type*.

    :param bytes hash: An encoded Argon2 hash as returned by
        :func:`hash_secret`.
    :param bytes secret: The secret to verify whether it matches the one
        in *hash*.
    :param Type type: Type for *hash*.

    :raises argon2.exceptions.VerifyMismatchError: If verification fails
        because *hash* is not valid for *secret* of *type*.
    :raises argon2.exceptions.VerificationError: If verification fails for
        other reasons.

    :return: ``True`` on success, raise
        :exc:`~argon2.exceptions.VerificationError` otherwise.
    :rtype: bool

    .. versionadded:: 16.0.0
    .. versionchanged:: 16.1.0
        Raise :exc:`~argon2.exceptions.VerifyMismatchError` on mismatches
        instead of its more generic superclass.
    r)   r*   T)r   argon2_verifyr   r.   r,   r-   r1   ARGON2_VERIFY_MISMATCHr   r2   r
   )r:   r   r%   r6   s       r   r   r      s    0 
	$V$$F
	
 
B 
S]t	s)	)	)!,r"2"2333R 0 0111r   contextc                 ,    t          j        | |          S )a  
    Direct binding to the ``argon2_ctx`` function.

    .. warning::
        This is a strictly advanced function working on raw C data structures.
        Both *Argon2*'s and *argon2-cffi*'s higher-level bindings do a lot of
        sanity checks and housekeeping work that *you* are now responsible for
        (e.g. clearing buffers). The structure of the *context* object can,
        has, and will change with *any* release!

        Use at your own peril; *argon2-cffi* does *not* use this binding
        itself.

    :param context: A CFFI *Argon2* context object (i.e. an ``struct
        Argon2_Context``/``argon2_context``).
    :param int type: Which *Argon2* variant to use.  You can use the ``value``
        field of :class:`Type`'s fields.

    :rtype: int
    :return: An *Argon2* error code.  Can be transformed into a string using
        :func:`error_to_str`.

    .. versionadded:: 16.0.0
    )r   
argon2_ctx)r>   r%   s     r   corerA      s    2 >'4(((r   errorc                 |    t          j        t          j        |                     }|                    d          }|S )z
    Convert an Argon2 error code into a native string.

    :param int error: An Argon2 error code as returned by :func:`core`.

    :rtype: str

    .. versionadded:: 16.0.0
    ascii)r   r3   r   argon2_error_messagedecode)rB   msgs     r   r2   r2      s4     *S-e44
5
5C
**W

CJr   N)r   enumr   typingr   _argon2_cffi_bindingsr   r   _typingr   
exceptionsr	   r
   r   __all__ARGON2_VERSION_NUMBERr   r   r8   intr   r   r   rA   strr2   r   r   r   <module>rQ      s<                * * * * * * * *       L L L L L L L L L L   *    4   P "? ??
? ? 	?
 ? ? ? ? ? ? ? ?T "%, %,%,
%, %, 	%,
 %, %, %, %, %, %, %, %,P#2 #2u #2D #2WT] #2 #2 #2 #2L)# )S )S ) ) ) )8       r   