a
    Qh                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 G dd de
Zddd	d
dZdZefddZdd ZdddZe	ejdrejZejZndddddZddddZdS )z3
Django's standard crypto functions and utilities.
    N)settings)force_bytes)func_supports_parameterc                   @   s   e Zd ZdZdS )InvalidAlgorithmz&Algorithm is not supported by hashlib.N)__name__
__module____qualname____doc__ r
   r
   L/var/www/sistema_ama/venv/lib/python3.9/site-packages/django/utils/crypto.pyr      s   r   Zsha1)	algorithmc             
   C   s   |du rt j}t| } t|}ztt|}W n2 ty^ } ztd| |W Y d}~n
d}~0 0 || |  }tj	|t||dS )a*  
    Return the HMAC of 'value', using a key generated from key_salt and a
    secret (which defaults to settings.SECRET_KEY). Default algorithm is SHA1,
    but any algorithm name supported by hashlib can be passed.

    A different key_salt should be passed in for every application of HMAC.
    Nz6%r is not an algorithm accepted by the hashlib module.)msgZ	digestmod)
r   
SECRET_KEYr   getattrhashlibAttributeErrorr   digesthmacnew)Zkey_saltvalueZsecretr   Zhasherekeyr
   r
   r   salted_hmac   s    r   Z>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c                    s   d  fddt| D S )aG  
    Return a securely generated random string.

    The bit length of the returned value can be calculated with the formula:
        log_2(len(allowed_chars)^length)

    For example, with default `allowed_chars` (26+26+10), this gives:
      * length: 12, bit length =~ 71 bits
      * length: 22, bit length =~ 131 bits
     c                 3   s   | ]}t  V  qd S N)secretschoice).0iallowed_charsr
   r   	<genexpr>>       z$get_random_string.<locals>.<genexpr>)joinrange)lengthr    r
   r   r   get_random_string3   s    r&   c                 C   s   t t| t|S )z:Return True if the two strings are equal, False otherwise.)r   Zcompare_digestr   )Zval1Zval2r
   r
   r   constant_time_compareA   s    r'   c                 C   s<   |du rt j}|pd}t| } t|}t | j| |||S )z)Return the hash of password using pbkdf2.N)r   Zsha256r   Zpbkdf2_hmacname)passwordZsaltZ
iterationsZdklenr   r
   r
   r   pbkdf2F   s    r*   usedforsecurityr"   T)r+   c                C   s
   t | S r   )r   md5)datar+   r
   r
   r   r,   Y   s    r,   c                C   s
   t | S r   )r   r   )Zhash_algorithmr+   r
   r
   r   new_hash\   s    r.   )N)r   N)r"   )r	   r   r   r   django.confr   Zdjango.utils.encodingr   django.utils.inspectr   
ValueErrorr   r   ZRANDOM_STRING_CHARSr&   r'   r*   r,   r   r.   r
   r
   r
   r   <module>   s"   
