o
    -׾gU                     @   s   d dl mZmZmZmZ d dlZd dlZd dlZd dlZddl	m
Z
mZ ddlmZ ddlmZmZmZ ejdk r<eZndd	 Zd
gZdd
 Zde_dS )    )unicode_literalsdivisionabsolute_importprint_functionN   )int_from_bytesint_to_bytes)pretty_message)	type_namebyte_cls	int_types)   c                 C   s
   t | gS )N)bytes)num r   Y/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/oscrypto/_pkcs5.pychr_cls   s   
r   pbkdf2c                 C   s  t |tsttdt|t |tsttdt|t |ts*ttdt||dk r7ttdt|t |tsEttdt||dk rRttdt|| tg dvrcttd	t| t	t
| }d
dddddd|  }t|d|}d}d}	t|	|k r| }
|
|td|  |
 }t|}t|d D ]}| }
|
| |
 }|t|N }q|	t||d7 }	|d7 }t|	|k s|	d| S )a4  
    Implements PBKDF2 from PKCS#5 v2.2 in pure Python

    :param hash_algorithm:
        The string name of the hash algorithm to use: "md5", "sha1", "sha224",
        "sha256", "sha384", "sha512"

    :param password:
        A byte string of the password to use an input to the KDF

    :param salt:
        A cryptographic random byte string

    :param iterations:
        The numbers of iterations to use when deriving the key

    :param key_length:
        The length of the desired key in bytes

    :return:
        The derived key as a byte string
    z@
            password must be a byte string, not %s
            z<
            salt must be a byte string, not %s
            z?
            iterations must be an integer, not %s
            r   zC
            iterations must be greater than 0 - is %s
            z?
            key_length must be an integer, not %s
            zC
            key_length must be greater than 0 - is %s
            )md5sha1sha224sha256sha384sha512z
            hash_algorithm must be one of "md5", "sha1", "sha224", "sha256",
            "sha384", "sha512", not %s
                         0   @   N    s   >I)widthr   )
isinstancer   	TypeErrorr	   r
   r   
ValueErrorreprsetgetattrhashlibhmacnewlencopyupdatestructpackdigestr   ranger   )hash_algorithmpasswordsalt
iterations
key_lengthalgohash_lengthoriginal_hmacblockoutputprflastu_r   r   r   r      s|   




	
T)
__future__r   r   r   r   sysr(   r)   r.   _asn1r   r   _errorsr	   _typesr
   r   r   version_infochrr   __all__r   pure_pythonr   r   r   r   <module>   s   

t