Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
python
sakia
Commits
80a4c790
Commit
80a4c790
authored
12 years ago
by
Donald Stufft
Browse files
Options
Downloads
Patches
Plain Diff
Moved nacl.random to nacl.utils
parent
84da25f6
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/secret.rst
+8
-8
8 additions, 8 deletions
docs/secret.rst
nacl/signing.py
+1
-1
1 addition, 1 deletion
nacl/signing.py
nacl/utils.py
+0
-0
0 additions, 0 deletions
nacl/utils.py
tests/test_utils.py
+9
-0
9 additions, 0 deletions
tests/test_utils.py
with
18 additions
and
9 deletions
docs/secret.rst
+
8
−
8
View file @
80a4c790
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
nacl/signing.py
+
1
−
1
View file @
80a4c790
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
nacl/
random
.py
→
nacl/
utils
.py
+
0
−
0
View file @
80a4c790
File moved
This diff is collapsed.
Click to expand it.
tests/test_
random
.py
→
tests/test_
utils
.py
+
9
−
0
View file @
80a4c790
import
nacl.
random
import
nacl.
utils
def
test_random_bytes_produces
():
assert
len
(
nacl
.
random
.
random
(
16
))
==
16
assert
len
(
nacl
.
utils
.
random
(
16
))
==
16
def
test_random_bytes_produces_different_bytes
():
assert
nacl
.
random
.
random
(
16
)
!=
nacl
.
random
.
random
(
16
)
assert
nacl
.
utils
.
random
(
16
)
!=
nacl
.
utils
.
random
(
16
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment