U
    ʹh                     @  s  d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ G dd dejd	ZG d
d deejd	ZG dd deejd	ZG dd deejd	Zejdeje
j ddZG dd deje Zeeje
je
je
je
jdf  Zeejj eejj eejj dS )    )annotationsN)openssl)CipherAlgorithm)modes)Bufferc                   @  sd   e Zd ZejdddddZejdddddd	Zejdd
ddZejdddddZdS )CipherContextr   bytesdatareturnc                 C  s   dS )zk
        Processes the provided bytes through the cipher and returns the results
        as bytes.
        N selfr
   r   r   Q./venv/lib/python3.8/site-packages/cryptography/hazmat/primitives/ciphers/base.pyupdate   s    zCipherContext.updateint)r
   bufr   c                 C  s   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   r   r   r   update_into   s    zCipherContext.update_intor   c                 C  s   dS )zM
        Returns the results of processing the final block as bytes.
        Nr   r   r   r   r   finalize   s    zCipherContext.finalizeNone)noncer   c                 C  s   dS )z
        Resets the nonce for the cipher context to the provided value.
        Raises an exception if it does not support reset or if the
        provided nonce does not have a valid length.
        Nr   )r   r   r   r   r   reset_nonce%   s    zCipherContext.reset_nonceN)	__name__
__module____qualname__abcabstractmethodr   r   r   r   r   r   r   r   r      s   r   )	metaclassc                   @  s"   e Zd ZejdddddZdS )AEADCipherContextr   r   r	   c                 C  s   dS )z3
        Authenticates the provided bytes.
        Nr   r   r   r   r   authenticate_additional_data/   s    z.AEADCipherContext.authenticate_additional_dataN)r   r   r   r   r   r!   r   r   r   r   r    .   s   r    c                   @  s"   e Zd ZejdddddZdS )AEADDecryptionContextr   )tagr   c                 C  s   dS )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_tag7   s    z'AEADDecryptionContext.finalize_with_tagN)r   r   r   r   r   r$   r   r   r   r   r"   6   s   r"   c                   @  s$   e Zd ZeejddddZdS )AEADEncryptionContextr   r   c                 C  s   dS )zb
        Returns tag bytes. This is only available after encryption is
        finalized.
        Nr   r   r   r   r   r#   @   s    zAEADEncryptionContext.tagN)r   r   r   propertyr   r   r#   r   r   r   r   r%   ?   s   r%   ModeT)ZboundZ	covariantc                   @  s   e Zd ZddddddddZejd	d
dddZejdddddZdd Zejd	ddddZejdddddZdd ZdS )CipherNr   r'   z
typing.Anyr   )	algorithmmodebackendr   c                 C  sD   t |tstd|d k	r4t |tjs*t|| || _|| _d S )Nz&Expected interface of CipherAlgorithm.)	
isinstancer   	TypeErrorr   r'   AssertionErrorZvalidate_for_algorithmr)   r*   )r   r)   r*   r+   r   r   r   __init__O   s    

zCipher.__init__z'Cipher[modes.ModeWithAuthenticationTag]r%   )r   r   c                 C  s   d S Nr   r   r   r   r   	encryptora   s    zCipher.encryptor_CIPHER_TYPEr   c                 C  s   d S r0   r   r   r   r   r   r1   f   s    c                 C  s4   t | jtjr"| jjd k	r"tdtj| j	| jS )Nz0Authentication tag must be None when encrypting.)
r,   r*   r   ZModeWithAuthenticationTagr#   
ValueErrorrust_opensslciphersZcreate_encryption_ctxr)   r   r   r   r   r1   k   s     r"   c                 C  s   d S r0   r   r   r   r   r   	decryptorv   s    zCipher.decryptorc                 C  s   d S r0   r   r   r   r   r   r6   {   s    c                 C  s   t j| j| jS r0   )r4   r5   Zcreate_decryption_ctxr)   r*   r   r   r   r   r6      s     )N)r   r   r   r/   typingZoverloadr1   r6   r   r   r   r   r(   N   s    r(   )Z
__future__r   r   r7   Z"cryptography.hazmat.bindings._rustr   r4   Z/cryptography.hazmat.primitives._cipheralgorithmr   Z&cryptography.hazmat.primitives.ciphersr   Zcryptography.utilsr   ABCMetar   r    r"   r%   ZTypeVarZOptionalr'   ZGenericr(   ZUnionZModeWithNonceZModeWithTweakZECBZModeWithInitializationVectorr2   registerr5   r   r   r   r   <module>   s:   	
 
 8
