# limitations under the License. from __future__ import absolute_import, division, print_function from nacl import exceptions as exc from nacl._sodium import ffi, lib from nacl.exceptions import ensure __all__ = ["crypto_box_keypair", "crypto_box"] crypto_box_SECRETKEYBYTES = lib.crypto_box_secretkeybytes() crypto_box_PUBLICKEYBYTES = lib.crypto_box_publickeybytes() crypto_box_NONCEBYTES = lib.crypto_box_noncebytes() crypto_box_ZEROBYTES = lib.crypto_box_zerobytes() crypto_box_BOXZEROBYTES = lib.crypto_box_boxzerobytes() crypto_box_BEFORENMBYTES = lib.crypto_box_beforenmbytes() def crypto_box_keypair(): """ Returns a randomly generated public and secret key. :rtype: (bytes(public_key), bytes(secret_key)) """ pk = ffi.new("unsigned char[]", crypto_box_PUBLICKEYBYTES) sk = ffi.new("unsigned char[]", crypto_box_SECRETKEYBYTES) rc = lib.crypto_box_keypair(pk, sk) ensure(rc == 0, 'Unexpected library error', raising=exc.RuntimeError) return (
from __future__ import absolute_import, division, print_function from nacl._sodium import ffi, lib from nacl.exceptions import CryptoError __all__ = ["crypto_box_keypair", "crypto_box"] crypto_box_SECRETKEYBYTES = lib.crypto_box_secretkeybytes() crypto_box_PUBLICKEYBYTES = lib.crypto_box_publickeybytes() crypto_box_NONCEBYTES = lib.crypto_box_noncebytes() crypto_box_ZEROBYTES = lib.crypto_box_zerobytes() crypto_box_BOXZEROBYTES = lib.crypto_box_boxzerobytes() crypto_box_BEFORENMBYTES = lib.crypto_box_beforenmbytes() def crypto_box_keypair(): """ Returns a randomly generated public and secret key. :rtype: (bytes(public_key), bytes(secret_key)) """ pk = ffi.new("unsigned char[]", crypto_box_PUBLICKEYBYTES) sk = ffi.new("unsigned char[]", crypto_box_SECRETKEYBYTES) rc = lib.crypto_box_keypair(pk, sk) assert rc == 0 return (