argon2id 0.5.0-arm64-darwin → 0.7.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +35 -8
- data/Rakefile +11 -16
- data/argon2id.gemspec +3 -3
- data/ext/argon2id/argon2id.c +13 -24
- data/ext/argon2id/extconf.rb +1 -1
- data/lib/{2.6 → argon2id/2.6}/argon2id.bundle +0 -0
- data/lib/{2.7 → argon2id/2.7}/argon2id.bundle +0 -0
- data/lib/{3.0 → argon2id/3.0}/argon2id.bundle +0 -0
- data/lib/{3.1 → argon2id/3.1}/argon2id.bundle +0 -0
- data/lib/{3.3 → argon2id/3.2}/argon2id.bundle +0 -0
- data/lib/{3.2 → argon2id/3.3}/argon2id.bundle +0 -0
- data/lib/argon2id/extension.rb +70 -0
- data/lib/argon2id/password.rb +9 -2
- data/lib/argon2id/version.rb +1 -1
- data/lib/argon2id.rb +2 -65
- data/test/argon2id/test_password.rb +548 -0
- data/test/test_argon2id.rb +66 -0
- metadata +11 -11
- data/test/test_hash_encoded.rb +0 -54
- data/test/test_password.rb +0 -172
- data/test/test_verify.rb +0 -35
@@ -0,0 +1,548 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "argon2id"
|
5
|
+
|
6
|
+
class StringLike
|
7
|
+
def initialize(str)
|
8
|
+
@str = str
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
@str
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestPassword < Minitest::Test
|
17
|
+
def test_valid_hash_with_argon2id_hash_returns_true
|
18
|
+
assert Argon2id::Password.valid_hash?(
|
19
|
+
"$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
20
|
+
"$CTFhFdXPJO1aFaMaO6Mm5c8y7cJHAph8ArZWb2GRPPc"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_valid_hash_with_versionless_argon2id_hash_returns_true
|
25
|
+
assert Argon2id::Password.valid_hash?(
|
26
|
+
"$argon2id$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
27
|
+
"$CTFhFdXPJO1aFaMaO6Mm5c8y7cJHAph8ArZWb2GRPPc"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_valid_hash_with_argon2i_hash_returns_false
|
32
|
+
refute Argon2id::Password.valid_hash?(
|
33
|
+
"$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
34
|
+
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ"
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_valid_hash_with_partial_argon2id_hash_returns_false
|
39
|
+
refute Argon2id::Password.valid_hash?(
|
40
|
+
"$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_valid_hash_with_argon2id_hash_with_null_bytes_returns_false
|
45
|
+
refute Argon2id::Password.valid_hash?(
|
46
|
+
"$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
47
|
+
"$CTFhFdXPJO1aFaMaO6Mm5c8y7cJHAph8ArZWb2GRPPc\x00foo"
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_valid_hash_with_bcrypt_hash_returns_false
|
52
|
+
refute Argon2id::Password.valid_hash?(
|
53
|
+
"$2a$12$stsRn7Mi9r02.keRyF4OK.Aq4UWOU185lWggfUQfcupAi.b7AI/nS"
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_valid_hash_with_nil_returns_false
|
58
|
+
refute Argon2id::Password.valid_hash?(nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_valid_hash_with_coercible_argon2id_hash_returns_true
|
62
|
+
assert Argon2id::Password.valid_hash?(
|
63
|
+
StringLike.new(
|
64
|
+
"$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
65
|
+
"$CTFhFdXPJO1aFaMaO6Mm5c8y7cJHAph8ArZWb2GRPPc"
|
66
|
+
)
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_valid_hash_with_coercible_bcrypt_hash_returns_false
|
71
|
+
refute Argon2id::Password.valid_hash?(
|
72
|
+
StringLike.new(
|
73
|
+
"$2a$12$stsRn7Mi9r02.keRyF4OK.Aq4UWOU185lWggfUQfcupAi.b7AI/nS"
|
74
|
+
)
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_new_m_65536_t_2_p_1_equals_password
|
79
|
+
password = Argon2id::Password.new(
|
80
|
+
"$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
81
|
+
"$CTFhFdXPJO1aFaMaO6Mm5c8y7cJHAph8ArZWb2GRPPc"
|
82
|
+
)
|
83
|
+
|
84
|
+
assert password == "password"
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_new_m_262144_t_2_p_1_equals_password
|
88
|
+
password = Argon2id::Password.new(
|
89
|
+
"$argon2id$v=19$m=262144,t=2,p=1$c29tZXNhbHQ" \
|
90
|
+
"$eP4eyR+zqlZX1y5xCFTkw9m5GYx0L5YWwvCFvtlbLow"
|
91
|
+
)
|
92
|
+
|
93
|
+
assert password == "password"
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_new_m_256_t_2_p_1_equals_password
|
97
|
+
password = Argon2id::Password.new(
|
98
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
99
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
100
|
+
)
|
101
|
+
|
102
|
+
assert password == "password"
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_new_m_256_t_2_p_2_equals_password
|
106
|
+
password = Argon2id::Password.new(
|
107
|
+
"$argon2id$v=19$m=256,t=2,p=2$c29tZXNhbHQ" \
|
108
|
+
"$bQk8UB/VmZZF4Oo79iDXuL5/0ttZwg2f/5U52iv1cDc"
|
109
|
+
)
|
110
|
+
|
111
|
+
assert password == "password"
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_new_m_65536_t_1_p_1_equals_password
|
115
|
+
password = Argon2id::Password.new(
|
116
|
+
"$argon2id$v=19$m=65536,t=1,p=1$c29tZXNhbHQ" \
|
117
|
+
"$9qWtwbpyPd3vm1rB1GThgPzZ3/ydHL92zKL+15XZypg"
|
118
|
+
)
|
119
|
+
|
120
|
+
assert password == "password"
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_new_m_65536_t_4_p_1_equals_password
|
124
|
+
password = Argon2id::Password.new(
|
125
|
+
"$argon2id$v=19$m=65536,t=4,p=1$c29tZXNhbHQ" \
|
126
|
+
"$kCXUjmjvc5XMqQedpMTsOv+zyJEf5PhtGiUghW9jFyw"
|
127
|
+
)
|
128
|
+
|
129
|
+
assert password == "password"
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_new_m_65536_t_2_p_1_equals_differentpassword
|
133
|
+
password = Argon2id::Password.new(
|
134
|
+
"$argon2id$v=19$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
135
|
+
"$C4TWUs9rDEvq7w3+J4umqA32aWKB1+DSiRuBfYxFj94"
|
136
|
+
)
|
137
|
+
|
138
|
+
assert password == "differentpassword"
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_new_m_65536_t_2_p_1_with_diffsalt_equals_password
|
142
|
+
password = Argon2id::Password.new(
|
143
|
+
"$argon2id$v=19$m=65536,t=2,p=1$ZGlmZnNhbHQ" \
|
144
|
+
"$vfMrBczELrFdWP0ZsfhWsRPaHppYdP3MVEMIVlqoFBw"
|
145
|
+
)
|
146
|
+
|
147
|
+
assert password == "password"
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_new_with_versionless_hash_equals_password
|
151
|
+
password = Argon2id::Password.new(
|
152
|
+
"$argon2id$m=256,t=2,p=1$c29tZXNhbHQ" \
|
153
|
+
"$2gcOV25Q8vOKPIl8vdxsf7QCjocJcf+erntOGHkpXm4"
|
154
|
+
)
|
155
|
+
|
156
|
+
assert password == "password"
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_new_with_non_argon2id_hash_raises_argument_error
|
160
|
+
assert_raises(ArgumentError) do
|
161
|
+
Argon2id::Password.new(
|
162
|
+
"$argon2i$m=65536,t=2,p=1$c29tZXNhbHQ" \
|
163
|
+
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ"
|
164
|
+
)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_new_with_invalid_hash_raises_argument_error
|
169
|
+
assert_raises(ArgumentError) do
|
170
|
+
Argon2id::Password.new("not a valid hash")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_new_with_nil_raises_argument_error
|
175
|
+
assert_raises(ArgumentError) do
|
176
|
+
Argon2id::Password.new(nil)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_new_with_coercible_equals_password
|
181
|
+
password = Argon2id::Password.new(
|
182
|
+
StringLike.new(
|
183
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
184
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
185
|
+
)
|
186
|
+
)
|
187
|
+
|
188
|
+
assert password == "password"
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_encoded_returns_the_full_encoded_hash
|
192
|
+
password = Argon2id::Password.new(
|
193
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
194
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
195
|
+
)
|
196
|
+
|
197
|
+
assert_equal(
|
198
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
|
199
|
+
password.encoded
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_version_returns_the_version
|
204
|
+
password = Argon2id::Password.new(
|
205
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
206
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
207
|
+
)
|
208
|
+
|
209
|
+
assert_equal(19, password.version)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_version_with_no_version_returns_the_default_version
|
213
|
+
password = Argon2id::Password.new(
|
214
|
+
"$argon2id$m=256,t=2,p=1$c29tZXNhbHQ" \
|
215
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
216
|
+
)
|
217
|
+
|
218
|
+
assert_equal(16, password.version)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_m_cost_returns_m_cost
|
222
|
+
password = Argon2id::Password.new(
|
223
|
+
"$argon2id$m=256,t=2,p=1$c29tZXNhbHQ" \
|
224
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
225
|
+
)
|
226
|
+
|
227
|
+
assert_equal(256, password.m_cost)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_t_cost_returns_t_cost
|
231
|
+
password = Argon2id::Password.new(
|
232
|
+
"$argon2id$m=256,t=2,p=1$c29tZXNhbHQ" \
|
233
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
234
|
+
)
|
235
|
+
|
236
|
+
assert_equal(2, password.t_cost)
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_parallelism_returns_parallelism
|
240
|
+
password = Argon2id::Password.new(
|
241
|
+
"$argon2id$m=256,t=2,p=1$c29tZXNhbHQ" \
|
242
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
243
|
+
)
|
244
|
+
|
245
|
+
assert_equal(1, password.parallelism)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_salt_returns_decoded_salt
|
249
|
+
password = Argon2id::Password.new(
|
250
|
+
"$argon2id$m=256,t=2,p=1$c29tZXNhbHQ" \
|
251
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
252
|
+
)
|
253
|
+
|
254
|
+
assert_equal("somesalt", password.salt)
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_salt_returns_decoded_binary_salt
|
258
|
+
password = Argon2id::Password.new(
|
259
|
+
"$argon2id$v=19$m=256,t=2,p=1$FImSDfu1p8vf1mZBL2PCkg" \
|
260
|
+
"$vG4bIkTJGMx6OvkLuKTeq37DTyAf8gF2Ouf3zSLlYVc"
|
261
|
+
)
|
262
|
+
|
263
|
+
assert_equal(
|
264
|
+
"\x14\x89\x92\r\xFB\xB5\xA7\xCB\xDF\xD6fA/c\xC2\x92".b,
|
265
|
+
password.salt
|
266
|
+
)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_output_returns_decoded_output
|
270
|
+
password = Argon2id::Password.new(
|
271
|
+
"$argon2id$v=19$m=65536,t=1,p=1$c29tZXNhbHQ" \
|
272
|
+
"$9qWtwbpyPd3vm1rB1GThgPzZ3/ydHL92zKL+15XZypg"
|
273
|
+
)
|
274
|
+
|
275
|
+
assert_equal(
|
276
|
+
"\xF6\xA5\xAD\xC1\xBAr=\xDD\xEF\x9BZ\xC1\xD4d\xE1\x80\xFC\xD9\xDF\xFC\x9D\x1C\xBFv\xCC\xA2\xFE\xD7\x95\xD9\xCA\x98".b,
|
277
|
+
password.output
|
278
|
+
)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_to_s_returns_the_full_encoded_hash
|
282
|
+
password = Argon2id::Password.new(
|
283
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
284
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
285
|
+
)
|
286
|
+
|
287
|
+
assert_equal(
|
288
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
|
289
|
+
password.to_s
|
290
|
+
)
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_equals_correct_password_returns_true
|
294
|
+
password = Argon2id::Password.new(
|
295
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
296
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
297
|
+
)
|
298
|
+
|
299
|
+
assert password == "password"
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_equals_incorrect_password_returns_false
|
303
|
+
password = Argon2id::Password.new(
|
304
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
305
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
306
|
+
)
|
307
|
+
|
308
|
+
refute password == "differentpassword"
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_equals_nil_returns_false
|
312
|
+
password = Argon2id::Password.new(
|
313
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
314
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
315
|
+
)
|
316
|
+
|
317
|
+
refute password == nil
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_equals_coercible_correct_password_returns_true
|
321
|
+
password = Argon2id::Password.new(
|
322
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
323
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
324
|
+
)
|
325
|
+
|
326
|
+
assert password == StringLike.new("password")
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_equals_coercible_incorrect_password_returns_false
|
330
|
+
password = Argon2id::Password.new(
|
331
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
332
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
333
|
+
)
|
334
|
+
|
335
|
+
refute password == StringLike.new("differentpassword")
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_is_password_correct_password_returns_true
|
339
|
+
password = Argon2id::Password.new(
|
340
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
341
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
342
|
+
)
|
343
|
+
|
344
|
+
assert password.is_password?("password")
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_is_password_incorrect_password_returns_false
|
348
|
+
password = Argon2id::Password.new(
|
349
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
350
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
351
|
+
)
|
352
|
+
|
353
|
+
refute password.is_password?("differentpassword")
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_is_password_nil_returns_false
|
357
|
+
password = Argon2id::Password.new(
|
358
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
359
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
360
|
+
)
|
361
|
+
|
362
|
+
refute password.is_password?(nil)
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_is_password_coercible_correct_password_returns_true
|
366
|
+
password = Argon2id::Password.new(
|
367
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
368
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
369
|
+
)
|
370
|
+
|
371
|
+
assert password.is_password?(StringLike.new("password"))
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_is_password_coercible_incorrect_password_returns_false
|
375
|
+
password = Argon2id::Password.new(
|
376
|
+
"$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ" \
|
377
|
+
"$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4"
|
378
|
+
)
|
379
|
+
|
380
|
+
refute password.is_password?(StringLike.new("differentpassword"))
|
381
|
+
end
|
382
|
+
|
383
|
+
def test_create_password_returns_password
|
384
|
+
password = Argon2id::Password.create("password")
|
385
|
+
|
386
|
+
assert_instance_of Argon2id::Password, password
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_create_password_uses_default_t_cost
|
390
|
+
password = Argon2id::Password.create("password")
|
391
|
+
|
392
|
+
assert_equal 2, password.t_cost
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_create_password_uses_default_m_cost
|
396
|
+
password = Argon2id::Password.create("password")
|
397
|
+
|
398
|
+
assert_equal 19_456, password.m_cost
|
399
|
+
end
|
400
|
+
|
401
|
+
def test_create_password_uses_default_parallelism
|
402
|
+
password = Argon2id::Password.create("password")
|
403
|
+
|
404
|
+
assert_equal 1, password.parallelism
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_create_password_uses_default_salt_len
|
408
|
+
password = Argon2id::Password.create("password")
|
409
|
+
|
410
|
+
assert_equal 16, password.salt.bytesize
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_create_password_uses_default_output_len
|
414
|
+
password = Argon2id::Password.create("password")
|
415
|
+
|
416
|
+
assert_equal 32, password.output.bytesize
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_create_password_with_t_cost_changes_t_cost
|
420
|
+
password = Argon2id::Password.create("password", t_cost: 1)
|
421
|
+
|
422
|
+
assert_equal(1, password.t_cost)
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_create_password_with_too_small_t_cost_raises_error
|
426
|
+
assert_raises(Argon2id::Error) do
|
427
|
+
Argon2id::Password.create("password", t_cost: 0)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
def test_create_password_with_m_cost_changes_m_cost
|
432
|
+
password = Argon2id::Password.create("password", m_cost: 8)
|
433
|
+
|
434
|
+
assert_equal(8, password.m_cost)
|
435
|
+
end
|
436
|
+
|
437
|
+
def test_create_password_with_too_small_m_cost_raises_error
|
438
|
+
assert_raises(Argon2id::Error) do
|
439
|
+
Argon2id::Password.create("password", m_cost: 0)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
def test_create_password_with_parallelism_changes_parallelism
|
444
|
+
password = Argon2id::Password.create("password", parallelism: 2)
|
445
|
+
|
446
|
+
assert_equal(2, password.parallelism)
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_create_password_with_too_small_parallelism_raises_error
|
450
|
+
assert_raises(Argon2id::Error) do
|
451
|
+
Argon2id::Password.create("password", parallelism: 0)
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_create_password_with_too_small_salt_raises_error
|
456
|
+
assert_raises(Argon2id::Error) do
|
457
|
+
Argon2id::Password.create("password", salt_len: 0)
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
def test_create_password_with_output_len_changes_output_len
|
462
|
+
password = Argon2id::Password.create("password", output_len: 8)
|
463
|
+
|
464
|
+
assert_equal 8, password.output.bytesize
|
465
|
+
end
|
466
|
+
|
467
|
+
def test_create_password_with_too_output_len_raises_error
|
468
|
+
assert_raises(Argon2id::Error) do
|
469
|
+
Argon2id::Password.create("password", output_len: 0)
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
def test_create_password_inherits_t_cost_from_argon2id
|
474
|
+
Argon2id.t_cost = 1
|
475
|
+
|
476
|
+
password = Argon2id::Password.create("password")
|
477
|
+
|
478
|
+
assert_equal(1, password.t_cost)
|
479
|
+
ensure
|
480
|
+
Argon2id.t_cost = Argon2id::DEFAULT_T_COST
|
481
|
+
end
|
482
|
+
|
483
|
+
def test_create_password_inherits_m_cost_from_argon2id
|
484
|
+
Argon2id.m_cost = 8
|
485
|
+
|
486
|
+
password = Argon2id::Password.create("password")
|
487
|
+
|
488
|
+
assert_equal(8, password.m_cost)
|
489
|
+
ensure
|
490
|
+
Argon2id.m_cost = Argon2id::DEFAULT_M_COST
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_create_password_inherits_parallelism_from_argon2id
|
494
|
+
Argon2id.parallelism = 2
|
495
|
+
|
496
|
+
password = Argon2id::Password.create("password")
|
497
|
+
|
498
|
+
assert_equal(2, password.parallelism)
|
499
|
+
ensure
|
500
|
+
Argon2id.parallelism = Argon2id::DEFAULT_PARALLELISM
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_create_password_inherits_salt_len_from_argon2id
|
504
|
+
Argon2id.salt_len = 8
|
505
|
+
|
506
|
+
password = Argon2id::Password.create("password")
|
507
|
+
|
508
|
+
assert_equal(8, password.salt.bytesize)
|
509
|
+
ensure
|
510
|
+
Argon2id.salt_len = Argon2id::DEFAULT_SALT_LEN
|
511
|
+
end
|
512
|
+
|
513
|
+
def test_create_password_inherits_output_len_from_argon2id
|
514
|
+
Argon2id.output_len = 8
|
515
|
+
|
516
|
+
password = Argon2id::Password.create("password")
|
517
|
+
|
518
|
+
assert_equal(8, password.output.bytesize)
|
519
|
+
ensure
|
520
|
+
Argon2id.output_len = Argon2id::DEFAULT_OUTPUT_LEN
|
521
|
+
end
|
522
|
+
|
523
|
+
def test_create_password_equals_correct_password
|
524
|
+
password = Argon2id::Password.create("password")
|
525
|
+
|
526
|
+
assert password == "password"
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_create_password_does_not_equal_incorrect_password
|
530
|
+
password = Argon2id::Password.create("password")
|
531
|
+
|
532
|
+
refute password == "differentpassword"
|
533
|
+
end
|
534
|
+
|
535
|
+
def test_hashing_password_verifies_correct_password
|
536
|
+
hash = Argon2id::Password.create("password").to_s
|
537
|
+
password = Argon2id::Password.new(hash)
|
538
|
+
|
539
|
+
assert password == "password"
|
540
|
+
end
|
541
|
+
|
542
|
+
def test_hashing_password_does_not_verify_incorrect_password
|
543
|
+
hash = Argon2id::Password.create("password").to_s
|
544
|
+
password = Argon2id::Password.new(hash)
|
545
|
+
|
546
|
+
refute password == "differentpassword"
|
547
|
+
end
|
548
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minitest/autorun"
|
4
|
+
require "argon2id"
|
5
|
+
|
6
|
+
class TestArgon2id < Minitest::Test
|
7
|
+
def test_t_cost_is_default_t_cost
|
8
|
+
assert_equal 2, Argon2id.t_cost
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_m_cost_is_default_m_cost
|
12
|
+
assert_equal 19_456, Argon2id.m_cost
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_parallelism_is_default_parallelism
|
16
|
+
assert_equal 1, Argon2id.parallelism
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_salt_len_is_default_salt_len
|
20
|
+
assert_equal 16, Argon2id.salt_len
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_output_len_is_default_output_len
|
24
|
+
assert_equal 32, Argon2id.output_len
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_t_cost_can_be_overridden
|
28
|
+
Argon2id.t_cost = 1
|
29
|
+
|
30
|
+
assert_equal 1, Argon2id.t_cost
|
31
|
+
ensure
|
32
|
+
Argon2id.t_cost = Argon2id::DEFAULT_T_COST
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_m_cost_can_be_overridden
|
36
|
+
Argon2id.m_cost = 256
|
37
|
+
|
38
|
+
assert_equal 256, Argon2id.m_cost
|
39
|
+
ensure
|
40
|
+
Argon2id.m_cost = Argon2id::DEFAULT_M_COST
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_parallelism_can_be_overridden
|
44
|
+
Argon2id.parallelism = 2
|
45
|
+
|
46
|
+
assert_equal 2, Argon2id.parallelism
|
47
|
+
ensure
|
48
|
+
Argon2id.parallelism = Argon2id::DEFAULT_PARALLELISM
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_salt_len_can_be_overridden
|
52
|
+
Argon2id.salt_len = 8
|
53
|
+
|
54
|
+
assert_equal 8, Argon2id.salt_len
|
55
|
+
ensure
|
56
|
+
Argon2id.salt_len = Argon2id::DEFAULT_SALT_LEN
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_output_len_can_be_overridden
|
60
|
+
Argon2id.output_len = 16
|
61
|
+
|
62
|
+
assert_equal 16, Argon2id.output_len
|
63
|
+
ensure
|
64
|
+
Argon2id.output_len = Argon2id::DEFAULT_OUTPUT_LEN
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argon2id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -82,18 +82,18 @@ files:
|
|
82
82
|
- ext/argon2id/libargon2/ref.c
|
83
83
|
- ext/argon2id/libargon2/thread.c
|
84
84
|
- ext/argon2id/libargon2/thread.h
|
85
|
-
- lib/2.6/argon2id.bundle
|
86
|
-
- lib/2.7/argon2id.bundle
|
87
|
-
- lib/3.0/argon2id.bundle
|
88
|
-
- lib/3.1/argon2id.bundle
|
89
|
-
- lib/3.2/argon2id.bundle
|
90
|
-
- lib/3.3/argon2id.bundle
|
91
85
|
- lib/argon2id.rb
|
86
|
+
- lib/argon2id/2.6/argon2id.bundle
|
87
|
+
- lib/argon2id/2.7/argon2id.bundle
|
88
|
+
- lib/argon2id/3.0/argon2id.bundle
|
89
|
+
- lib/argon2id/3.1/argon2id.bundle
|
90
|
+
- lib/argon2id/3.2/argon2id.bundle
|
91
|
+
- lib/argon2id/3.3/argon2id.bundle
|
92
|
+
- lib/argon2id/extension.rb
|
92
93
|
- lib/argon2id/password.rb
|
93
94
|
- lib/argon2id/version.rb
|
94
|
-
- test/
|
95
|
-
- test/
|
96
|
-
- test/test_verify.rb
|
95
|
+
- test/argon2id/test_password.rb
|
96
|
+
- test/test_argon2id.rb
|
97
97
|
homepage: https://github.com/mudge/argon2id
|
98
98
|
licenses:
|
99
99
|
- BSD-3-Clause
|
data/test/test_hash_encoded.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "minitest/autorun"
|
4
|
-
require "argon2id"
|
5
|
-
|
6
|
-
class TestHashEncoded < Minitest::Test
|
7
|
-
def test_valid_password_and_salt_encodes_successfully
|
8
|
-
encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
|
9
|
-
|
10
|
-
assert_equal "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4", encoded
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_password_with_parallelism_of_two
|
14
|
-
encoded = Argon2id.hash_encoded(2, 256, 2, "password", "somesalt", 32)
|
15
|
-
|
16
|
-
assert_equal "$argon2id$v=19$m=256,t=2,p=2$c29tZXNhbHQ$bQk8UB/VmZZF4Oo79iDXuL5/0ttZwg2f/5U52iv1cDc", encoded
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_valid_password_does_not_include_trailing_null_byte
|
20
|
-
encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
|
21
|
-
|
22
|
-
refute encoded.end_with?("\x00")
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_raises_with_too_short_output
|
26
|
-
assert_raises(Argon2id::Error) do
|
27
|
-
Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 1)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_raises_with_too_few_lanes
|
32
|
-
assert_raises(Argon2id::Error) do
|
33
|
-
Argon2id.hash_encoded(2, 256, 0, "password", "somesalt", 32)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_raises_with_too_small_memory_cost
|
38
|
-
assert_raises(Argon2id::Error) do
|
39
|
-
Argon2id.hash_encoded(2, 0, 1, "password", "somesalt", 32)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_raises_with_too_small_time_cost
|
44
|
-
assert_raises(Argon2id::Error) do
|
45
|
-
Argon2id.hash_encoded(0, 256, 1, "password", "somesalt", 32)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_raises_with_too_short_salt
|
50
|
-
assert_raises(Argon2id::Error) do
|
51
|
-
Argon2id.hash_encoded(2, 256, 1, "password", "", 32)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|