
     hM                      F   d dl Z d dlZd dlmZmZmZ d dlmZ d dlm	Z	 ej
        r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 ej        dej        e	j                 d          Z G d dej        e                   Zeej        e	j        e	j        de	j        e	j        f                  Z G d de          Z G d de          Z G d dee          Z G d dee          Z dS )    N)AlreadyFinalizedAlreadyUpdatedNotYetFinalized)CipherAlgorithm)modes)_CipherContextc                       e Zd Zej        dedefd            Zej        dededefd            Zej        defd            Z	dS )CipherContextdatareturnc                     dS )zk
        Processes the provided bytes through the cipher and returns the results
        as bytes.
        N selfr   s     g/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.pyupdatezCipherContext.update             bufc                     dS )z
        Processes the provided bytes and writes the resulting data into the
        provided buffer. Returns the number of bytes written.
        Nr   r   r   r   s      r   update_intozCipherContext.update_into   r   r   c                     dS )zM
        Returns the results of processing the final block as bytes.
        Nr   r   s    r   finalizezCipherContext.finalize&   r   r   N)
__name__
__module____qualname__abcabstractmethodbytesr   intr   r   r   r   r   r
   r
      s        5 U     	 E c     	%      r   r
   )	metaclassc                   8    e Zd Zej        deddfd            ZdS )AEADCipherContextr   r   Nc                     dS )z3
        Authenticates the provided bytes.
        Nr   r   s     r   authenticate_additional_dataz.AEADCipherContext.authenticate_additional_data.   r   r   )r   r   r   r   r    r!   r'   r   r   r   r%   r%   -   sD         4      r   r%   c                   8    e Zd Zej        dedefd            ZdS )AEADDecryptionContexttagr   c                     dS )z
        Returns the results of processing the final block as bytes and allows
        delayed passing of the authentication tag.
        Nr   )r   r*   s     r   finalize_with_tagz'AEADDecryptionContext.finalize_with_tag6   r   r   N)r   r   r   r   r    r!   r,   r   r   r   r)   r)   5   sD        U u      r   r)   c                   D    e Zd Zeej        defd                        ZdS )AEADEncryptionContextr   c                     dS )zb
        Returns tag bytes. This is only available after encryption is
        finalized.
        Nr   r   s    r   r*   zAEADEncryptionContext.tag?   r   r   N)r   r   r   propertyr   r    r!   r*   r   r   r   r.   r.   >   sG        U     X  r   r.   ModeT)bound	covariantc            	          e Zd Z	 ddededej        ddfdZej        ddde	fd	            Z
ej        dd
defd            Z
d Z
ej        dddefd            Zej        dd
defd            Zd Zdddedej        e	eef         fdZdS )CipherN	algorithmmodebackendr   c                     t          |t                    st          d          |1t          |t          j                  sJ |                    |           || _        || _        d S )Nz&Expected interface of CipherAlgorithm.)
isinstancer   	TypeErrorr   r1   validate_for_algorithmr6   r7   )r   r6   r7   r8   s       r   __init__zCipher.__init__N   sl     )_55 	FDEEE dEJ/////''	222"			r   r   z'Cipher[modes.ModeWithAuthenticationTag]c                     d S Nr   r   s    r   	encryptorzCipher.encryptor`   	     	r   _CIPHER_TYPEc                     d S r?   r   r   s    r   r@   zCipher.encryptorf   rA   r   c                     t          | j        t          j                  r| j        j        t          d          ddlm} |                    | j	        | j                  }| 
                    |d          S )Nz0Authentication tag must be None when encrypting.r   r8   Tencrypt)r:   r7   r   ModeWithAuthenticationTagr*   
ValueError,cryptography.hazmat.backends.openssl.backendr8   create_symmetric_encryption_ctxr6   	_wrap_ctxr   r8   ctxs      r   r@   zCipher.encryptorl   s    di!@AA 	y}( F   	IHHHHH55NDI
 
 ~~c4~000r   c                     d S r?   r   r   s    r   	decryptorzCipher.decryptory   rA   r   c                     d S r?   r   r   s    r   rP   zCipher.decryptor   rA   r   c                 |    ddl m} |                    | j        | j                  }|                     |d          S )Nr   rE   FrF   )rJ   r8   create_symmetric_decryption_ctxr6   r7   rL   rM   s      r   rP   zCipher.decryptor   sJ    HHHHHH55NDI
 
 ~~c5~111r   rN   _BackendCipherContextrG   c                     t          | j        t          j                  r |rt	          |          S t          |          S t          |          S r?   )r:   r7   r   rH   _AEADEncryptionContext_AEADDecryptionContextr   )r   rN   rG   s      r   rL   zCipher._wrap_ctx   sM    
 di!@AA 	' 3-c222-c222!#&&&r   r?   )r   r   r   r   r1   typingAnyr=   overloadr.   r@   r
   r)   rP   boolUnionrL   r   r   r   r5   r5   M   s~       
 #	 "  	
 
   $ _7	   _
 _	   _
1 1 1 _7	   _
 _	   _
2 2 2'*'59'	4mC
' ' ' ' ' 'r   r5   c                   h    e Zd ZU ej        d         ed<   ddZdedefdZded	ede	fd
Z
defdZdS )r   rT   _ctxrN   r   Nc                     || _         d S r?   )r^   r   rN   s     r   r=   z_CipherContext.__init__   s    			r   r   c                 b    | j         t          d          | j                             |          S NContext was already finalized.)r^   r   r   r   s     r   r   z_CipherContext.update   s/    9"#CDDDy%%%r   r   c                 d    | j         t          d          | j                             ||          S rb   )r^   r   r   r   s      r   r   z_CipherContext.update_into   s1    9"#CDDDy$$T3///r   c                 r    | j         t          d          | j                                         }d | _         |S rb   )r^   r   r   r   s     r   r   z_CipherContext.finalize   s8    9"#CDDDy!!##	r   rN   rT   r   N)r   r   r   rX   Optional__annotations__r=   r!   r   r"   r   r   r   r   r   r   r      s         
/1
2222   &5 &U & & & &
0 0E 0c 0 0 0 0
%      r   r   c                       e Zd ZU ej        d         ed<   ej        e         ed<   ddZdeddfd	Z	d
edefdZ
d
ededefdZdefdZd
eddfdZdS )_AEADCipherContextrT   r^   _tagrN   r   Nc                 L    || _         d| _        d| _        d | _        d| _        d S )Nr   F)r^   _bytes_processed_aad_bytes_processedrk   _updatedr`   s     r   r=   z_AEADCipherContext.__init__   s+    	 !$%!	r   	data_sizec                    | j         t          d          d| _        | xj        |z  c_        | j        | j         j        j        k    rAt          d                    | j         j        j        | j         j        j                            d S )Nrc   Tz+{} has a maximum encrypted byte limit of {})	r^   r   ro   rm   _mode_MAX_ENCRYPTED_BYTESrI   formatname)r   rp   s     r   _check_limitz_AEADCipherContext._check_limit   s    9"#CDDD* 49?#GGG=DDIO($)/*N    HGr   r   c                     |                      t          |                     | j        J | j                            |          S r?   )rv   lenr^   r   r   s     r   r   z_AEADCipherContext.update   s@    #d))$$$y$$$y%%%r   r   c                     |                      t          |                     | j        J | j                            ||          S r?   )rv   rx   r^   r   r   s      r   r   z_AEADCipherContext.update_into   sB    #d))$$$y$$$y$$T3///r   c                     | j         t          d          | j                                         }| j         j        | _        d | _         |S rb   )r^   r   r   r*   rk   r   s     r   r   z_AEADCipherContext.finalize   sC    9"#CDDDy!!##IM		r   c                    | j         t          d          | j        rt          d          | xj        t          |          z  c_        | j        | j         j        j        k    rAt          d	                    | j         j        j
        | j         j        j                            | j                             |           d S )Nrc   z'Update has been called on this context.z%{} has a maximum AAD byte limit of {})r^   r   ro   r   rn   rx   rr   _MAX_AAD_BYTESrI   rt   ru   r'   r   s     r   r'   z/_AEADCipherContext.authenticate_additional_data   s    9"#CDDD= 	L !JKKK!!SYY.!!$ty'EEE7>>IO($)/*H    		..t44444r   rf   )r   r   r   rX   rg   rh   r!   r=   r"   rv   r   r   r   r'   r   r   r   rj   rj      s         
/1
2222
/%
       
c 
d 
 
 
 
&5 &U & & & &0 0E 0c 0 0 0 0%    5 54 5 5 5 5 5 5r   rj   c                       e Zd ZdedefdZdS )rW   r*   r   c                     | j         t          d          | j                             |          }| j         j        | _        d | _         |S rb   )r^   r   r,   r*   rk   )r   r*   r   s      r   r,   z(_AEADDecryptionContext.finalize_with_tag   sE    9"#CDDDy**3//IM		r   N)r   r   r   r!   r,   r   r   r   rW   rW      s6        U u      r   rW   c                   *    e Zd Zedefd            ZdS )rV   r   c                 N    | j         t          d          | j        J | j        S )Nz4You must finalize encryption before getting the tag.)r^   r   rk   r   s    r   r*   z_AEADEncryptionContext.tag  s7    9 !I   y$$$yr   N)r   r   r   r0   r!   r*   r   r   r   rV   rV     s9        U    X  r   rV   )!r   rX   cryptography.exceptionsr   r   r   /cryptography.hazmat.primitives._cipheralgorithmr   &cryptography.hazmat.primitives.ciphersr   TYPE_CHECKING,cryptography.hazmat.backends.openssl.ciphersr   rT   ABCMetar
   r%   r)   r.   TypeVarrg   r1   Genericr5   r\   ModeWithNonceModeWithTweakECBModeWithInitializationVectorrB   rj   rW   rV   r   r   r   <module>r      s   


          
 L K K K K K 8 8 8 8 8 8	      
    ck    ,            -        -     v~
&/%*-  
K' K' K' K' K'V^D! K' K' K'\ 
L	*		,    ]   095 95 95 95 95* 95 95 95x    /1F       /1F     r   