
    _f^                     R   d dl mZ 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 )    )annotationsN)AlreadyFinalizedAlreadyUpdatedNotYetFinalized)CipherAlgorithm)modes)_CipherContextc                  t    e Zd Zej        d
d            Zej        dd            Zej        dd            Zd	S )CipherContextdatabytesreturnc                    dS )zk
        Processes the provided bytes through the cipher and returns the results
        as bytes.
        N selfr   s     ]/var/www/html/env/lib/python3.11/site-packages/cryptography/hazmat/primitives/ciphers/base.pyupdatezCipherContext.update             bufintc                    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r   r   r   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname__abcabstractmethodr   r   r   r   r   r   r   r      s~            	    	     r   r   )	metaclassc                  0    e Zd Zej        dd            ZdS )AEADCipherContextr   r   r   Nonec                    dS )z3
        Authenticates the provided bytes.
        Nr   r   s     r   authenticate_additional_dataz.AEADCipherContext.authenticate_additional_data/   r   r   Nr   r   r   r*   )r"   r#   r$   r%   r&   r,   r   r   r   r)   r)   .   s6             r   r)   c                  0    e Zd Zej        dd            ZdS )AEADDecryptionContexttagr   r   c                    dS )z
        Returns the results of processing the final block as bytes and allows
        delayed passing of the authentication tag.
        Nr   )r   r0   s     r   finalize_with_tagz'AEADDecryptionContext.finalize_with_tag7   r   r   Nr0   r   r   r   )r"   r#   r$   r%   r&   r2   r   r   r   r/   r/   6   s6             r   r/   c                  @    e Zd Zeej        dd                        ZdS )AEADEncryptionContextr   r   c                    dS )zb
        Returns tag bytes. This is only available after encryption is
        finalized.
        Nr   r   s    r   r0   zAEADEncryptionContext.tag@   r   r   Nr!   )r"   r#   r$   propertyr%   r&   r0   r   r   r   r5   r5   ?   s@            X  r   r5   ModeT)bound	covariantc                      e Zd Z	 ddd
Zej        dd            Zej        d d            Zd Zej        d!d            Zej        d d            Zd Zd"dZdS )#CipherN	algorithmr   moder8   backend
typing.Anyr   r*   c                    t          |t                    st          d          |1t          |t          j                  sJ |                    |           || _        || _        d S )Nz&Expected interface of CipherAlgorithm.)
isinstancer   	TypeErrorr   r8   validate_for_algorithmr=   r>   )r   r=   r>   r?   s       r   __init__zCipher.__init__O   sl     )_55 	FDEEE dEJ/////''	222"			r   r   'Cipher[modes.ModeWithAuthenticationTag]r5   c                    d S Nr   r   s    r   	encryptorzCipher.encryptora   	     	r   _CIPHER_TYPEr   c                    d S rH   r   r   s    r   rI   zCipher.encryptorg   rJ   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   r?   Tencrypt)rB   r>   r   ModeWithAuthenticationTagr0   
ValueError,cryptography.hazmat.backends.openssl.backendr?   create_symmetric_encryption_ctxr=   	_wrap_ctxr   r?   ctxs      r   rI   zCipher.encryptorm   s    di!@AA 	y}( F   	IHHHHH55NDI
 
 ~~c4~000r   r/   c                    d S rH   r   r   s    r   	decryptorzCipher.decryptorz   rJ   r   c                    d S rH   r   r   s    r   rY   zCipher.decryptor   rJ   r   c                |    ddl m} |                    | j        | j                  }|                     |d          S )Nr   rN   FrO   )rS   r?   create_symmetric_decryption_ctxr=   r>   rU   rV   s      r   rY   zCipher.decryptor   sJ    HHHHHH55NDI
 
 ~~c5~111r   rW   _BackendCipherContextrP   boolItyping.Union[AEADEncryptionContext, AEADDecryptionContext, CipherContext]c                    t          | j        t          j                  r |rt	          |          S t          |          S t          |          S rH   )rB   r>   r   rQ   _AEADEncryptionContext_AEADDecryptionContextr	   )r   rW   rP   s      r   rU   zCipher._wrap_ctx   sM    
 di!@AA 	' 3-c222-c222!#&&&r   rH   )r=   r   r>   r8   r?   r@   r   r*   )r   rF   r   r5   )r   rK   r   r   )r   rF   r   r/   )rW   r]   rP   r^   r   r_   )	r"   r#   r$   rE   typingoverloadrI   rY   rU   r   r   r   r<   r<   N   s        
 #	    $ _   _
 _   _
1 1 1 _   _
 _   _
2 2 2' ' ' ' ' 'r   r<   c                  :    e Zd ZU ded<   ddZdd
ZddZddZdS )r	   &typing.Optional[_BackendCipherContext]_ctxrW   r]   r   r*   c                    || _         d S rH   )rg   r   rW   s     r   rE   z_CipherContext.__init__   s    			r   r   r   c                b    | j         t          d          | j                             |          S NContext was already finalized.)rg   r   r   r   s     r   r   z_CipherContext.update   s/    9"#CDDDy%%%r   r   r   c                d    | j         t          d          | j                             ||          S rk   )rg   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 rk   )rg   r   r   r   s     r   r   z_CipherContext.finalize   s8    9"#CDDDy!!##	r   NrW   r]   r   r*   r   r    r!   )r"   r#   r$   __annotations__rE   r   r   r   r   r   r   r	   r	      sr         0000   & & & &
0 0 0 0
     r   r	   c                  T    e Zd ZU ded<   ded<   dd	ZddZddZddZddZddZ	dS )_AEADCipherContextrf   rg   ztyping.Optional[bytes]_tagrW   r]   r   r*   c                L    || _         d| _        d| _        d | _        d| _        d S )Nr   F)rg   _bytes_processed_aad_bytes_processedrs   _updatedri   s     r   rE   z_AEADCipherContext.__init__   s+    	 !$%!	r   	data_sizer   c                   | j         t          d          d| _        | xj        |z  c_        | j        | j         j        j        k    rAt          d                    | j         j        j        | j         j        j                            d S )Nrl   Tz+{} has a maximum encrypted byte limit of {})	rg   r   rw   ru   _mode_MAX_ENCRYPTED_BYTESrR   formatname)r   rx   s     r   _check_limitz_AEADCipherContext._check_limit   s    9"#CDDD* 49?#GGG=DDIO($)/*N    HGr   r   r   c                    |                      t          |                     | j        J | j                            |          S rH   )r~   lenrg   r   r   s     r   r   z_AEADCipherContext.update   s@    #d))$$$y$$$y%%%r   r   c                    |                      t          |                     | j        J | j                            ||          S rH   )r~   r   rg   r   r   s      r   r   z_AEADCipherContext.update_into   sB    #d))$$$y$$$y$$T3///r   c                    | j         t          d          | j                                         }| j         j        | _        d | _         |S rk   )rg   r   r   r0   rs   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 )Nrl   z'Update has been called on this context.z%{} has a maximum AAD byte limit of {})rg   r   rw   r   rv   r   rz   _MAX_AAD_BYTESrR   r|   r}   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   Nro   )rx   r   r   r*   r   r    r!   r-   )
r"   r#   r$   rp   rE   r~   r   r   r   r,   r   r   r   rr   rr      s         0000       
 
 
 
& & & &0 0 0 0   5 5 5 5 5 5r   rr   c                      e Zd ZddZdS )rb   r0   r   r   c                    | j         t          d          | j                             |          }| j         j        | _        d | _         |S rk   )rg   r   r2   r0   rs   )r   r0   r   s      r   r2   z(_AEADDecryptionContext.finalize_with_tag   sE    9"#CDDDy**3//IM		r   Nr3   )r"   r#   r$   r2   r   r   r   rb   rb      s(             r   rb   c                  &    e Zd Zedd            ZdS )ra   r   r   c                N    | j         t          d          | j        J | j        S )Nz4You must finalize encryption before getting the tag.)rg   r   rs   r   s    r   r0   z_AEADEncryptionContext.tag  s7    9 !I   y$$$yr   Nr!   )r"   r#   r$   r7   r0   r   r   r   ra   ra     s2           X  r   ra   )#
__future__r   r%   rc   cryptography.exceptionsr   r   r   /cryptography.hazmat.primitives._cipheralgorithmr   &cryptography.hazmat.primitives.ciphersr   TYPE_CHECKING,cryptography.hazmat.backends.openssl.ciphersr	   r]   ABCMetar   r)   r/   r5   TypeVarOptionalr8   Genericr<   UnionModeWithNonceModeWithTweakECBModeWithInitializationVectorrK   rr   rb   ra   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   