o
    Df2	                     @  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                   @  s.   e Zd Z	ddddZdddZdddZdS )ScryptNsaltbyteslengthintnrpbackend
typing.Anyc                 C  s   ddl m} | std|| _td| |dk s#||d @ dkr'td|dk r/td|dk r7t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),cryptography.hazmat.backends.openssl.backendr   scrypt_supportedr   _lengthr   _check_bytes
ValueError_used_salt_n_r_p)selfr   r   r   r   r   r   ossl r"   b/home/ubuntu/webapp/venv/lib/python3.10/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   _check_byteslikerust_opensslkdfderive_scryptr   r   r   r   
_MEM_LIMITr   )r    r%   r"   r"   r#   derive<   s   zScrypt.deriveexpected_keyNonec                 C  s"   |  |}t||stdd S )NzKeys do not match.)r,   r   bytes_eqr   )r    r%   r-   derived_keyr"   r"   r#   verifyM   s   
zScrypt.verify)N)r   r   r   r   r   r   r   r   r   r   r   r   )r%   r   r&   r   )r%   r   r-   r   r&   r.   )__name__
__module____qualname__r$   r,   r1   r"   r"   r"   r#   r      s
    
"r   )
__future__r   systypingcryptographyr   cryptography.exceptionsr   r   r   "cryptography.hazmat.bindings._rustr   r(   cryptography.hazmat.primitivesr   "cryptography.hazmat.primitives.kdfr	   maxsizer+   r   r"   r"   r"   r#   <module>   s   
