U q`0 @sddlmZmZmZddlmZddlmZm Z ddl m Z e Z e Ze Ze Ze Ze ZddZddZd S) )absolute_importdivisionprint_function) exceptions)ffilib)ensurecCst|tkrtdt|tkr,tddt|}tdt|}t ||t|||}t |dkdtj dt |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 Invalid key Invalid nonceunsigned char[]rzEncryption failedZraisingN)lencrypto_secretbox_KEYBYTESexc ValueErrorcrypto_secretbox_NONCEBYTEScrypto_secretbox_ZEROBYTESrnewrcrypto_secretboxr CryptoErrorbuffercrypto_secretbox_BOXZEROBYTES)messagenoncekeypadded ciphertextresrE/tmp/pip-target-nv4zd3e_/lib/python/nacl/bindings/crypto_secretbox.pyrs     rcCst|tkrtdt|tkr,tddt|}tdt|}t ||t|||}t |dkdtj dt |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 r r r r rz1Decryption failed. Ciphertext failed verificationr N)rrrrrrrrrcrypto_secretbox_openrrrr)rrrr plaintextrrrr r!8s$      r!N) __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 s