
    .Ph~                     $   d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZ  G d dej        	          Z G d
 deej        	          Z G d deej        	          Z G d deej        	          Z G d deej        	          Zd0dZd1dZd2dZd3dZ G d  d!e          Z G d" d#e          Z G d$ d%e          Z G d& d'e          Z G d( d)e          Z G d* d+e          Z G d, d-e          Z G d. d/ee          ZdS )4    )annotationsN)utils)UnsupportedAlgorithm_Reasons)BlockCipherAlgorithmCipherAlgorithm)
algorithmsc                  b    e Zd Zeej        d	d                        Zej        d
d            ZdS )Modereturnstrc                    dS )z@
        A string naming this mode (e.g. "ECB", "CBC").
        N selfs    l/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/modes.pynamez	Mode.name             	algorithmr   Nonec                    dS )zq
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        Nr   r   r   s     r   validate_for_algorithmzMode.validate_for_algorithm   r   r   N)r   r   r   r   r   r   )__name__
__module____qualname__propertyabcabstractmethodr   r   r   r   r   r   r      sd            X
 	     r   r   )	metaclassc                  @    e Zd Zeej        dd                        ZdS )ModeWithInitializationVectorr   utils.Bufferc                    dS )zP
        The value of the initialization vector for this mode as bytes.
        Nr   r   s    r   initialization_vectorz2ModeWithInitializationVector.initialization_vector#   r   r   Nr   r%   )r   r   r   r   r    r!   r'   r   r   r   r$   r$   "   @            X  r   r$   c                  @    e Zd Zeej        dd                        ZdS )ModeWithTweakr   r%   c                    dS )z@
        The value of the tweak for this mode as bytes.
        Nr   r   s    r   tweakzModeWithTweak.tweak,   r   r   Nr(   )r   r   r   r   r    r!   r-   r   r   r   r+   r+   +   r)   r   r+   c                  @    e Zd Zeej        dd                        ZdS )ModeWithNoncer   r%   c                    dS )z@
        The value of the nonce for this mode as bytes.
        Nr   r   s    r   noncezModeWithNonce.nonce5   r   r   Nr(   )r   r   r   r   r    r!   r1   r   r   r   r/   r/   4   r)   r   r/   c                  @    e Zd Zeej        dd                        ZdS )ModeWithAuthenticationTagr   bytes | Nonec                    dS )zP
        The value of the tag supplied to the constructor of this mode.
        Nr   r   s    r   tagzModeWithAuthenticationTag.tag>   r   r   Nr   r4   )r   r   r   r   r    r!   r6   r   r   r   r3   r3   =   r)   r   r3   r   r   r   r   r   c                T    |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   s     r   _check_aes_key_lengthr=   F   s?    CINe$;$;K
 
 	
  $;$;r   r   c                    t          | j                  }|dz  |j        k    rt          d| d| j         d          d S )N   zInvalid IV size () for .)lenr'   
block_sizer<   r   )r   r   iv_lens      r   _check_iv_lengthrE   M   sR     +,,FzY)))GVGG49GGGHHH *)r   r1   r%   r   r   c                    t          |t                    st          | dt          j                  t          |           dz  |j        k    r#t          dt          |            d| d          d S )N" requires a block cipher algorithmr?   zInvalid nonce size (r@   rA   )
isinstancer   r   r   UNSUPPORTED_CIPHERrB   rC   r<   )r1   r   r   s      r   _check_nonce_lengthrJ   U   s     i!566 
"777'
 
 	
 5zzA~---IE

II$IIIJJJ .-r   c                    t          |t                    st          |  dt          j                  t          | |           t          | |           d S )NrG   )rH   r   r   r   rI   r=   rE   r   s     r   _check_iv_and_key_lengthrL   a   sc     i!566 
"777'
 
 	
 $	***T9%%%%%r   c                  6    e Zd Zd ZddZedd            ZeZdS )	CBCr'   r%   c                >    t          j        d|           || _        d S Nr'   r   _check_byteslike_initialization_vectorr   r'   s     r   __init__zCBC.__init__p   %    68MNNN&;###r   r   c                    | j         S NrS   r   s    r   r'   zCBC.initialization_vectort       **r   Nr'   r%   r(   	r   r   r   r   rU   r   r'   rL   r   r   r   r   rN   rN   m   Q        D< < < < + + + X+ 6r   rN   c                  :    e Zd Zd ZddZedd            Zdd	Zd
S )XTSr-   r%   c                    t          j        d|           t          |          dk    rt          d          || _        d S )Nr-      z!tweak must be 128-bits (16 bytes))r   rR   rB   r<   _tweak)r   r-   s     r   rU   zXTS.__init__~   s@    w...u::@AAAr   r   c                    | j         S rX   )rb   r   s    r   r-   z	XTS.tweak   
    {r   r   r   r   c                    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.)r9   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)rH   r	   AES128AES256	TypeErrorr;   r<   r   s     r   r   zXTS.validate_for_algorithm   se    i*"3Z5F!GHH 	2  
 Z//3   0/r   N)r-   r%   r(   r   )r   r   r   r   rU   r   r-   r   r   r   r   r_   r_   {   sa        D       X     r   r_   c                      e Zd Zd ZeZdS )ECBN)r   r   r   r   r=   r   r   r   r   rj   rj      s        D2r   rj   c                  6    e Zd Zd ZddZedd            ZeZdS )	OFBr'   r%   c                >    t          j        d|           || _        d S rP   rQ   rT   s     r   rU   zOFB.__init__   rV   r   r   c                    | j         S rX   rY   r   s    r   r'   zOFB.initialization_vector   rZ   r   Nr[   r(   r\   r   r   r   rl   rl      r]   r   rl   c                  6    e Zd Zd ZddZedd            ZeZdS )	CFBr'   r%   c                >    t          j        d|           || _        d S rP   rQ   rT   s     r   rU   zCFB.__init__   rV   r   r   c                    | j         S rX   rY   r   s    r   r'   zCFB.initialization_vector   rZ   r   Nr[   r(   r\   r   r   r   rp   rp      r]   r   rp   c                  6    e Zd Zd ZddZedd            ZeZdS )	CFB8r'   r%   c                >    t          j        d|           || _        d S rP   rQ   rT   s     r   rU   zCFB8.__init__   rV   r   r   c                    | j         S rX   rY   r   s    r   r'   zCFB8.initialization_vector   rZ   r   Nr[   r(   r\   r   r   r   rt   rt      sQ        D< < < < + + + X+ 6r   rt   c                  :    e Zd Zd ZddZedd            Zdd	Zd
S )CTRr1   r%   c                >    t          j        d|           || _        d S )Nr1   )r   rR   _nonce)r   r1   s     r   rU   zCTR.__init__   s     w...r   r   c                    | j         S rX   )rz   r   s    r   r1   z	CTR.nonce   rd   r   r   r   r   c                \    t          | |           t          | j        | j        |           d S rX   )r=   rJ   r1   r   r   s     r   r   zCTR.validate_for_algorithm   s.    dI...DJ	9=====r   N)r1   r%   r(   r   )r   r   r   r   rU   r   r1   r   r   r   r   rx   rx      sa        D       X> > > > > >r   rx   c                  `    e Zd Zd ZdZdZ	 	 dddZedd            Zedd            Z	ddZ
dS )GCMl   ? l            Nra   r'   r%   r6   r4   min_tag_lengthintc                h   t          j        d|           t          |          dk     st          |          dk    rt          d          || _        |Pt          j        d|           |dk     rt          d          t          |          |k     rt          d| d	          || _        || _        d S )
Nr'   r?      zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).r6      zmin_tag_length must be >= 4zAuthentication tag must be z bytes or longer.)r   rR   rB   r<   rS   _check_bytes_tag_min_tag_length)r   r'   r6   r   s       r   rU   zGCM.__init__   s     	68MNNN$%%))S1F-G-G#-M-M"   '<#?uc***!! !>???3xx.(( .      	-r   r   c                    | j         S rX   )r   r   s    r   r6   zGCM.tag   s
    yr   c                    | j         S rX   rY   r   s    r   r'   zGCM.initialization_vector   rZ   r   r   r   r   c                    t          | |           t          |t                    st          dt          j                  |j        dz  }| j        +t          | j                  |k    rt          d| d          d S d S )Nz%GCM requires a block cipher algorithmr?   z'Authentication tag cannot be more than z bytes.)
r=   rH   r   r   r   rI   rC   r   rB   r<   )r   r   block_size_bytess      r   r   zGCM.validate_for_algorithm   s    dI...)%9:: 	&7+   %/149 S^^6F%F%F:J      ! %F%Fr   )Nra   )r'   r%   r6   r4   r   r   r7   r(   r   )r   r   r   r   _MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESrU   r   r6   r'   r   r   r   r   r~   r~      s        D-!N
 ! 	. . . . .6    X + + + X+     r   r~   )r   r   r   r   r   r   )r   r$   r   r   r   r   )r1   r%   r   r   r   r   r   r   )r   r$   r   r   r   r   )
__future__r   r    cryptographyr   cryptography.exceptionsr   r   /cryptography.hazmat.primitives._cipheralgorithmr   r   &cryptography.hazmat.primitives.ciphersr	   ABCMetar   r$   r+   r/   r3   r=   rE   rJ   rL   rN   r_   rj   rl   rp   rt   rx   r~   r   r   r   <module>r      s?  
 # " " " " " 



       B B B B B B B B        > = = = = =    S[         43;        DCK        DCK            
 
 
 
I I I I	K 	K 	K 	K	& 	& 	& 	&6 6 6 6 6
& 6 6 6    -   :3 3 3 3 3$ 3 3 36 6 6 6 6
& 6 6 66 6 6 6 6
& 6 6 66 6 6 6 6' 6 6 6> > > > >- > > > 4 4 4 4 4
&(A 4 4 4 4 4r   