a
    ϏPf2	                     @  s~   d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ ejd ZG d	d
 d
eZdS )    )annotationsN)utils)AlreadyFinalized
InvalidKeyUnsupportedAlgorithm)openssl)constant_time)KeyDerivationFunction   c                   @  sH   e Zd ZddddddddddZdddd	d
ZddddddZdS )ScryptNbytesintz
typing.Any)saltlengthnrpbackendc                 C  s   ddl m} | std|| _td| |dk sF||d @ dkrNtd|dk r^td|dk rntd	d
| _|| _	|| _
|| _|| _d S )Nr   )r   z/This version of OpenSSL does not support scryptr   r
      z-n must be greater than 1 and be a power of 2.z%r must be greater than or equal to 1.z%p must be greater than or equal to 1.F)Z,cryptography.hazmat.backends.openssl.backendr   Zscrypt_supportedr   _lengthr   _check_bytes
ValueError_used_salt_n_r_p)selfr   r   r   r   r   r   Zossl r   j/var/www/html/python-backend/venv/lib/python3.9/site-packages/cryptography/hazmat/primitives/kdf/scrypt.py__init__   s$    	zScrypt.__init__)key_materialreturnc              	   C  sB   | j rtdd| _ td| tj|| j| j| j	| j
t| jS )Nz'Scrypt instances can only be used once.Tr!   )r   r   r   Z_check_byteslikerust_opensslZkdfZderive_scryptr   r   r   r   
_MEM_LIMITr   )r   r!   r   r   r   derive<   s    zScrypt.deriveNone)r!   expected_keyr"   c                 C  s"   |  |}t||stdd S )NzKeys do not match.)r%   r   Zbytes_eqr   )r   r!   r'   Zderived_keyr   r   r   verifyM   s    
zScrypt.verify)N)__name__
__module____qualname__r    r%   r(   r   r   r   r   r      s    "r   )
__future__r   systypingZcryptographyr   Zcryptography.exceptionsr   r   r   Z"cryptography.hazmat.bindings._rustr   r#   Zcryptography.hazmat.primitivesr   Z"cryptography.hazmat.primitives.kdfr	   maxsizer$   r   r   r   r   r   <module>   s   
