From 80a4c790d27ab85b94b839a58bf47768ae0561ba Mon Sep 17 00:00:00 2001 From: Donald Stufft <donald@stufft.io> Date: Sun, 17 Mar 2013 14:11:32 -0400 Subject: [PATCH] Moved nacl.random to nacl.utils --- docs/secret.rst | 16 ++++++++-------- nacl/signing.py | 2 +- nacl/{random.py => utils.py} | 0 tests/test_random.py | 9 --------- tests/test_utils.py | 9 +++++++++ 5 files changed, 18 insertions(+), 18 deletions(-) rename nacl/{random.py => utils.py} (100%) delete mode 100644 tests/test_random.py create mode 100644 tests/test_utils.py diff --git a/docs/secret.rst b/docs/secret.rst index dd20c429..3a431bc2 100644 --- a/docs/secret.rst +++ b/docs/secret.rst @@ -15,11 +15,11 @@ Example .. code:: python - import nacl.random import nacl.secret + import nacl.utils # This must be kept secret, this is the combination to your safe - key = nacl.random.random(nacl.secret.SecretBox.KEY_SIZE) + key = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE) # This is your safe, you can use it to encrypt or decrypt messages box = nacl.secret.SecretBox(key) @@ -31,7 +31,7 @@ Example # This is a nonce, it *MUST* only be used once, but it is not considered # secret and can be transmitted or stored alongside the ciphertext. A # good source of nonce is just 24 random bytes. - nonce = nacl.random.random(nacl.secret.SecretBox.NONCE_SIZE) + nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE) # Encrypt our message, it will be exactly 16 bytes longer than the original # message as it stores authentication information alongside it. @@ -76,11 +76,11 @@ is not enough to simply use a random value and hope that it's not being reused One good method of generating nonces is for each person to pick a unique prefix, for example ``b"p1"`` and ``b"p2"``. When each person generates a nonce they -prefix it, so instead of ``nacl.random.random(24)`` you'd do ``b"p1" + nacl.random.random(22)``. -This prefix serves as a guarantee that no two messages from different people -will inadvertently overlap nonces while in transit. They should still record -every nonce they've personally used and every nonce they've received to prevent -reuse or replays. +prefix it, so instead of ``nacl.utils.random(24)`` you'd do +``b"p1" + nacl.utils.random(22)``. This prefix serves as a guarantee that no +two messages from different people will inadvertently overlap nonces while in +transit. They should still record every nonce they've personally used and every +nonce they've received to prevent reuse or replays. Reference diff --git a/nacl/signing.py b/nacl/signing.py index c1067cb0..01efafa7 100644 --- a/nacl/signing.py +++ b/nacl/signing.py @@ -5,7 +5,7 @@ from . import six from . import nacl, encoding from .exceptions import CryptoError -from .random import random +from .utils import random class BadSignatureError(CryptoError): diff --git a/nacl/random.py b/nacl/utils.py similarity index 100% rename from nacl/random.py rename to nacl/utils.py diff --git a/tests/test_random.py b/tests/test_random.py deleted file mode 100644 index 4ec3817b..00000000 --- a/tests/test_random.py +++ /dev/null @@ -1,9 +0,0 @@ -import nacl.random - - -def test_random_bytes_produces(): - assert len(nacl.random.random(16)) == 16 - - -def test_random_bytes_produces_different_bytes(): - assert nacl.random.random(16) != nacl.random.random(16) diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 00000000..83dbee05 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,9 @@ +import nacl.utils + + +def test_random_bytes_produces(): + assert len(nacl.utils.random(16)) == 16 + + +def test_random_bytes_produces_different_bytes(): + assert nacl.utils.random(16) != nacl.utils.random(16) -- GitLab