o
    gb                     @   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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 )	z
    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   zEncryption failedraisingN)lenr   exc
ValueErrorr   r   r   newr   crypto_secretboxr   CryptoErrorbufferr	   )r   r   r   padded
ciphertextres r!   X/var/www/html/api-tag/env/lib/python3.10/site-packages/nacl/bindings/crypto_secretbox.pyr      s   


r   r   c                 C   r   )	z
    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   z1Decryption 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#   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!   r!   r!   r"   <module>   s(   
