3 L]0 @sddlmZmZmZddlmZddlmZm Z ddl m Z e j Z e jZe jZe jZe jZe jZddZddZd S) )absolute_importdivisionprint_function) exceptions)ffilib)ensurecCst|tkrtjdt|tkr,tjddt|}tjdt|}tj ||t|||}t |dkdtj dtj |t|}|t dS) 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 z Invalid keyz Invalid noncezunsigned char[]rzEncryption failed)raisingN)lencrypto_secretbox_KEYBYTESexc ValueErrorcrypto_secretbox_NONCEBYTEScrypto_secretbox_ZEROBYTESrnewrcrypto_secretboxr CryptoErrorbuffercrypto_secretbox_BOXZEROBYTES)messagenoncekeypadded ciphertextresrB/tmp/pip-install-wfra5znf/pynacl/nacl/bindings/crypto_secretbox.pyrs     rcCst|tkrtjdt|tkr,tjddt|}tjdt|}tj ||t|||}t |dkdtj dtj |t|}|t dS) 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 z Invalid keyz Invalid noncer zunsigned char[]rz1Decryption failed. Ciphertext failed verification)r N)r r r rrrrrrcrypto_secretbox_openrrrr)rrrr plaintextrrrrr8s       rN) __future__rrrZnaclrr Z nacl._sodiumrrZnacl.exceptionsrZcrypto_secretbox_keybytesr Zcrypto_secretbox_noncebytesrZcrypto_secretbox_zerobytesrZcrypto_secretbox_boxzerobytesrZcrypto_secretbox_macbytesZcrypto_secretbox_MACBYTESZ!crypto_secretbox_messagebytes_maxZ!crypto_secretbox_MESSAGEBYTES_MAXrrrrrrs