Skip to content
Snippets Groups Projects
Commit 84da25f6 authored by Donald Stufft's avatar Donald Stufft
Browse files

Remove nacl.* implicit imports in favor of explicit

parent 8ee769bc
No related branches found
Tags gdev-900-0.9.2
No related merge requests found
...@@ -15,11 +15,11 @@ Example ...@@ -15,11 +15,11 @@ Example
.. code:: python .. code:: python
import nacl import nacl.random
import nacl.secret import nacl.secret
# This must be kept secret, this is the combination to your safe # This must be kept secret, this is the combination to your safe
key = nacl.random(nacl.secret.SecretBox.KEY_SIZE) key = nacl.random.random(nacl.secret.SecretBox.KEY_SIZE)
# This is your safe, you can use it to encrypt or decrypt messages # This is your safe, you can use it to encrypt or decrypt messages
box = nacl.secret.SecretBox(key) box = nacl.secret.SecretBox(key)
...@@ -31,7 +31,7 @@ Example ...@@ -31,7 +31,7 @@ Example
# This is a nonce, it *MUST* only be used once, but it is not considered # 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 # secret and can be transmitted or stored alongside the ciphertext. A
# good source of nonce is just 24 random bytes. # good source of nonce is just 24 random bytes.
nonce = nacl.random(nacl.secret.SecretBox.NONCE_SIZE) nonce = nacl.random.random(nacl.secret.SecretBox.NONCE_SIZE)
# Encrypt our message, it will be exactly 16 bytes longer than the original # Encrypt our message, it will be exactly 16 bytes longer than the original
# message as it stores authentication information alongside it. # message as it stores authentication information alongside it.
...@@ -76,7 +76,7 @@ is not enough to simply use a random value and hope that it's not being reused ...@@ -76,7 +76,7 @@ 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, 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 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)``. 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 This prefix serves as a guarantee that no two messages from different people
will inadvertently overlap nonces while in transit. They should still record 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 every nonce they've personally used and every nonce they've received to prevent
......
# 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"
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import division from __future__ import division
from . import __about__ __all__ = [
from . import hash # pylint: disable=W0622 "__title__", "__summary__", "__uri__", "__version__", "__author__",
from . import signing "__email__", "__license__", "__copyright__",
from .random import random ]
__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 - __license__ = "Simplified BSD"
# This is pretty ugly __copyright__ = "Copyright 2012 Donald Stufft"
for attr in __about__.__all__:
if hasattr(__about__, attr):
globals()[attr] = getattr(__about__, attr)
# - End Meta Information -
#!/usr/bin/env python #!/usr/bin/env python
from setuptools import setup
from setuptools.command.test import test as TestCommand
import sys import sys
__about__ = {} from setuptools import setup
from setuptools.command.test import test as TestCommand
with open("nacl/__about__.py") as fp:
exec(fp.read(), None, __about__)
import nacl
try: try:
import nacl.nacl import nacl.nacl
...@@ -32,16 +29,16 @@ class PyTest(TestCommand): ...@@ -32,16 +29,16 @@ class PyTest(TestCommand):
setup( setup(
name=__about__["__title__"], name=nacl.__title__,
version=__about__["__version__"], version=nacl.__version__,
description=__about__["__summary__"], description=nacl.__summary__,
long_description=open("README.rst").read(), long_description=open("README.rst").read(),
url=__about__["__uri__"], url=nacl.__uri__,
license=__about__["__license__"], license=nacl.__license__,
author=__about__["__author__"], author=nacl.__author__,
author_email=__about__["__email__"], author_email=nacl.__email__,
install_requires=[ install_requires=[
"cffi", "cffi",
...@@ -59,5 +56,5 @@ setup( ...@@ -59,5 +56,5 @@ setup(
ext_modules=ext_modules, ext_modules=ext_modules,
zip_safe=False, zip_safe=False,
cmdclass = {'test': PyTest}, cmdclass={"test": PyTest},
) )
import pytest import pytest
import nacl import nacl.hash
import nacl.encoding import nacl.encoding
......
import nacl import nacl.random
def test_random_bytes_produces(): def test_random_bytes_produces():
assert len(nacl.random(16)) == 16 assert len(nacl.random.random(16)) == 16
def test_random_bytes_produces_different_bytes(): def test_random_bytes_produces_different_bytes():
assert nacl.random(16) != nacl.random(16) assert nacl.random.random(16) != nacl.random.random(16)
...@@ -6,7 +6,7 @@ import os ...@@ -6,7 +6,7 @@ import os
import pytest import pytest
import nacl import nacl.signing
import nacl.encoding import nacl.encoding
import nacl.nacl import nacl.nacl
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment