o
    jw                     @  sP  d dl mZ d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ G dd deZG dd deZG dd deZG dd deZG dd deeZeje
edej dd ejeedej dd eje	edej dd d S )!    )annotations)utils)UnsupportedAlgorithm_Reasons)CFB)CFB8)OFB)BlockCipherAlgorithmCipherAlgorithm)Mode)ModeWithAuthenticationTag)ModeWithInitializationVector)ModeWithNonce)ModeWithTweak)_check_aes_key_length_check_iv_and_key_length_check_nonce_length)
algorithmsc                   @  s,   e Zd Zd Zd	ddZed
ddZeZdS )CBCinitialization_vectorutils.Bufferc                 C     t d| || _d S )Nr   )r   _check_byteslike_initialization_vector)selfr    r   r/var/www/html/fyndo/pharma/fyndo/venv/lib/python3.10/site-packages/cryptography/hazmat/primitives/ciphers/modes.py__init__*      
zCBC.__init__returnc                 C     | j S Nr   r   r   r   r   r   .      zCBC.initialization_vectorN)r   r   r   r   )	__name__
__module____qualname__namer   propertyr   r   validate_for_algorithmr   r   r   r   r   '   s    
r   c                   @  2   e Zd Zd ZdddZedddZdddZdS )XTStweakr   c                 C  s*   t d| t|dkrtd|| _d S )Nr.      z!tweak must be 128-bits (16 bytes))r   r   len
ValueError_tweak)r   r.   r   r   r   r   8   s   
zXTS.__init__r   c                 C  r    r!   )r2   r#   r   r   r   r.   @   r$   z	XTS.tweak	algorithmr
   Nonec                 C  s0   t |tjtjfrtd|jdvrtdd S )Nz\The AES128 and AES256 classes do not support XTS, please use the standard AES class instead.)   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)
isinstancer   AES128AES256	TypeErrorkey_sizer1   r   r3   r   r   r   r+   D   s   
zXTS.validate_for_algorithmN)r.   r   r%   r3   r
   r   r4   )r&   r'   r(   r)   r   r*   r.   r+   r   r   r   r   r-   5   s    
r-   c                   @  s   e Zd Zd ZeZdS )ECBN)r&   r'   r(   r)   r   r+   r   r   r   r   r=   R   s    r=   c                   @  r,   )CTRnoncer   c                 C  r   )Nr?   )r   r   _nonce)r   r?   r   r   r   r   [   r   zCTR.__init__r   c                 C  r    r!   )r@   r#   r   r   r   r?   _   r$   z	CTR.noncer3   r
   r4   c                 C  s   t | | t| j| j| d S r!   )r   r   r?   r)   r;   r   r   r   r+   c   s   
zCTR.validate_for_algorithmN)r?   r   r%   r<   )r&   r'   r(   r)   r   r*   r?   r+   r   r   r   r   r>   X   s    
r>   c                   @  sN   e Zd Zd ZdZdZ		ddddZedddZedddZ	dddZ
dS )GCMl   ? l            Nr/   r   r   tagbytes | Nonemin_tag_lengthintc                 C  s   t d| t|dk st|dkrtd|| _|d ur9t d| |dk r+tdt||k r9td| d	|| _|| _d S )
Nr         zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).rB      zmin_tag_length must be >= 4zAuthentication tag must be z bytes or longer.)r   r   r0   r1   r   _check_bytes_tag_min_tag_length)r   r   rB   rD   r   r   r   r   m   s    

zGCM.__init__r   c                 C  r    r!   )rJ   r#   r   r   r   rB      r$   zGCM.tagc                 C  r    r!   r"   r#   r   r   r   r      r$   zGCM.initialization_vectorr3   r
   r4   c                 C  sZ   t | | t|tstdtj|jd }| jd ur)t| j|kr+t	d| dd S d S )Nz%GCM requires a block cipher algorithmrF   z'Authentication tag cannot be more than z bytes.)
r   r6   r	   r   r   UNSUPPORTED_CIPHER
block_sizerJ   r0   r1   )r   r3   block_size_bytesr   r   r   r+      s   



zGCM.validate_for_algorithm)Nr/   )r   r   rB   rC   rD   rE   )r   rC   r%   r<   )r&   r'   r(   r)   _MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESr   r*   rB   r   r+   r   r   r   r   rA   h   s    rA   zOFB has been moved to cryptography.hazmat.decrepit.ciphers.modes.OFB and will be removed from cryptography.hazmat.primitives.ciphers.modes in 49.0.0.r   )r)   zCFB has been moved to cryptography.hazmat.decrepit.ciphers.modes.CFB and will be removed from cryptography.hazmat.primitives.ciphers.modes in 49.0.0.r   zCFB8 has been moved to cryptography.hazmat.decrepit.ciphers.modes.CFB8 and will be removed from cryptography.hazmat.primitives.ciphers.modes in 49.0.0.r   N)!
__future__r   cryptographyr   cryptography.exceptionsr   r   *cryptography.hazmat.decrepit.ciphers.modesr   r   r   /cryptography.hazmat.primitives._cipheralgorithmr	   r
   %cryptography.hazmat.primitives._modesr   r   r   r   r   r   r   r   &cryptography.hazmat.primitives.ciphersr   r   r-   r=   r>   rA   
deprecatedr&   DeprecatedIn47r   r   r   r   <module>   sP   7
