Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

Commit 39010e1

Browse files
author
Federico Ceratto
committed
Update tests
1 parent 164dba7 commit 39010e1

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

test_sodium.nim

+57-57
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,50 @@ suite "basics":
1515

1616
test "zeroed":
1717
let s = zeroed 20
18-
assert s == repeat('\0', 20)
18+
check s == repeat('\0', 20)
1919

2020
test "memcmp":
21-
assert memcmp("hello", "hello")
22-
assert memcmp("hello", "hello2") == false
23-
assert memcmp("hello2", "hello") == false
24-
assert memcmp("hello", "hallo") == false
21+
check memcmp("hello", "hello")
22+
check memcmp("hello", "hello2") == false
23+
check memcmp("hello2", "hello") == false
24+
check memcmp("hello", "hallo") == false
2525

2626
test "is zero":
27-
assert is_zero("")
28-
assert is_zero("\0\0\0")
29-
assert is_zero("\0\0\1") == false
30-
assert zeroed(20).is_zero()
27+
check is_zero("")
28+
check is_zero("\0\0\0")
29+
check is_zero("\0\0\1") == false
30+
check zeroed(20).is_zero()
3131

3232
test "bin2hex":
33-
assert bin2hex("") == ""
34-
assert bin2hex("\0\255") == "00ff"
35-
assert bin2hex("\255\0") == "ff00"
36-
assert bin2hex("\0\1\2\3\4\5\6\7\8\9") == "00010203040506070809"
33+
check bin2hex("") == ""
34+
check bin2hex("\0\255") == "00ff"
35+
check bin2hex("\255\0") == "ff00"
36+
check bin2hex("\0\1\2\3\4\5\6\7\8\9") == "00010203040506070809"
3737

3838
test "hex2bin":
39-
assert hex2bin("") == ""
40-
assert hex2bin("00ff") == "\0\255"
41-
assert hex2bin("ff00") == "\255\0"
42-
assert hex2bin("ff:aa:bb:cc", ignore=":") == "\xFF\xAA\xBB\xCC\0"
39+
check hex2bin("") == ""
40+
check hex2bin("00ff") == "\0\255"
41+
check hex2bin("ff00") == "\255\0"
42+
check hex2bin("ff:aa:bb:cc", ignore=":") == "\xFF\xAA\xBB\xCC\0"
4343
# FIXME
44-
#assert hex2bin("ff:aa:bb:cc", ignore=":").len == 4
45-
#assert hex2bin("00010203040506070809") == "\0\x01\x02\x03\x04\x05\x06\x07\x08\x09"
44+
#check hex2bin("ff:aa:bb:cc", ignore=":").len == 4
45+
#check hex2bin("00010203040506070809") == "\0\x01\x02\x03\x04\x05\x06\x07\x08\x09"
4646

4747
test "random":
4848
var r = randombytes(8)
49-
assert r.len == 8
49+
check r.len == 8
5050

5151
test "auth":
5252
let
5353
key = repeat('k', crypto_auth_KEYBYTES())
5454
mac = crypto_auth("hello", key)
55-
assert mac.len == crypto_auth_BYTES()
56-
assert crypto_auth_verify(mac, "hello", key)
57-
assert crypto_auth_verify(mac, "hallo", key) == false
55+
check mac.len == crypto_auth_BYTES()
56+
check crypto_auth_verify(mac, "hello", key)
57+
check crypto_auth_verify(mac, "hallo", key) == false
5858
let mac_bogus = zeroed crypto_auth_BYTES()
59-
assert crypto_auth_verify(mac_bogus, "hello", key) == false
59+
check crypto_auth_verify(mac_bogus, "hello", key) == false
6060
let key_bogus = repeat('b', crypto_auth_KEYBYTES())
61-
assert crypto_auth_verify(mac, "hello", key_bogus) == false
61+
check crypto_auth_verify(mac, "hello", key_bogus) == false
6262

6363

6464
test "hex2bin":
@@ -72,7 +72,7 @@ suite "authenticated encryption":
7272
msg = "hello there"
7373
ciphertext = crypto_secretbox_easy(key, msg)
7474
decrypted = crypto_secretbox_open_easy(key, ciphertext)
75-
assert msg == decrypted
75+
check msg == decrypted
7676

7777

7878
# Public-key authenticated encryption
@@ -84,12 +84,12 @@ suite "crypto_box":
8484
(pk, sk) = crypto_box_keypair()
8585
nonce = randombytes(crypto_box_NONCEBYTES())
8686
ciphertext = crypto_box_easy(msg, nonce, pk, sk)
87-
assert ciphertext.len == msg.len + crypto_box_MACBYTES()
87+
check ciphertext.len == msg.len + crypto_box_MACBYTES()
8888

8989
let orig = crypto_box_open_easy(ciphertext, nonce, pk, sk)
90-
assert orig == msg
90+
check orig == msg
9191
# FIXME let sig = sign(sk, "hello")
92-
#assert sig.len == 64
92+
#check sig.len == 64
9393

9494

9595
suite "public-key signatures":
@@ -98,23 +98,23 @@ suite "public-key signatures":
9898
let
9999
seed = repeat('s', crypto_sign_SEEDBYTES())
100100
(pk, sk) = crypto_sign_seed_keypair(seed)
101-
assert pk.len == crypto_sign_PUBLICKEYBYTES()
102-
assert sk.len == crypto_sign_SECRETKEYBYTES()
101+
check pk.len == crypto_sign_PUBLICKEYBYTES()
102+
check sk.len == crypto_sign_SECRETKEYBYTES()
103103

104104
test "real keypair":
105105
let (real_pk, real_sk) = crypto_sign_keypair()
106-
assert real_pk.len == crypto_sign_PUBLICKEYBYTES()
107-
assert real_sk.len == crypto_sign_SECRETKEYBYTES()
106+
check real_pk.len == crypto_sign_PUBLICKEYBYTES()
107+
check real_sk.len == crypto_sign_SECRETKEYBYTES()
108108

109109
test "extract seed from secret key":
110-
assert crypto_sign_ed25519_sk_to_seed(sk) == seed
110+
check crypto_sign_ed25519_sk_to_seed(sk) == seed
111111

112112
test "generate public key from secret key":
113-
assert crypto_sign_ed25519_sk_to_pk(sk) == pk
113+
check crypto_sign_ed25519_sk_to_pk(sk) == pk
114114

115115
test "sign":
116116
let sig = crypto_sign_detached(sk, "hello")
117-
assert sig.len == crypto_sign_BYTES()
117+
check sig.len == crypto_sign_BYTES()
118118

119119
test "verify":
120120
let signature = crypto_sign_detached(sk, "hello")
@@ -130,43 +130,43 @@ suite "public-key signatures":
130130
let
131131
msg = "4242424242424242424242"
132132
sealed = crypto_box_seal(msg, pk)
133-
assert sealed.len == msg.len + crypto_box_SEALBYTES()
133+
check sealed.len == msg.len + crypto_box_SEALBYTES()
134134

135135
test "crypto_box_seal_open":
136136
checkpoint "seal"
137137
let
138138
msg = "123456789"
139139
sealed = crypto_box_seal(msg, pk)
140-
assert sealed.len == msg.len + crypto_box_SEALBYTES()
140+
check sealed.len == msg.len + crypto_box_SEALBYTES()
141141
checkpoint "open"
142142
# FIXME
143143
#let opened = crypto_box_seal_open(sealed, pk, sk)
144-
#assert msg == opened
144+
#check msg == opened
145145

146146

147147
suite "hashing":
148148

149149
test "generic hashing":
150150
let h = crypto_generichash("hello")
151-
assert h.len == crypto_generichash_BYTES()
151+
check h.len == crypto_generichash_BYTES()
152152

153153
test "generic multipart hashing":
154154
let ha = new_generic_hash(repeat('k', crypto_generichash_KEYBYTES()))
155155
skip()
156156
#for x in 0..100:
157157
# let ha_old = ha
158158
# ha.update("hello")
159-
# assert ha != ha_old
159+
# check ha != ha_old
160160
#let h = ha.finalize()
161-
#assert bin2hex(h) == "3d76eda4eaf33f6bf73ab54a37e86e1a87a" &
161+
#check bin2hex(h) == "3d76eda4eaf33f6bf73ab54a37e86e1a87a" &
162162
# "fbe5fb803e727cbcb33c082f32035"
163163

164164
test "generic multipart hashing key = nil":
165165
let ha = new_generic_hash(nil, 33)
166166
ha.update("hello")
167167
skip()
168168
#let h = ha.finalize()
169-
#assert bin2hex(h) == "1fc1d1cb09e15737e79c9a3a687bc751e07" &
169+
#check bin2hex(h) == "1fc1d1cb09e15737e79c9a3a687bc751e07" &
170170
# "d151c2da09ecb65ea8b8b38c89b03af"
171171

172172
test "generic multipart hashing bad sizes":
@@ -186,20 +186,20 @@ suite "hashing":
186186
h = crypto_shorthash("hello", k)
187187
h2 = crypto_shorthash("hello", k)
188188
h_using_k2 = crypto_shorthash("hello", k2)
189-
assert k.len == crypto_shorthash_KEYBYTES()
190-
assert k2.len == crypto_shorthash_KEYBYTES()
191-
assert k != k2
192-
assert h.len == crypto_shorthash_BYTES()
193-
assert h == h2
194-
assert h != h_using_k2
189+
check k.len == crypto_shorthash_KEYBYTES()
190+
check k2.len == crypto_shorthash_KEYBYTES()
191+
check k != k2
192+
check h.len == crypto_shorthash_BYTES()
193+
check h == h2
194+
check h != h_using_k2
195195

196196
test "Diffie-Hellman function":
197197

198198
test "scalarmult base":
199199
let
200200
secret_key = repeat('k', crypto_scalarmult_SCALARBYTES())
201201
public_key = crypto_scalarmult_base(secret_key)
202-
assert public_key == hex2bin "8462fb3f0798f9fe2c39f3823bb41cd3effe70bb5c81735be46a143135c58454"
202+
check public_key == hex2bin "8462fb3f0798f9fe2c39f3823bb41cd3effe70bb5c81735be46a143135c58454"
203203

204204
test "scalarmult":
205205
let
@@ -209,24 +209,24 @@ test "Diffie-Hellman function":
209209
public_key2 = crypto_scalarmult_base(secret_key2)
210210
shared_secret12 = crypto_scalarmult(secret_key1, public_key2)
211211
shared_secret21 = crypto_scalarmult(secret_key2, public_key1)
212-
assert shared_secret12.bin2hex() == "806b0dffd3436ce81b12c4283db697bcfaab98571910ad33d3f385ec5409c009"
213-
assert shared_secret12 == shared_secret21
212+
check shared_secret12.bin2hex() == "806b0dffd3436ce81b12c4283db697bcfaab98571910ad33d3f385ec5409c009"
213+
check shared_secret12 == shared_secret21
214214

215215
test "poly1305 onetimeauth":
216216
let
217217
msg = repeat('m', 33)
218218
key = repeat('k', crypto_onetimeauth_KEYBYTES())
219219
tok = crypto_onetimeauth(msg, key)
220220
ok = crypto_onetimeauth_verify(tok, msg, key)
221-
assert ok
222-
assert tok.len == crypto_onetimeauth_BYTES()
221+
check ok
222+
check tok.len == crypto_onetimeauth_BYTES()
223223

224224
let bogus_msg = repeat('m', 32)
225-
assert crypto_onetimeauth_verify(tok, bogus_msg, key) == false
225+
check crypto_onetimeauth_verify(tok, bogus_msg, key) == false
226226
let bogus_tok = repeat('z', crypto_onetimeauth_BYTES())
227-
assert crypto_onetimeauth_verify(bogus_tok, msg, key) == false
227+
check crypto_onetimeauth_verify(bogus_tok, msg, key) == false
228228
let bogus_key = repeat('x', crypto_onetimeauth_KEYBYTES())
229-
assert crypto_onetimeauth_verify(tok, msg, bogus_key) == false
229+
check crypto_onetimeauth_verify(tok, msg, bogus_key) == false
230230

231231

232232
suite "HMAC":

0 commit comments

Comments
 (0)