관리-도구
편집 파일: pbkdf2.cpython-39.opt-1.pyc
a f�WcBJ � @ s� d Z ddlmZmZ ddlmZmZ ddlZe�e �Z ddlmZ ddl mZmZ ddlmZmZmZmZ ddlmZ ddlm mZ g d �ZG d d� dejejejej�Z dde fd d�Z!e!ddded�d�Z"e!ddd�Z#e!ddd�Z$ej%de"dddd�Z&ej%de#dddd�Z'ej%d e$d!d"dd�Z(d#Z)G d$d%� d%ejejejej�Z*G d&d'� d'ejej+ej�Z,G d(d)� d)ejejej�Z-G d*d+� d+ejejejej�Z.dS ),z,passlib.handlers.pbkdf - PBKDF2 based hashes� )�hexlify� unhexlify)� b64encode� b64decodeN)� to_unicode)�ab64_decode�ab64_encode)� str_to_bascii�u� uascii_to_str�unicode)�pbkdf2_hmac)�pbkdf2_sha1� pbkdf2_sha256� pbkdf2_sha512�cta_pbkdf2_sha1�dlitz_pbkdf2_sha1�grub_pbkdf2_sha512c @ sR e Zd ZdZdZejZdZdZ dZ dZdZdZ dZed d � �Zdd� Zd d� ZdS )�Pbkdf2DigestHandlerz1base class for various pbkdf2_{digest} algorithms��saltZ salt_size�rounds� � N� � �� �linearc C sF t j|| j| d�\}}}t|�d��}|r8t|�d��}| |||d�S )N)�handler�ascii�r r �checksum)�uh� parse_mc3�identr �encode��cls�hashr r �chk� r) �;/usr/lib/python3.9/site-packages/passlib/handlers/pbkdf2.py�from_string? s zPbkdf2DigestHandler.from_stringc C s4 t | j��d�}t | j��d�}t�| j| j||�S �Nr )r r �decoder r! � render_mc3r# r ��selfr r( r) r) r* � to_stringG s zPbkdf2DigestHandler.to_stringc C s t | j|| j| j| j�S )N)r �_digestr r � checksum_size�r0 �secretr) r) r* �_calc_checksumL s z"Pbkdf2DigestHandler._calc_checksum)�__name__� __module__�__qualname__�__doc__�setting_kwdsr! �HASH64_CHARSZchecksum_chars�default_salt_size� max_salt_size�default_rounds� min_rounds� max_rounds�rounds_costr2 �classmethodr+ r1 r6 r) r) r) r* r s r i�. c C sd d| }|du rt d�| f }t}t||ft|||| |||d d d dt| �� |j|d� d ��S ) z;create new Pbkdf2DigestHandler subclass for a specific hashZpbkdf2_Nz$pbkdf2-%s$� � � a$ This class implements a generic ``PBKDF2-HMAC-%(digest)s``-based password hash, and follows the :ref:`password-hash-api`. It supports a variable-length salt, and a variable number of rounds. The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords: :type salt: bytes :param salt: Optional salt bytes. If specified, the length must be between 0-1024 bytes. If not specified, a %(dsc)d byte salt will be autogenerated (this is recommended). :type salt_size: int :param salt_size: Optional number of bytes to use when autogenerating new salts. Defaults to %(dsc)d bytes, but can be any value between 0 and 1024. :type rounds: int :param rounds: Optional number of rounds to use. Defaults to %(dr)d, but must be within ``range(1,1<<32)``. :type relaxed: bool :param relaxed: By default, providing an invalid value for one of the other keywords will result in a :exc:`ValueError`. If ``relaxed=True``, and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning` will be issued instead. Correctable errors include ``rounds`` that are too small or too large, and ``salt`` strings that are too long. .. versionadded:: 1.6 )�digestZdscZdr)r8 �namer# r2 r? r3 Zencoded_checksum_sizer: )r r �type�dict�upperr= )Z hash_name�digest_sizer r# �modulerH �baser) r) r* �create_pbkdf2_hashP s ��rO �sha1� i�� z$pbkdf2$)r# Zsha256� iHq �sha512�@ i�a �ldap_pbkdf2_sha1z{PBKDF2}T�ldap_pbkdf2_sha256z{PBKDF2-SHA256}z$pbkdf2-sha256$�ldap_pbkdf2_sha512z{PBKDF2-SHA512}z$pbkdf2-sha512$s -_c @ sZ e Zd ZdZd ZdZed�ZdZdZ dZ ejZdZ dZd Zed d� �Zdd � Zdd� ZdS )r a� This class implements Cryptacular's PBKDF2-based crypt algorithm, and follows the :ref:`password-hash-api`. It supports a variable-length salt, and a variable number of rounds. The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords: :type salt: bytes :param salt: Optional salt bytes. If specified, it may be any length. If not specified, a one will be autogenerated (this is recommended). :type salt_size: int :param salt_size: Optional number of bytes to use when autogenerating new salts. Defaults to 16 bytes, but can be any value between 0 and 1024. :type rounds: int :param rounds: Optional number of rounds to use. Defaults to 60000, must be within ``range(1,1<<32)``. :type relaxed: bool :param relaxed: By default, providing an invalid value for one of the other keywords will result in a :exc:`ValueError`. If ``relaxed=True``, and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning` will be issued instead. Correctable errors include ``rounds`` that are too small or too large, and ``salt`` strings that are too long. .. versionadded:: 1.6 r �$p5k2$rQ r r r r r c C sL t j|| jd| d�\}}}t|�d�t�}|r>t|�d�t�}| |||d�S )Nr )�rounds_baser r r )r! r"