Your IP : 216.73.217.13


Current Path : /lib/python3/dist-packages/nacl/bindings/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/nacl/bindings/__pycache__/crypto_secretbox.cpython-38.pyc

U

�֫[0�@s�ddlmZmZmZddlmZddlmZm	Z	ddl
mZe	��Z
e	��Ze	��Ze	��Ze	��Ze	��Zdd�Zdd�Zd	S)
�)�absolute_import�division�print_function)�
exceptions)�ffi�lib)�ensurecCs�t|�tkrt�d��t|�tkr,t�d��dt|}t�dt|��}t�	||t|�||�}t
|dkdtjd�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[]rzEncryption failed�ZraisingN)�len�crypto_secretbox_KEYBYTES�exc�
ValueError�crypto_secretbox_NONCEBYTES�crypto_secretbox_ZEROBYTESr�newr�crypto_secretboxr�CryptoError�buffer�crypto_secretbox_BOXZEROBYTES)�message�nonce�key�padded�
ciphertext�res�r�@/usr/lib/python3/dist-packages/nacl/bindings/crypto_secretbox.pyrs


rcCs�t|�tkrt�d��t|�tkr,t�d��dt|}t�dt|��}t�	||t|�||�}t
|dkdtjd�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
rrrz1Decryption failed. Ciphertext failed verificationr
N)rrrrrrrrr�crypto_secretbox_openrrrr)rrrrZ	plaintextrrrr r!8s$


�
�r!N)Z
__future__rrrZnaclrrZnacl._sodiumrrZnacl.exceptionsrZcrypto_secretbox_keybytesrZcrypto_secretbox_noncebytesrZcrypto_secretbox_zerobytesrZcrypto_secretbox_boxzerobytesrZcrypto_secretbox_macbytesZcrypto_secretbox_MACBYTESZ!crypto_secretbox_messagebytes_maxZ!crypto_secretbox_MESSAGEBYTES_MAXrr!rrrr �<module>s