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
b2d863c4
Commit
b2d863c4
authored
12 years ago
by
Donald Stufft
Browse files
Options
Downloads
Patches
Plain Diff
Add nacl.random(N) to generate a random N bytes
parent
fbe68012
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
nacl/__init__.py
+2
-1
2 additions, 1 deletion
nacl/__init__.py
nacl/nacl.py
+10
-0
10 additions, 0 deletions
nacl/nacl.py
nacl/random.py
+7
-0
7 additions, 0 deletions
nacl/random.py
tests/test_random.py
+9
-0
9 additions, 0 deletions
tests/test_random.py
with
28 additions
and
1 deletion
nacl/__init__.py
+
2
−
1
View file @
b2d863c4
from
.
import
__about__
from
.
import
hash
# pylint: disable=W0622
from
.random
import
random
__all__
=
[
"
hash
"
]
+
__about__
.
__all__
__all__
=
[
"
hash
"
,
"
random
"
]
+
__about__
.
__all__
# - Meta Information -
...
...
This diff is collapsed.
Click to expand it.
nacl/nacl.py
+
10
−
0
View file @
b2d863c4
...
...
@@ -23,6 +23,11 @@ ffi.cdef(
int crypto_hash_sha256(unsigned char *out, const unsigned char *in, unsigned long long inlen);
int crypto_hash_sha512(unsigned char *out, const unsigned char *in, unsigned long long inlen);
"""
# Secure Random
"""
void randombytes(unsigned char * const buf, const unsigned long long buf_len);
"""
)
...
...
@@ -37,6 +42,11 @@ try:
#include
"
crypto_hash.h
"
#include
"
crypto_hash_sha256.h
"
#include
"
crypto_hash_sha512.h
"
"""
# Secure Random
"""
#include
"
randombytes.h
"
"""
,
libraries
=
[
"
nacl
"
],
)
...
...
This diff is collapsed.
Click to expand it.
nacl/random.py
0 → 100644
+
7
−
0
View file @
b2d863c4
from
.
import
nacl
def
random
(
size
=
32
):
data
=
nacl
.
ffi
.
new
(
"
unsigned char[]
"
,
size
)
nacl
.
lib
.
randombytes
(
data
,
size
)
return
nacl
.
ffi
.
string
(
data
)
This diff is collapsed.
Click to expand it.
tests/test_random.py
0 → 100644
+
9
−
0
View file @
b2d863c4
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
)
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