diff --git a/docs/secret.rst b/docs/secret.rst index fa2f65b7cd4595299298bdca1862381f56439dae..3a431bc22d56b8c5750346ad81011e8c2138afee 100644 --- a/docs/secret.rst +++ b/docs/secret.rst @@ -15,11 +15,11 @@ Example .. code:: python - import nacl import nacl.secret + import nacl.utils # This must be kept secret, this is the combination to your safe - key = nacl.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(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(24)`` you'd do ``b"p1" + nacl.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/__about__.py b/nacl/__about__.py deleted file mode 100644 index 60fbfcf0f1fb981e58fdfa47e54618cfd1543afb..0000000000000000000000000000000000000000 --- a/nacl/__about__.py +++ /dev/null @@ -1,21 +0,0 @@ -# pylint: disable=C0301 -from __future__ import absolute_import -from __future__ import division -from __future__ import unicode_literals - -__all__ = [ - "__title__", "__summary__", "__uri__", "__version__", "__author__", - "__email__", "__license__", "__copyright__", -] - -__title__ = "PyNaCl" -__summary__ = "Python binding to the Networking and Cryptography (NaCl) library" # nopep8 -__uri__ = "https://github.com/dstufft/pynacl/" - -__version__ = "0.1dev1" - -__author__ = "Donald Stufft" -__email__ = "donald@stufft.io" - -__license__ = "Simplified BSD" -__copyright__ = "Copyright 2012 Donald Stufft" diff --git a/nacl/__init__.py b/nacl/__init__.py index 2dcf301c7ebbff9aeb40769984d5ffb1c74e0722..69e3431d08ab49d693a95699f22c4e3bd254d4a8 100644 --- a/nacl/__init__.py +++ b/nacl/__init__.py @@ -1,18 +1,19 @@ from __future__ import absolute_import from __future__ import division -from . import __about__ -from . import hash # pylint: disable=W0622 -from . import signing -from .random import random +__all__ = [ + "__title__", "__summary__", "__uri__", "__version__", "__author__", + "__email__", "__license__", "__copyright__", +] +__title__ = "PyNaCl" +__summary__ = "Python binding to the Networking and Cryptography (NaCl) library" +__uri__ = "https://github.com/dstufft/pynacl/" -__all__ = ["hash", "random"] + __about__.__all__ +__version__ = "0.1dev1" +__author__ = "Donald Stufft" +__email__ = "donald@stufft.io" -# - Meta Information - -# This is pretty ugly -for attr in __about__.__all__: - if hasattr(__about__, attr): - globals()[attr] = getattr(__about__, attr) -# - End Meta Information - +__license__ = "Simplified BSD" +__copyright__ = "Copyright 2012 Donald Stufft" diff --git a/nacl/signing.py b/nacl/signing.py index c1067cb0fb26bc613f4ff629b443a0a98d30c03d..01efafa778951d493ff44fea5ab29a9830f0260e 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/setup.py b/setup.py index 3e4ab38aacef40800704c5ce4a4022e67b124eba..9cec5549817afac347c1f35b1c769054a37b4e3f 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,10 @@ #!/usr/bin/env python -from setuptools import setup -from setuptools.command.test import test as TestCommand import sys -__about__ = {} - -with open("nacl/__about__.py") as fp: - exec(fp.read(), None, __about__) +from setuptools import setup +from setuptools.command.test import test as TestCommand +import nacl try: import nacl.nacl @@ -32,16 +29,16 @@ class PyTest(TestCommand): setup( - name=__about__["__title__"], - version=__about__["__version__"], + name=nacl.__title__, + version=nacl.__version__, - description=__about__["__summary__"], + description=nacl.__summary__, long_description=open("README.rst").read(), - url=__about__["__uri__"], - license=__about__["__license__"], + url=nacl.__uri__, + license=nacl.__license__, - author=__about__["__author__"], - author_email=__about__["__email__"], + author=nacl.__author__, + author_email=nacl.__email__, install_requires=[ "cffi", @@ -59,5 +56,5 @@ setup( ext_modules=ext_modules, zip_safe=False, - cmdclass = {'test': PyTest}, + cmdclass={"test": PyTest}, ) diff --git a/tests/test_hash.py b/tests/test_hash.py index b24b25bd31392705e06035dc842d7f2468ed7392..66730124b1c69bc6a9eb88a7559930634725e0df 100644 --- a/tests/test_hash.py +++ b/tests/test_hash.py @@ -1,6 +1,6 @@ import pytest -import nacl +import nacl.hash import nacl.encoding diff --git a/tests/test_random.py b/tests/test_random.py deleted file mode 100644 index 6c43388f908ec7c76134e1b5419d9e756cfe398e..0000000000000000000000000000000000000000 --- a/tests/test_random.py +++ /dev/null @@ -1,9 +0,0 @@ -import nacl - - -def test_random_bytes_produces(): - assert len(nacl.random(16)) == 16 - - -def test_random_bytes_produces_different_bytes(): - assert nacl.random(16) != nacl.random(16) diff --git a/tests/test_signing.py b/tests/test_signing.py index d22e2944320d1eadc84a1d51c8b6d37fcfcaf8f7..2122d1ca8a137d58cf875b83aff7d1f047c35dcc 100644 --- a/tests/test_signing.py +++ b/tests/test_signing.py @@ -6,7 +6,7 @@ import os import pytest -import nacl +import nacl.signing import nacl.encoding import nacl.nacl diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..83dbee05cafdc32cfa27a2a85c541d6c3b1c26b7 --- /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)