
    _f                     ,   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 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    ^/var/www/html/env/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   bytesc                    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.nonce6   r   r   Nr(   )r   r   r   r   r    r!   r1   r   r   r   r/   r/   5   r)   r   r/   c                  @    e Zd Zeej        dd                        ZdS )ModeWithAuthenticationTagr   typing.Optional[bytes]c                    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=   G   s?    CINe$;$;K
 
 	
  $;$;r   r   c                    t          | j                  dz  |j        k    r:t          d                    t          | j                  | j                            d S )N   zInvalid IV size ({}) for {}.)lenr'   
block_sizer<   formatr   r   s     r   _check_iv_lengthrC   N   sb     4%&&*i.BBB*11D.// 
 
 	
 CBr   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 (z) for .)
isinstancer   r   r   UNSUPPORTED_CIPHERr@   rA   r<   )r1   r   r   s      r   _check_nonce_lengthrI   Y   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 )NrE   )rG   r   r   r   rH   r=   rC   r   s     r   _check_iv_and_key_lengthrK   e   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__t   %    68MNNN&;###r   r   c                    | j         S NrR   r   s    r   r'   zCBC.initialization_vectorx       **r   Nr'   r%   r(   	r   r   r   r   rT   r   r'   rK   r   r   r   r   rM   rM   q   Q        D< < < < + + + X+ 6r   rM   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   rQ   r@   r<   _tweak)r   r-   s     r   rT   zXTS.__init__   s@    w...u::@AAAr   r   c                    | j         S rW   )ra   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)rG   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   rT   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   ri   ri      s        D2r   ri   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 rO   rP   rS   s     r   rT   zOFB.__init__   rU   r   r   c                    | j         S rW   rX   r   s    r   r'   zOFB.initialization_vector   rY   r   NrZ   r(   r[   r   r   r   rk   rk      r\   r   rk   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 rO   rP   rS   s     r   rT   zCFB.__init__   rU   r   r   c                    | j         S rW   rX   r   s    r   r'   zCFB.initialization_vector   rY   r   NrZ   r(   r[   r   r   r   ro   ro      r\   r   ro   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 rO   rP   rS   s     r   rT   zCFB8.__init__   rU   r   r   c                    | j         S rW   rX   r   s    r   r'   zCFB8.initialization_vector   rY   r   NrZ   r(   r[   r   r   r   rs   rs      sQ        D< < < < + + + X+ 6r   rs   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   rQ   _nonce)r   r1   s     r   rT   zCTR.__init__   s     w...r   r   c                    | j         S rW   )ry   r   s    r   r1   z	CTR.nonce   rc   r   r   r   r   c                \    t          | |           t          | j        | j        |           d S rW   )r=   rI   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   rT   r   r1   r   r   r   r   rw   rw      sa        D       X> > > > > >r   rw   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            Nr`   r'   r%   r6   r4   min_tag_lengthintc                   t          j        d|           t          |          dk     st          |          dk    rt          d          || _        |_t          j        d|           |dk     rt          d          t          |          |k     r"t          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 {} bytes or longer.)	r   rQ   r@   r<   rR   _check_bytesrB   _tag_min_tag_length)r   r'   r6   r~   s       r   rT   zGCM.__init__   s     	68MNNN$%%))S1F-G-G#-M-M"   '<#?uc***!! !>???3xx.(( DKK&   
 	-r   r   c                    | j         S rW   )r   r   s    r   r6   zGCM.tag   s
    yr   c                    | j         S rW   rX   r   s    r   r'   zGCM.initialization_vector  rY   r   r   r   r   c                   t          | |           t          |t                    st          dt          j                  |j        dz  }| j        :t          | j                  |k    r$t          d
                    |                    d S d S )Nz%GCM requires a block cipher algorithmr?   z0Authentication tag cannot be more than {} bytes.)r=   rG   r   r   r   rH   rA   r   r@   r<   rB   )r   r   block_size_bytess      r   r   zGCM.validate_for_algorithm  s    dI...)%9:: 	&7+   %/149 S^^6F%F%FBII$    ! %F%Fr   )Nr`   )r'   r%   r6   r4   r~   r   r7   r(   r   )r   r   r   r   _MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESrT   r   r6   r'   r   r   r   r   r}   r}      s        D-!N
 '+ 	. . . . .8    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    typingcryptographyr   cryptography.exceptionsr   r   /cryptography.hazmat.primitives._cipheralgorithmr   r   &cryptography.hazmat.primitives.ciphersr	   ABCMetar   r$   r+   r/   r3   r=   rC   rI   rK   rM   r^   ri   rk   ro   rs   rw   r}   r   r   r   <module>r      sD  
 # " " " " " 



        B B B B B B B B        > = = = = =    S[         43;        DCK        DCK            
 
 
 

 
 
 
	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> > > > >- > > > 6 6 6 6 6
&(A 6 6 6 6 6r   