U
    ΂db                     @   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	< eeeed
ddZeeeed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   s   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ZraisingN)lenr   exc
ValueErrorr   r   r   newr   crypto_secretboxr   CryptoErrorbufferr	   )r   r   r   padded
ciphertextres r   [/var/www/html/myproject/myenv/lib/python3.8/site-packages/nacl/bindings/crypto_secretbox.pyr      s    


r   )r   r   r   r   c                 C   s   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
    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   Z	plaintextr   r   r   r    r!   9   s    

r!   N)Znaclr   r   Znacl._sodiumr   r   Znacl.exceptionsr   Zcrypto_secretbox_keybytesr   int__annotations__Zcrypto_secretbox_noncebytesr   Zcrypto_secretbox_zerobytesr   Zcrypto_secretbox_boxzerobytesr	   Zcrypto_secretbox_macbytesr
   Z!crypto_secretbox_messagebytes_maxr   bytesr   r!   r   r   r   r    <module>   s     
  