U
    ^y                     @   s   d dl mZ d dl mZ d dlZd dlZd dlZd dlZddlmZ ddl	m
Z
mZmZmZmZmZmZmZ ddd	d
ddddddddgZedZdddZdd Zdd ZdddZdd ZdS )    )absolute_import)divisionN   )_bcrypt)
__author____copyright__	__email____license____summary__	__title____uri____version__r   r
   r   r   r   r   r	   r   gensalthashpwkdfcheckpws   ^\$2y\$      2bc                 C   s~   |dkrt d| dk s | dkr(t dtd}tjdd}tj||t| d	| d	 d
|  	d d	 tj
| S )N)s   2ar   z%Supported prefixes are b'2a' or b'2b'      zInvalid rounds   char[]      $z%2.2uascii)
ValueErrorosurandomr   ffinewlibencode_base64lenencodestring)roundsprefixsaltoutput r)   3/tmp/pip-install-v5gamh74/bcrypt/bcrypt/__init__.pyr   *   s    

c                 C   s   t | tjst |tjr tdd| kr0td| d d } |td| }}tj	dd}tj
| ||t|}|dkrtd	|d d
 tj|d
d   S )N.Unicode-objects must be encoded before hashing    z"password may not contain NUL bytesH   s   $2b$r      r   zInvalid saltr   )
isinstancesix	text_type	TypeErrorr   _normalize_resubr   r   r   r    Zbcrypt_hashpassr"   r$   )passwordr'   Zoriginal_salthashedretvalr)   r)   r*   r   ;   s    c                 C   sn   t | tjst |tjr tdd| ks0d|kr8tdt| |}t|t|krVdS tj	||t|dkS )Nz/Unicode-objects must be encoded before checkingr,   z6password and hashed_password may not contain NUL bytesFr   )
r/   r0   r1   r2   r   r   r"   r   r    Ztimingsafe_bcmp)r5   Zhashed_passwordretr)   r)   r*   r   a   s    

Fc              	   C   s   t | tjst |tjr tdt| dks8t|dkr@td|dksP|dkrXtd|dk rhtd|dk r|stjd	|t	d
d t
jd|}t
j| t| |t||t||}t|dk t
j||d d  S )Nr+   r   z#password and salt must not be emptyi   zdesired_key_bytes must be 1-512r   zrounds must be 1 or more2   zrWarning: bcrypt.kdf() called with only {0} round(s). This few is not secure: the parameter is linear, like PBKDF2.   )
stacklevelz	uint8_t[])r/   r0   r1   r2   r"   r   warningswarnformatUserWarningr   r   r   r    Zbcrypt_pbkdf_bcrypt_assertbuffer)r5   r'   Zdesired_key_bytesr%   Zignore_few_roundskeyresr)   r)   r*   r   s   s8          c                 C   s   | st dd S )Nzbcrypt assertion failed)SystemError)okr)   r)   r*   r@      s    r@   )r   r   )F)
__future__r   r   r   rer<   r0    r   	__about__r   r   r   r	   r
   r   r   r   __all__compiler3   r   r   r   r   r@   r)   r)   r)   r*   <module>   s4   (         

&
"