
     h                      T   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dede	ddfdZdededdfdZdedede	ddfdZdede	ddfd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 )*    N)utils)UnsupportedAlgorithm_Reasons)BlockCipherAlgorithmCipherAlgorithm)
algorithmsc                   n    e Zd Zeej        defd                        Zej        deddfd            Z	dS )Modereturnc                     dS )z@
        A string naming this mode (e.g. "ECB", "CBC").
        N selfs    h/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/modes.pynamez	Mode.name             	algorithmNc                     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   )
__name__
__module____qualname__propertyabcabstractmethodstrr   r   r   r   r   r   r
   r
      sy        c     X
 	 D      r   r
   )	metaclassc                   D    e Zd Zeej        defd                        ZdS )ModeWithInitializationVectorr   c                     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   bytesr#   r   r   r   r!   r!   "   sG        u     X  r   r!   c                   D    e Zd Zeej        defd                        ZdS )ModeWithTweakr   c                     dS )z@
        The value of the tweak for this mode as bytes.
        Nr   r   s    r   tweakzModeWithTweak.tweak,   r   r   N)r   r   r   r   r   r   r$   r(   r   r   r   r&   r&   +   G        u     X  r   r&   c                   D    e Zd Zeej        defd                        ZdS )ModeWithNoncer   c                     dS )z@
        The value of the nonce for this mode as bytes.
        Nr   r   s    r   noncezModeWithNonce.nonce5   r   r   N)r   r   r   r   r   r   r$   r-   r   r   r   r+   r+   4   r)   r   r+   c                   Z    e Zd Zeej        dej        e         fd                        Z	dS )ModeWithAuthenticationTagr   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   r   r   r   r   r   typingOptionalr$   r1   r   r   r   r/   r/   =   sN        V_U+     X  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_lengthr9   F   s?    CINe$;$;K
 
 	
  $;$;r   c                     t          | j                  dz  |j        k    r:t          d                    t          | j                  | j                            d S )N   zInvalid IV size ({}) for {}.)lenr#   
block_sizer8   formatr   r   s     r   _check_iv_lengthr?   M   sb     4%&&*i.BBB*11D.// 
 
 	
 CBr   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<   r=   r8   )r-   r   r   s      r   _check_nonce_lengthrE   X   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 )NrA   )rC   r   r   r   rD   r9   r?   r   s     r   _check_iv_and_key_lengthrG   d   sc     i!566 
"777'
 
 	
 $	***T9%%%%%r   c                   >    e Zd Zd ZdefdZedefd            ZeZ	dS )CBCr#   c                 >    t          j        d|           || _        d S Nr#   r   _check_byteslike_initialization_vectorr   r#   s     r   __init__zCBC.__init__s   %    68MNNN&;###r   r   c                     | j         S NrN   r   s    r   r#   zCBC.initialization_vectorw       **r   N
r   r   r   r   r$   rP   r   r#   rG   r   r   r   r   rI   rI   p   _        D<e < < < < +u + + + X+ 6r   rI   c                   J    e Zd Zd ZdefdZedefd            ZdeddfdZ	dS )XTSr(   c                     t          j        d|           t          |          dk    rt          d          || _        d S )Nr(      z!tweak must be 128-bits (16 bytes))r   rM   r<   r8   _tweak)r   r(   s     r   rP   zXTS.__init__   s@    w...u::@AAAr   r   c                     | j         S rS   )r\   r   s    r   r(   z	XTS.tweak   
    {r   r   Nc                     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.)r5   i   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)rC   r   AES128AES256	TypeErrorr7   r8   r   s     r   r   zXTS.validate_for_algorithm   se    i*"3Z5F!GHH 	2  
 Z//3   0/r   )
r   r   r   r   r$   rP   r   r(   r   r   r   r   r   rY   rY   ~   s}        De     u    X D      r   rY   c                       e Zd Zd ZeZdS )ECBN)r   r   r   r   r9   r   r   r   r   rd   rd      s        D2r   rd   c                   >    e Zd Zd ZdefdZedefd            ZeZ	dS )OFBr#   c                 >    t          j        d|           || _        d S rK   rL   rO   s     r   rP   zOFB.__init__   rQ   r   r   c                     | j         S rS   rT   r   s    r   r#   zOFB.initialization_vector   rU   r   NrV   r   r   r   rf   rf      rW   r   rf   c                   >    e Zd Zd ZdefdZedefd            ZeZ	dS )CFBr#   c                 >    t          j        d|           || _        d S rK   rL   rO   s     r   rP   zCFB.__init__   rQ   r   r   c                     | j         S rS   rT   r   s    r   r#   zCFB.initialization_vector   rU   r   NrV   r   r   r   rj   rj      rW   r   rj   c                   >    e Zd Zd ZdefdZedefd            ZeZ	dS )CFB8r#   c                 >    t          j        d|           || _        d S rK   rL   rO   s     r   rP   zCFB8.__init__   rQ   r   r   c                     | j         S rS   rT   r   s    r   r#   zCFB8.initialization_vector   rU   r   NrV   r   r   r   rn   rn      s_        D<e < < < < +u + + + X+ 6r   rn   c                   J    e Zd Zd ZdefdZedefd            ZdeddfdZ	dS )CTRr-   c                 >    t          j        d|           || _        d S )Nr-   )r   rM   _nonce)r   r-   s     r   rP   zCTR.__init__   s     w...r   r   c                     | j         S rS   )rt   r   s    r   r-   z	CTR.nonce   r^   r   r   Nc                 \    t          | |           t          | j        | j        |           d S rS   )r9   rE   r-   r   r   s     r   r   zCTR.validate_for_algorithm   s.    dI...DJ	9=====r   )
r   r   r   r   r$   rP   r   r-   r   r   r   r   r   rr   rr      s}        De     u    X> >D > > > > > >r   rr   c                       e Zd Zd ZdZdZ	 	 ddedej        e         de	fdZ
ed	ej        e         fd
            Zed	efd            Zded	dfdZdS )GCMl   ? l            Nr[   r#   r1   min_tag_lengthc                    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).r1      zmin_tag_length must be >= 4z.Authentication tag must be {} bytes or longer.)	r   rM   r<   r8   rN   _check_bytesr>   _tag_min_tag_length)r   r#   r1   ry   s       r   rP   zGCM.__init__   s     	68MNNN$%%))S1F-G-G#-M-M"   '<#?uc***!! !>???3xx.(( DKK&   
 	-r   r   c                     | j         S rS   )r~   r   s    r   r1   zGCM.tag   s
    yr   c                     | j         S rS   rT   r   s    r   r#   zGCM.initialization_vector   rU   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.)r9   rC   r   r   r   rD   r=   r~   r<   r8   r>   )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   r   r   _MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESr$   r2   r3   intrP   r   r1   r#   r   r   r   r   r   rx   rx      s        D-!N
 '+ 	. .$. _U#. 	. . . .8 V_U+    X +u + + + X+ D      r   rx   ) r   r2   cryptographyr   cryptography.exceptionsr   r   /cryptography.hazmat.primitives._cipheralgorithmr   r   &cryptography.hazmat.primitives.ciphersr   ABCMetar
   r!   r&   r+   r/   r9   r?   r$   r   rE   rG   rI   rY   rd   rf   rj   rn   rr   rx   r   r   r   <module>r      s   


        B B B B B B B B        > = = = = =    S[         43;        DCK        DCK            
 
 
T 
 
 
 


&
3G
	
 
 
 
	K	K	K(7	K		K 	K 	K 	K	&
&	&3B	&		& 	& 	& 	&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   