From 64df134438cee8dc2521e9ad7a1e555af468a323 Mon Sep 17 00:00:00 2001 From: Donald Stufft <donald@stufft.io> Date: Sun, 17 Mar 2013 19:08:11 -0400 Subject: [PATCH] Put the PrivateKey before the PublicKey --- docs/public.rst | 4 ++-- nacl/public.py | 8 ++++---- tests/test_box.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/public.rst b/docs/public.rst index 495dc3ec..9ba2712a 100644 --- a/docs/public.rst +++ b/docs/public.rst @@ -56,7 +56,7 @@ with equal that from (pkbob, skalice). This is how the system works: # Bob wishes to send Alice an encrypted message # So Bob must make a Box with his private key and Alice's public key - bob_box = Box(pkalice, skbob) + bob_box = Box(skbob, pkalice) # This is our message to send, it must be a bytestring as Box will # treat is as just a binary blob of data. @@ -72,7 +72,7 @@ with equal that from (pkbob, skalice). This is how the system works: ciphertext = bob_box.encrypt(message, nonce) # Alice creates a second box with her private key to decrypt the message - alice_box = Box(pkbob, skalice) + alice_box = Box(skalice, pkbob) # Decrypt our message, an exception will be raised if the encryption was # tampered with or there was otherwise an error. diff --git a/nacl/public.py b/nacl/public.py index 42705132..ae0c7922 100644 --- a/nacl/public.py +++ b/nacl/public.py @@ -93,18 +93,18 @@ class Box(encoding.Encodable, six.StringFixer, object): send are repudiable. For non-repudiable messages, sign them after encryption. - :param public_key: :class:`~nacl.public.PublicKey` used to encrypt and - decrypt messages :param private_key: :class:`~nacl.public.PrivateKey` used to encrypt and decrypt messages + :param public_key: :class:`~nacl.public.PublicKey` used to encrypt and + decrypt messages :cvar NONCE_SIZE: The size that the nonce is required to be. """ NONCE_SIZE = nacl.lib.crypto_box_NONCEBYTES - def __init__(self, public_key, private_key): - if public_key and private_key: + def __init__(self, private_key, public_key): + if private_key and public_key: _shared_key_size = nacl.lib.crypto_box_BEFORENMBYTES _shared_key = nacl.ffi.new("unsigned char[]", _shared_key_size) diff --git a/tests/test_box.py b/tests/test_box.py index 25e2ef39..539fa815 100644 --- a/tests/test_box.py +++ b/tests/test_box.py @@ -37,7 +37,7 @@ def test_box_encryption(skalice, pkalice, skbob, pkbob, nonce, plaintext, cipher pkalice = PublicKey(pkalice, encoder=HexEncoder) skbob = PrivateKey(skbob, encoder=HexEncoder) - box = Box(pkalice, skbob) + box = Box(skbob, pkalice) plaintext = binascii.unhexlify(plaintext) nonce = binascii.unhexlify(nonce) @@ -50,7 +50,7 @@ def test_box_decryption(skalice, pkalice, skbob, pkbob, nonce, plaintext, cipher pkbob = PublicKey(pkbob, encoder=HexEncoder) skalice = PrivateKey(skalice, encoder=HexEncoder) - box = Box(pkbob, skalice) + box = Box(skalice, pkbob) nonce = binascii.unhexlify(nonce) decrypted = binascii.hexlify( -- GitLab