o
    àý°js  ã                   @  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   úŸ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/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k r!tdƒ‚|d ur9t  d|¡ t|ƒ|k r9td|› d	�ƒ‚|| _|| _d S )
Nr   é   é€   zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).é   zmin_tag_length must be >= 4rB   z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   z•OFB 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)   z•CFB 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   z—CFB8 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øø
ø