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
8d55e676
Commit
8d55e676
authored
10 years ago
by
Brian Warner
Browse files
Options
Downloads
Patches
Plain Diff
fix py3 bytes-vs-str problems
parent
ee4e204e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_raw.py
+25
-21
25 additions, 21 deletions
tests/test_raw.py
with
25 additions
and
21 deletions
tests/test_raw.py
+
25
−
21
View file @
8d55e676
...
...
@@ -17,34 +17,38 @@ from nacl import c
import
hashlib
def
tohex
(
b
):
return
hexlify
(
b
).
decode
(
"
ascii
"
)
def
test_hash
():
msg
=
"
message
"
msg
=
b
"
message
"
h1
=
c
.
crypto_hash
(
msg
)
assert
len
(
h1
)
==
c
.
crypto_hash_BYTES
assert
hex
lify
(
h1
)
==
(
"
f8daf57a3347cc4d6b9d575b31fe6077
"
"
e2cb487f60a96233c08cb479dbf31538
"
"
cc915ec6d48bdbaa96ddc1a16db4f4f9
"
"
6f37276cfcb3510b8246241770d5952c
"
)
assert
hex
lify
(
h1
)
==
hashlib
.
sha512
(
msg
).
hexdigest
()
assert
to
hex
(
h1
)
==
(
"
f8daf57a3347cc4d6b9d575b31fe6077
"
"
e2cb487f60a96233c08cb479dbf31538
"
"
cc915ec6d48bdbaa96ddc1a16db4f4f9
"
"
6f37276cfcb3510b8246241770d5952c
"
)
assert
to
hex
(
h1
)
==
hashlib
.
sha512
(
msg
).
hexdigest
()
h2
=
c
.
crypto_hash_sha512
(
msg
)
assert
len
(
h2
)
==
c
.
crypto_hash_sha512_BYTES
assert
hex
lify
(
h2
)
==
hex
lify
(
h1
)
assert
to
hex
(
h2
)
==
to
hex
(
h1
)
h3
=
c
.
crypto_hash_sha256
(
msg
)
assert
len
(
h3
)
==
c
.
crypto_hash_sha256_BYTES
assert
hex
lify
(
h3
)
==
(
"
ab530a13e45914982b79f9b7e3fba994
"
"
cfd1f3fb22f71cea1afbf02b460c6d1d
"
)
assert
hex
lify
(
h3
)
==
hashlib
.
sha256
(
msg
).
hexdigest
()
assert
to
hex
(
h3
)
==
(
"
ab530a13e45914982b79f9b7e3fba994
"
"
cfd1f3fb22f71cea1afbf02b460c6d1d
"
)
assert
to
hex
(
h3
)
==
hashlib
.
sha256
(
msg
).
hexdigest
()
def
test_secretbox
():
key
=
"
\x00
"
*
c
.
crypto_secretbox_KEYBYTES
msg
=
"
message
"
nonce
=
"
\x01
"
*
c
.
crypto_secretbox_NONCEBYTES
key
=
b
"
\x00
"
*
c
.
crypto_secretbox_KEYBYTES
msg
=
b
"
message
"
nonce
=
b
"
\x01
"
*
c
.
crypto_secretbox_NONCEBYTES
ct
=
c
.
crypto_secretbox
(
msg
,
nonce
,
key
)
assert
len
(
ct
)
==
len
(
msg
)
+
c
.
crypto_secretbox_BOXZEROBYTES
assert
hex
lify
(
ct
)
==
"
3ae84dfb89728737bd6e2c8cacbaf8af3d34cc1666533a
"
assert
to
hex
(
ct
)
==
"
3ae84dfb89728737bd6e2c8cacbaf8af3d34cc1666533a
"
msg2
=
c
.
crypto_secretbox_open
(
ct
,
nonce
,
key
)
assert
msg2
==
msg
...
...
@@ -58,15 +62,15 @@ def test_box():
k1
=
c
.
crypto_box_beforenm
(
B_pubkey
,
A_secretkey
)
assert
len
(
k1
)
==
c
.
crypto_box_BEFORENMBYTES
k2
=
c
.
crypto_box_beforenm
(
A_pubkey
,
B_secretkey
)
assert
hex
lify
(
k1
)
==
hex
lify
(
k2
)
assert
to
hex
(
k1
)
==
to
hex
(
k2
)
message
=
"
message
"
nonce
=
"
\x01
"
*
c
.
crypto_box_NONCEBYTES
message
=
b
"
message
"
nonce
=
b
"
\x01
"
*
c
.
crypto_box_NONCEBYTES
ct1
=
c
.
crypto_box_afternm
(
message
,
nonce
,
k1
)
assert
len
(
ct1
)
==
len
(
message
)
+
c
.
crypto_box_BOXZEROBYTES
ct2
=
c
.
crypto_box
(
message
,
nonce
,
B_pubkey
,
A_secretkey
)
assert
hex
lify
(
ct2
)
==
hex
lify
(
ct1
)
assert
to
hex
(
ct2
)
==
to
hex
(
ct1
)
m1
=
c
.
crypto_box_open
(
ct1
,
nonce
,
A_pubkey
,
B_secretkey
)
assert
m1
==
message
...
...
@@ -76,7 +80,7 @@ def test_box():
def
test_sign
():
seed
=
"
\x00
"
*
c
.
crypto_sign_SEEDBYTES
seed
=
b
"
\x00
"
*
c
.
crypto_sign_SEEDBYTES
pubkey
,
secretkey
=
c
.
crypto_sign_seed_keypair
(
seed
)
assert
len
(
pubkey
)
==
c
.
crypto_sign_PUBLICKEYBYTES
assert
len
(
secretkey
)
==
c
.
crypto_sign_SECRETKEYBYTES
...
...
@@ -85,7 +89,7 @@ def test_sign():
assert
len
(
pubkey
)
==
c
.
crypto_sign_PUBLICKEYBYTES
assert
len
(
secretkey
)
==
c
.
crypto_sign_SECRETKEYBYTES
msg
=
"
message
"
msg
=
b
"
message
"
sigmsg
=
c
.
crypto_sign
(
msg
,
secretkey
)
assert
len
(
sigmsg
)
==
len
(
msg
)
+
c
.
crypto_sign_BYTES
...
...
@@ -106,4 +110,4 @@ def test_scalarmult():
y
,
ypub
=
secret_scalar
()
bx
=
c
.
crypto_scalarmult_base
(
x
)
assert
hex
lify
(
bx
)
==
hex
lify
(
xpub
)
assert
to
hex
(
bx
)
==
to
hex
(
xpub
)
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