o
    àý°j�  ã                   @  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                   @  sL   e Zd Zejddd„ƒZejdd	d
„ƒZejddd„ƒZejddd„ƒZdS )ÚCipherContextÚdatar   ÚreturnÚbytesc                 C  ó   dS )zk
        Processes the provided bytes through the cipher and returns the results
        as bytes.
        N© ©Úselfr   r   r   úž/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/cryptography/hazmat/primitives/ciphers/base.pyÚupdate   ó    zCipherContext.updateÚbufÚintc                 C  r   )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   r   zCipherContext.update_intoc                 C  r   )zM
        Returns the results of processing the final block as bytes.
        Nr   ©r   r   r   r   Úfinalize   r   zCipherContext.finalizeÚnonceÚNonec                 C  r   )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%   r   zCipherContext.reset_nonceN)r   r   r	   r
   )r   r   r   r   r	   r   ©r	   r
   )r   r
   r	   r   )	Ú__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„ƒZdS )	ÚAEADCipherContextr   r   r	   r   c                 C  r   )z3
        Authenticates the provided bytes.
        Nr   r   r   r   r   Úauthenticate_additional_data/   r   z.AEADCipherContext.authenticate_additional_dataN)r   r   r	   r   )r   r   r   r   r   r"   r   r   r   r   r!   .   ó    r!   c                   @  s   e Zd Zejddd„ƒZdS )ÚAEADDecryptionContextÚtagr
   r	   c                 C  r   )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   r   z'AEADDecryptionContext.finalize_with_tagN)r%   r
   r	   r
   )r   r   r   r   r   r&   r   r   r   r   r$   6   r#   r$   c                   @  s    e Zd Zeejddd„ƒƒZdS )ÚAEADEncryptionContextr	   r
   c                 C  r   )zb
        Returns tag bytes. This is only available after encryption is
        finalized.
        Nr   r   r   r   r   r%   @   r   zAEADEncryptionContext.tagNr   )r   r   r   Úpropertyr   r   r%   r   r   r   r   r'   ?   s    r'   ÚModeT)ÚboundÚ	covariantc                   @  sj   e Zd Z	ddd
d„Zejddd„ƒZejddd„ƒZdd„ Zejddd„ƒZejddd„ƒZdd„ ZdS )ÚCipherNÚ	algorithmr   Úmoder)   Úbackendú
typing.Anyr	   r   c                 C  sD   t |tƒs	tdƒ‚|d urt |tjƒsJ ‚| |¡ || _|| _d S )Nz&Expected interface of CipherAlgorithm.)Ú
isinstancer   Ú	TypeErrorr   r)   Úvalidate_for_algorithmr-   r.   )r   r-   r.   r/   r   r   r   Ú__init__O   s   


zCipher.__init__r   ú'Cipher[modes.ModeWithAuthenticationTag]r'   c                 C  ó   d S ©Nr   r   r   r   r   Ú	encryptora   ó   zCipher.encryptorÚ_CIPHER_TYPEr   c                 C  r6   r7   r   r   r   r   r   r8   f   r9   c                 C  s4   t | jtjƒr| jjd urtdƒ‚tj | j	| j¡S )Nz0Authentication tag must be None when encrypting.)
r1   r.   r   ÚModeWithAuthenticationTagr%   Ú
ValueErrorÚrust_opensslÚciphersÚcreate_encryption_ctxr-   r   r   r   r   r8   k   s   ÿÿr$   c                 C  r6   r7   r   r   r   r   r   Ú	decryptorv   r9   zCipher.decryptorc                 C  r6   r7   r   r   r   r   r   r@   {   r9   c                 C  s   t j | j| j¡S r7   )r=   r>   Úcreate_decryption_ctxr-   r.   r   r   r   r   r@   €   s   ÿr7   )r-   r   r.   r)   r/   r0   r	   r   )r   r5   r	   r'   )r   r:   r	   r   )r   r5   r	   r$   )r   r   r   r4   ÚtypingÚoverloadr8   r@   r   r   r   r   r,   N   s    ür,   )Ú
__future__r   r   rB   Ú"cryptography.hazmat.bindings._rustr   r=   Ú/cryptography.hazmat.primitives._cipheralgorithmr   Ú&cryptography.hazmat.primitives.ciphersr   Úcryptography.utilsr   ÚABCMetar   r!   r$   r'   ÚTypeVarÚOptionalr)   ÚGenericr,   ÚUnionÚModeWithNonceÚModeWithTweakÚECBÚModeWithInitializationVectorr:   Úregisterr>   r   r   r   r   Ú<module>   s8   	
ÿ8üÿÿ
