o
    ™¨Êhs  ã                   @   sø  d dl mZmZmZ d dlZd dlZd dlmZ e ej	¡G dd„ de
ƒƒZe ej	¡G dd„ de
ƒƒZe ej	¡G dd	„ d	e
ƒƒZe ej	¡G d
d„ de
ƒƒZe ej	¡G dd„ de
ƒƒZdd„ Zdd„ Zdd„ Ze e¡e e¡G dd„ de
ƒƒƒZe e¡e e¡G dd„ de
ƒƒƒZe e¡G dd„ de
ƒƒZe e¡e e¡G dd„ de
ƒƒƒZe e¡e e¡G dd„ de
ƒƒƒZe e¡e e¡G dd„ de
ƒƒƒZe e¡e e¡G d d!„ d!e
ƒƒƒZe e¡e e¡e e¡G d"d#„ d#e
ƒƒƒƒZdS )$é    )Úabsolute_importÚdivisionÚprint_functionN)Úutilsc                   @   s(   e Zd Zejdd„ ƒZejdd„ ƒZdS )ÚModec                 C   ó   dS )z@
        A string naming this mode (e.g. "ECB", "CBC").
        N© ©Úselfr   r   ú^/var/www/html/env/lib/python3.10/site-packages/cryptography/hazmat/primitives/ciphers/modes.pyÚname   ó    z	Mode.namec                 C   r   )zq
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        Nr   ©r
   Ú	algorithmr   r   r   Úvalidate_for_algorithm   r   zMode.validate_for_algorithmN)Ú__name__Ú
__module__Ú__qualname__ÚabcÚabstractpropertyr   Úabstractmethodr   r   r   r   r   r      s
    
r   c                   @   ó   e Zd Zejdd„ ƒZdS )ÚModeWithInitializationVectorc                 C   r   )zP
        The value of the initialization vector for this mode as bytes.
        Nr   r	   r   r   r   Úinitialization_vector    r   z2ModeWithInitializationVector.initialization_vectorN)r   r   r   r   r   r   r   r   r   r   r      ó    r   c                   @   r   )ÚModeWithTweakc                 C   r   )z@
        The value of the tweak for this mode as bytes.
        Nr   r	   r   r   r   Útweak)   r   zModeWithTweak.tweakN)r   r   r   r   r   r   r   r   r   r   r   '   r   r   c                   @   r   )ÚModeWithNoncec                 C   r   )z@
        The value of the nonce for this mode as bytes.
        Nr   r	   r   r   r   Únonce2   r   zModeWithNonce.nonceN)r   r   r   r   r   r   r   r   r   r   r   0   r   r   c                   @   r   )ÚModeWithAuthenticationTagc                 C   r   )zP
        The value of the tag supplied to the constructor of this mode.
        Nr   r	   r   r   r   Útag;   r   zModeWithAuthenticationTag.tagN)r   r   r   r   r   r    r   r   r   r   r   9   r   r   c                 C   s$   |j dkr|jdkrtdƒ‚d S d S )Né   ÚAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)Úkey_sizer   Ú
ValueErrorr   r   r   r   Ú_check_aes_key_lengthB   s
   ÿÿr%   c                 C   s0   t | jƒd |jkrtd t | jƒ| j¡ƒ‚d S )Né   zInvalid IV size ({0}) for {1}.)Úlenr   Ú
block_sizer$   Úformatr   r   r   r   r   Ú_check_iv_lengthI   s
   ÿÿr*   c                 C   s   t | |ƒ t| |ƒ d S ©N)r%   r*   r   r   r   r   Ú_check_iv_and_key_lengthP   s   
r,   c                   @   ó&   e Zd Zd Zdd„ Ze d¡ZeZ	dS )ÚCBCc                 C   ó   t |tƒs	tdƒ‚|| _d S ©Nú#initialization_vector must be bytes©Ú
isinstanceÚbytesÚ	TypeErrorÚ_initialization_vector©r
   r   r   r   r   Ú__init__Z   ó   

zCBC.__init__r6   N©
r   r   r   r   r8   r   Úread_only_propertyr   r,   r   r   r   r   r   r.   U   ó
    
r.   c                   @   ó*   e Zd Zd Zdd„ Ze d¡Zdd„ ZdS )ÚXTSc                 C   s0   t |tƒs	tdƒ‚t|ƒdkrtdƒ‚|| _d S )Nztweak must be bytesé   z!tweak must be 128-bits (16 bytes))r3   r4   r5   r'   r$   Ú_tweak)r
   r   r   r   r   r8   i   s
   

zXTS.__init__r@   c                 C   s   |j dvr	tdƒ‚d S )N)r!   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)r#   r$   r   r   r   r   r   t   s
   
ÿÿzXTS.validate_for_algorithmN)	r   r   r   r   r8   r   r;   r   r   r   r   r   r   r>   d   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   rA   |   s    rA   c                   @   r-   )ÚOFBc                 C   r/   r0   r2   r7   r   r   r   r8   ˆ   r9   zOFB.__init__r6   Nr:   r   r   r   r   rB   ƒ   r<   rB   c                   @   r-   )ÚCFBc                 C   r/   r0   r2   r7   r   r   r   r8   —   r9   zCFB.__init__r6   Nr:   r   r   r   r   rC   ’   r<   rC   c                   @   r-   )ÚCFB8c                 C   r/   r0   r2   r7   r   r   r   r8   ¦   r9   zCFB8.__init__r6   Nr:   r   r   r   r   rD   ¡   r<   rD   c                   @   r=   )ÚCTRc                 C   r/   )Nznonce must be bytes)r3   r4   r5   Ú_nonce)r
   r   r   r   r   r8   µ   r9   zCTR.__init__rF   c                 C   s:   t | |ƒ t| jƒd |jkrtd t| jƒ| j¡ƒ‚d S )Nr&   z!Invalid nonce size ({0}) for {1}.)r%   r'   r   r(   r$   r)   r   r   r   r   r   r   ½   s   
ÿÿzCTR.validate_for_algorithmN)	r   r   r   r   r8   r   r;   r   r   r   r   r   r   rE   °   s
    
rE   c                   @   s>   e Zd Zd ZdZdZddd„Ze d¡Z	e d¡Z
d	d
„ ZdS )ÚGCMl   àÿ? l            Nr?   c                 C   s€   t |tƒs	tdƒ‚t|ƒdkrtdƒ‚|| _|d ur8t |tƒs#tdƒ‚|dk r+tdƒ‚t|ƒ|k r8td |¡ƒ‚|| _|| _d S )Nr1   r   z-initialization_vector must be at least 1 byteztag must be bytes or Noneé   zmin_tag_length must be >= 4z/Authentication tag must be {0} bytes or longer.)	r3   r4   r5   r'   r$   r6   r)   Ú_tagÚ_min_tag_length)r
   r   r    Úmin_tag_lengthr   r   r   r8   Í   s$   

ÿÿ
zGCM.__init__rI   r6   c                 C   s   t | |ƒ d S r+   )r%   r   r   r   r   r   æ   s   zGCM.validate_for_algorithm)Nr?   )r   r   r   r   Ú_MAX_ENCRYPTED_BYTESÚ_MAX_AAD_BYTESr8   r   r;   r    r   r   r   r   r   r   rG   Å   s    


rG   )Ú
__future__r   r   r   r   ÚsixÚcryptographyr   Úadd_metaclassÚABCMetaÚobjectr   r   r   r   r   r%   r*   r,   Úregister_interfacer.   r>   rA   rB   rC   rD   rE   rG   r   r   r   r   Ú<module>   sR   




