ó Û_e[c@`sddlmZmZmZddlmZddlmZm Z ddl m Z ddgZ e j ƒZe jƒZe jƒZe jƒZe jƒZe jƒZe jƒZe jƒZd„Zd„Zd „Zd „Z d „Z!d „Z"d „Z#d„Z$d„Z%dS(i(tabsolute_importtdivisiontprint_function(t exceptions(tffitlib(tensuretcrypto_box_keypairt crypto_boxcC`svtjdtƒ}tjdtƒ}tj||ƒ}t|dkddtjƒtj |tƒtj |tƒfS(sq Returns a randomly generated public and secret key. :rtype: (bytes(public_key), bytes(secret_key)) sunsigned char[]isUnexpected library errortraising( Rtnewtcrypto_box_PUBLICKEYBYTEStcrypto_box_SECRETKEYBYTESRRRtexct RuntimeErrortbuffer(tpktsktrc((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR#s  cC`s¹tt|tƒddtƒt|ƒtkr@tjdƒ‚ntj dt ƒ}tj dt ƒ}t j |||ƒ}t|dkddtjƒtj|t ƒtj|t ƒfS(s Returns a (public, secret) keypair deterministically generated from an input ``seed``. .. warning:: The seed **must** be high-entropy; therefore, its generator **must** be a cryptographic quality random function like, for example, :func:`~nacl.utils.random`. .. warning:: The seed **must** be protected and remain secret. Anyone who knows the seed is really in possession of the corresponding PrivateKey. :param seed: bytes :rtype: (bytes(public_key), bytes(secret_key)) sseed must be bytesR s Invalid seedsunsigned char[]isUnexpected library error(Rt isinstancetbytest TypeErrortlentcrypto_box_SEEDBYTESR t ValueErrorRR R R Rtcrypto_box_seed_keypairRR(tseedRRR((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR7s  cC`sìt|ƒtkr$tjdƒ‚nt|ƒtkrHtjdƒ‚nt|ƒtkrltjdƒ‚ndt|}tjdt|ƒƒ}t j ||t|ƒ|||ƒ}t |dkddtj ƒtj |t|ƒƒtS( sð Encrypts and returns a message ``message`` using the secret key ``sk``, public key ``pk``, and the nonce ``nonce``. :param message: bytes :param nonce: bytes :param pk: bytes :param sk: bytes :rtype: bytes sInvalid nonce sizesInvalid public keysInvalid secret keytsunsigned char[]isUnexpected library errorR (Rtcrypto_box_NONCEBYTESR RR R tcrypto_box_ZEROBYTESRR RRRRRtcrypto_box_BOXZEROBYTES(tmessagetnonceRRtpaddedt ciphertextR((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR]s $  cC`sìt|ƒtkr$tjdƒ‚nt|ƒtkrHtjdƒ‚nt|ƒtkrltjdƒ‚ndt|}tjdt|ƒƒ}t j ||t|ƒ|||ƒ}t |dkddtj ƒtj |t|ƒƒtS( s Decrypts and returns an encrypted message ``ciphertext``, using the secret key ``sk``, public key ``pk``, and the nonce ``nonce``. :param ciphertext: bytes :param nonce: bytes :param pk: bytes :param sk: bytes :rtype: bytes sInvalid nonce sizesInvalid public keysInvalid secret keyRsunsigned char[]is/An error occurred trying to decrypt the messageR (RRR RR R RRR Rtcrypto_box_openRt CryptoErrorRR(R"R RRR!t plaintexttres((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR#|s $ cC`sœt|ƒtkr$tjdƒ‚nt|ƒtkrHtjdƒ‚ntjdtƒ}tj |||ƒ}t |dkddtj ƒtj |tƒS(s Computes and returns the shared key for the public key ``pk`` and the secret key ``sk``. This can be used to speed up operations where the same set of keys is going to be used multiple times. :param pk: bytes :param sk: bytes :rtype: bytes sInvalid public keysInvalid secret keysunsigned char[]isUnexpected library errorR ( RR R RR RR tcrypto_box_BEFORENMBYTESRtcrypto_box_beforenmRRR(RRtkR((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR(šs   cC`sÅt|ƒtkr$tjdƒ‚nt|ƒtkrHtjdƒ‚ndt|}tjdt|ƒƒ}tj ||t|ƒ||ƒ}t |dkddtj ƒtj |t|ƒƒt S(sÇ Encrypts and returns the message ``message`` using the shared key ``k`` and the nonce ``nonce``. :param message: bytes :param nonce: bytes :param k: bytes :rtype: bytes s Invalid noncesInvalid shared keyRsunsigned char[]isUnexpected library errorR (RRR RR'RRR Rtcrypto_box_afternmRRRR(RR R)R!R"R((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR*´s !  cC`sÅt|ƒtkr$tjdƒ‚nt|ƒtkrHtjdƒ‚ndt|}tjdt|ƒƒ}tj ||t|ƒ||ƒ}t |dkddtj ƒtj |t|ƒƒt S(sØ Decrypts and returns the encrypted message ``ciphertext``, using the shared key ``k`` and the nonce ``nonce``. :param ciphertext: bytes :param nonce: bytes :param k: bytes :rtype: bytes s Invalid noncesInvalid shared keyRsunsigned char[]is/An error occurred trying to decrypt the messageR (RRR RR'RRR Rtcrypto_box_open_afternmRR$RR(R"R R)R!R%R&((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR+Ïs  cC`sÉtt|tƒddtƒtt|tƒddtƒt|ƒtkr\tjdƒ‚nt|ƒ}t|}t j d|ƒ}t j ||||ƒ}t|dkddtj ƒt j||ƒS(s€ Encrypts and returns a message ``message`` using an ephemeral secret key and the public key ``pk``. The ephemeral public key, which is embedded in the sealed box, is also used, in combination with ``pk``, to derive the nonce needed for the underlying box construct. :param message: bytes :param pk: bytes :rtype: bytes .. versionadded:: 1.2 sinput message must be bytesR spublic key must be bytessInvalid public keysunsigned char[]isUnexpected library error(RRRRRR R Rtcrypto_box_SEALBYTESRR Rtcrypto_box_sealRR(RRt_mlent_clenR"R((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR-ês     cC`s tt|tƒddtƒtt|tƒddtƒtt|tƒddtƒt|ƒtkrxtjdƒ‚nt|ƒtkrœtjdƒ‚nt|ƒ}|t }t j d|ƒ}t j |||||ƒ}t|dkd dtjƒt j||ƒS( s“ Decrypts and returns an encrypted message ``ciphertext``, using the recipent's secret key ``sk`` and the sender's ephemeral public key embedded in the sealed box. The box contruct nonce is derived from the recipient's public key ``pk`` and the sender's public key. :param ciphertext: bytes :param pk: bytes :param sk: bytes :rtype: bytes .. versionadded:: 1.2 sinput ciphertext must be bytesR spublic key must be bytesssecret key must be bytessInvalid public keysInvalid secret keysunsigned char[]is/An error occurred trying to decrypt the message(RRRRRR R RR R,RR Rtcrypto_box_seal_openR$R(R"RRR/R.R%R&((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyR0s(   N(&t __future__RRRtnaclRR t nacl._sodiumRRtnacl.exceptionsRt__all__tcrypto_box_secretkeybytesR tcrypto_box_publickeybytesR tcrypto_box_seedbytesRtcrypto_box_noncebytesRtcrypto_box_zerobytesRtcrypto_box_boxzerobytesRtcrypto_box_beforenmbytesR'tcrypto_box_sealbytesR,RRRR#R(R*R+R-R0(((s:/tmp/pip-install-KP2Jbq/pynacl/nacl/bindings/crypto_box.pyts*           &      &