o
    FD©i  ã                   @   sö   U d dl mZ d dlmZmZ d dlmZ e ¡ Z	e
ed< e ¡ Ze
ed< e ¡ Ze
ed< e ¡ Ze
ed< e ¡ Ze
ed< e ¡ Ze
ed	< d
edededefdd„Zdedededefdd„Zd
edededefdd„Zdedededefdd„ZdS )é    )Ú
exceptions)ÚffiÚlib)ÚensureÚcrypto_secretbox_KEYBYTESÚcrypto_secretbox_NONCEBYTESÚcrypto_secretbox_ZEROBYTESÚcrypto_secretbox_BOXZEROBYTESÚcrypto_secretbox_MACBYTESÚ!crypto_secretbox_MESSAGEBYTES_MAXÚmessageÚnonceÚkeyÚreturnc                 C   óŽ   t |ƒtkrt d¡‚t |ƒtkrt d¡‚dt |  }t dt |ƒ¡}t 	||t |ƒ||¡}t
|dkdtjd t |t |ƒ¡}|td… S )	úÆ
    Encrypts and returns the message ``message`` with the secret ``key`` and
    the nonce ``nonce``.

    :param message: bytes
    :param nonce: bytes
    :param key: bytes
    :rtype: bytes
    úInvalid keyúInvalid nonceó    úunsigned char[]r   úEncryption failed©ÚraisingN)Úlenr   ÚexcÚ
ValueErrorr   r   r   Únewr   Úcrypto_secretboxr   ÚCryptoErrorÚbufferr	   )r   r   r   ÚpaddedÚ
ciphertextÚres© r#   úW/var/www/Datamplify/venv/lib/python3.10/site-packages/nacl/bindings/crypto_secretbox.pyr      s   


r   r!   c                 C   r   )	úÕ
    Decrypt and returns the encrypted message ``ciphertext`` with the secret
    ``key`` and the nonce ``nonce``.

    :param ciphertext: bytes
    :param nonce: bytes
    :param key: bytes
    :rtype: bytes
    r   r   r   r   r   ú1Decryption failed. Ciphertext failed verificationr   N)r   r   r   r   r   r	   r   r   r   Úcrypto_secretbox_openr   r   r   r   )r!   r   r   r    Ú	plaintextr"   r#   r#   r$   r'   9   s   

ýr'   c                 C   s†   t |ƒtkrt d¡‚t |ƒtkrt d¡‚t | ƒ}t| }t d|¡}t 	|| |||¡}t
|dkdtjd t ||¡}|dd… S )r   r   r   r   r   r   r   N)r   r   r   r   r   r
   r   r   r   Úcrypto_secretbox_easyr   r   r   )r   r   r   Ú_mlenÚ_clenr!   r"   r#   r#   r$   r)   Y   s   


r)   c                 C   s¦   t |ƒtkrt d¡‚t |ƒtkrt d¡‚t | ƒ}t|tkd t¡tjd |t }t	 
dtd|ƒ¡}t || |||¡}t|dkdtjd t	 ||¡}|d	d	… S )
r%   r   r   z)Input ciphertext must be at least {} longr   r   é   r   r&   N)r   r   r   r   r   r   r
   ÚformatÚ	TypeErrorr   r   Úmaxr   Úcrypto_secretbox_open_easyr   r   )r!   r   r   r+   r*   r(   r"   r#   r#   r$   r0   u   s0   

ÿû
ÿýr0   N)Únaclr   r   Únacl._sodiumr   r   Únacl.exceptionsr   Úcrypto_secretbox_keybytesr   ÚintÚ__annotations__Úcrypto_secretbox_noncebytesr   Úcrypto_secretbox_zerobytesr   Úcrypto_secretbox_boxzerobytesr	   Úcrypto_secretbox_macbytesr
   Ú!crypto_secretbox_messagebytes_maxr   Úbytesr   r'   r)   r0   r#   r#   r#   r$   Ú<module>   s<   
ÿÿÿÿ
þ ÿÿÿþ