Server : Apache System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64 User : dh_edsupp ( 6597262) PHP Version : 8.2.26 Disable Function : NONE Directory : /lib/python3/dist-packages/django/utils/__pycache__/ |
Upload File : |
o 3�aC � @ s� d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m Z G dd� de�Zddd �d d�Z e� ZdZeefd d�Zdd� Zddd�ZdS )z3 Django's standard crypto functions and utilities. � N)�settings)�RemovedInDjango40Warning)�force_bytesc @ s e Zd ZdZdS )�InvalidAlgorithmz&Algorithm is not supported by hashlib.N)�__name__� __module__�__qualname__�__doc__� r r �5/usr/lib/python3/dist-packages/django/utils/crypto.pyr s r �sha1)� algorithmc C sx |du rt j}t| �} t|�}ztt|�}W n ty) } ztd| �|�d}~ww || | ��� }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 � SECRET_KEYr �getattr�hashlib�AttributeErrorr �digest�hmac�new)�key_salt�value�secretr �hasher�e�keyr r r �salted_hmac s$ �����r �>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c s4 | t u rt�dt� d} 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 z.Not providing a length argument is deprecated.� � c 3 s � | ]}t �� �V qd S �N)�secrets�choice)�.0�i�� allowed_charsr r � <genexpr>H s � z$get_random_string.<locals>.<genexpr>)�NOT_PROVIDED�warnings�warnr �join�range)�lengthr'