a a @ s d dl Z d dlZd dlmZ d dlmZmZmZ d dlm Z d dl mZ G dd de jdZ G d d d e jdZG dd de jdZG d d de jdZG dd deZee G dd deZeeee eeG dd deZeeG dd deZdS ) N)utils)AlreadyFinalizedAlreadyUpdatedNotYetFinalized)CipherAlgorithm)modesc @ sL e Zd ZejeedddZejeedddZejedddZ d S ) CipherContextdatareturnc C s dS )zk Processes the provided bytes through the cipher and returns the results as bytes. N selfr r r Q/usr/lib64/python3.9/site-packages/cryptography/hazmat/primitives/ciphers/base.pyupdate s zCipherContext.updatec C s dS )z Processes the provided bytes and writes the resulting data into the provided buffer. Returns the number of bytes written. Nr r r bufr r r update_into s zCipherContext.update_intor c C s dS )zM Returns the results of processing the final block as bytes. Nr r r r r finalize" s zCipherContext.finalizeN) __name__ __module____qualname__abcabstractmethodbytesr intr r r r r r r s r ) metaclassc @ s" e Zd ZejeddddZdS )AEADCipherContextNr c C s dS )z3 Authenticates the provided bytes. Nr r r r r authenticate_additional_data* s z.AEADCipherContext.authenticate_additional_data)r r r r r r r r r r r r ) s r c @ s" e Zd ZejeedddZdS )AEADDecryptionContexttagr c C s dS )z Returns the results of processing the final block as bytes and allows delayed passing of the authentication tag. Nr )r r# r r r finalize_with_tag2 s z'AEADDecryptionContext.finalize_with_tagN)r r r r r r r$ r r r r r! 1 s r! c @ s e Zd ZejedddZdS )AEADEncryptionContextr c C s dS )zb Returns tag bytes. This is only available after encryption is finalized. Nr r r r r r# ; s zAEADEncryptionContext.tagN)r r r r abstractpropertyr r# r r r r r% : s r% c @ sB e Zd Zdeejej ejdddZ dd Z dd Zd d ZdS )CipherN) algorithmmodebackendc C s4 t |tstd|d ur$|| || _|| _d S )Nz&Expected interface of CipherAlgorithm.) isinstancer TypeErrorZvalidate_for_algorithmr( r) )r r( r) r* r r r __init__D s zCipher.__init__c C sL t | jtjr"| jjd ur"tdddlm} || j | j}| j |ddS )Nz0Authentication tag must be None when encrypting.r r* Tencrypt)r+ r) r ModeWithAuthenticationTagr# ValueError,cryptography.hazmat.backends.openssl.backendr* Zcreate_symmetric_encryption_ctxr( _wrap_ctxr r* ctxr r r encryptorT s zCipher.encryptorc C s* ddl m} || j| j}| j|ddS )Nr r. Fr/ )r3 r* Zcreate_symmetric_decryption_ctxr( r) r4 r5 r r r decryptora s zCipher.decryptorc C s0 t | jtjr$|rt|S t|S nt|S d S N)r+ r) r r1 _AEADEncryptionContext_AEADCipherContext_CipherContext)r r6 r0 r r r r4 i s zCipher._wrap_ctx)N) r r r r typingOptionalr ZModeAnyr- r7 r8 r4 r r r r r' C s r' c @ sB e Zd Zdd ZeedddZeedddZedd d ZdS )r<