← Back
Editing: crypto.cpython-311.pyc
� �|�eC � � � d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl m Z G d� de� � Zddd �d �Z e� � ZdZeefd�Zd � Zdd�ZdS )z3 Django's standard crypto functions and utilities. � N)�settings)�RemovedInDjango40Warning)�force_bytesc � � e Zd ZdZdS )�InvalidAlgorithmz&Algorithm is not supported by hashlib.N)�__name__� __module__�__qualname__�__doc__� � �5/usr/lib/python3/dist-packages/django/utils/crypto.pyr r s � � � � � �0�0��Dr r �sha1)� algorithmc �Z � |�t j }t | � � } t |� � } t t |� � }n%# t $ r}t d|z � � |�d}~ww xY w || |z � � � � � }t j |t |� � |�� � 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�keys r �salted_hmacr! s� � � �~��$���8�$�$�H� �� � �F����)�,�,����� � � ��D�� � � � � ��������� �&��F�"� #� #� *� *� ,� ,�C� �8�C�[��/�/�6�B�B�B�Bs �A � A&�A!�!A&�>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c � �� | t u rt j dt � � d} d� �fd�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 �@ �K � | ]}t j �� � V � �d S �N)�secrets�choice)�.0�i� allowed_charss �r � <genexpr>z$get_random_string.<locals>.<genexpr>H s- �� � � �H�H�Q�7�>�-�0�0�H�H�H�H�H�Hr )�NOT_PROVIDED�warnings�warnr �join�range)�lengthr, s `r �get_random_stringr4 7 s^ �� � ����� �<�$� � � � �� �7�7�H�H�H�H�%��-�-�H�H�H�H�H�Hr c �` � t j t | � � t |� � � � S )z:Return True if the two strings are equal, False otherwise.)r( �compare_digestr )�val1�val2s r �constant_time_comparer9 K s% � ��!�+�d�"3�"3�[��5F�5F�G�G�Gr c � � |�t j }|pd}t | � � } t |� � }t j |� � j | |||� � S )z)Return the hash of password using pbkdf2.N)r �sha256r �pbkdf2_hmac�name)�password�salt� iterations�dklenr s r �pbkdf2rB P sR � � �~�����M�T�E��8�$�$�H��t���D���v�v�x�x�}�h��j�%�P�P�Pr r'