OwlCyberSecurity - MANAGER
Edit File: crypto.cpython-39.pyc
a ���e� � @ s� d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z G dd� de �Zddd �d d�ZdZ e fd d�Zdd� Zddd�Ze ejd�r�ejZejZnddd�dd�Zdd�dd�ZdS )z3 Django's standard crypto functions and utilities. � N)�settings)�force_bytes)�func_supports_parameterc @ s e Zd ZdZdS )�InvalidAlgorithmz&Algorithm is not supported by hashlib.N)�__name__� __module__�__qualname__�__doc__� r r �T/home/gouroczh/virtualenv/pat/3.9/lib/python3.9/site-packages/django/utils/crypto.pyr s r �sha1)� algorithmc C s� |du rt j}t| �} t|�}ztt|�}W n2 ty^ } ztd| �|�W Y d}~n d}~0 0 || | ��� }tj |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.)�msg� digestmod) r Z SECRET_KEYr �getattr�hashlib�AttributeErrorr �digest�hmac�new)Zkey_salt�value�secretr Zhasher�e�keyr r r �salted_hmac s ��r Z>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c s d� � fdd�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 qd S �N)�secrets�choice)�.0�i�� allowed_charsr r � <genexpr>>