o
    k9_Ž  ã                   @   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 g d¢Ze d¡Zddededefdd„Zdededefdd„Zdededefdd„Z	d dedededededefdd„Zdeddf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\$é   ó   2bÚroundsÚprefixÚreturnc                 C   s~   |dv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)r   r   ÚsaltÚoutput© r*   ú1/usr/lib/python3/dist-packages/bcrypt/__init__.pyr   9   s&   
ÿþýü
ûÿr   Úpasswordr(   c                 C   s¢   t | tjƒst |tjƒrtdƒ‚d| v rtdƒ‚| d d… } |t d|¡}}tj 	dd¡}tj
 | ||t|ƒ¡}|dkrAtd	ƒ‚|d d
… tj |¡d
d …  S )Nú.Unicode-objects must be encoded before hashingó    z"password may not contain NUL byteséH   s   $2b$r   é€   r   zInvalid saltr   )Ú
isinstanceÚsixÚ	text_typeÚ	TypeErrorr   Ú_normalize_reÚsubr   r!   r"   r#   Úbcrypt_hashpassr%   r'   )r,   r(   Úoriginal_saltÚhashedÚretvalr*   r*   r+   r   N   s    r   Úhashed_passwordc                 C   sn   t | tjƒst |tjƒrtdƒ‚d| v sd|v rtdƒ‚t| |ƒ}t|ƒt|ƒkr+dS tj 	||t|ƒ¡dkS )Nz/Unicode-objects must be encoded before checkingr.   z6password and hashed_password may not contain NUL bytesFr   )
r1   r2   r3   r4   r   r   r%   r   r#   Útimingsafe_bcmp)r,   r;   Úretr*   r*   r+   r   t   s   ÿÿ
r   FÚdesired_key_bytesÚignore_few_roundsc              	   C   sÞ   t | tjƒst |tjƒrtdƒ‚t| ƒdkst|ƒdkr tdƒ‚|dks(|dkr,tdƒ‚|dk r4tdƒ‚|dk rE|sEt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 moreé2   zrWarning: bcrypt.kdf() called with only {0} round(s). This few is not secure: the parameter is linear, like PBKDF2.é   )Ú
stacklevelz	uint8_t[])r1   r2   r3   r4   r%   r   ÚwarningsÚwarnÚformatÚUserWarningr   r!   r"   r#   Úbcrypt_pbkdfÚ_bcrypt_assertÚbuffer)r,   r(   r>   r   r?   ÚkeyÚresr*   r*   r+   r   ‡   s*   ú	ÿr   Úokc                 C   s   | st dƒ‚d S )Nzbcrypt assertion failed)ÚSystemError)rL   r*   r*   r+   rH   °   s   ÿrH   )r   r   )F)Ú
__future__r   r   r   ÚrerC   r2   Ú r   Ú	__about__r   r   r   r	   r
   r   r   r   Ú__all__Úcompiler5   ÚintÚbytesr   r   Úboolr   r   rH   r*   r*   r*   r+   Ú<module>   s8   (
&ûÿþýüû
ú)