@@ -2,7 +2,7 @@ const assert = require("node:assert/strict");
2
2
const { describe, it } = require ( "node:test" ) ;
3
3
const argon2 = require ( "./argon2.cjs" ) ;
4
4
5
- const { argon2i, argon2d, argon2id, limits } = argon2 ;
5
+ const { argon2i, argon2d, argon2id } = argon2 ;
6
6
7
7
const password = "password" ;
8
8
const salt = Buffer . alloc ( 16 , "salt" ) ;
@@ -121,17 +121,11 @@ describe("set options", () => {
121
121
assert . match ( await argon2 . hash ( password , { timeCost : 4 } ) , / t = 4 / ) ;
122
122
} ) ;
123
123
124
- it ( "hash with low time cost" , async ( ) => {
124
+ it ( "hash with high time cost" , ( ) => {
125
125
assert . rejects (
126
- argon2 . hash ( password , { timeCost : limits . timeCost . min - 1 } ) ,
127
- / i n v a l i d t i m e C o s t .+ b e t w e e n \d + a n d \d + / i,
128
- ) ;
129
- } ) ;
130
-
131
- it ( "hash with high time cost" , async ( ) => {
132
- assert . rejects (
133
- argon2 . hash ( password , { timeCost : limits . timeCost . max + 1 } ) ,
134
- / i n v a l i d t i m e C o s t .+ b e t w e e n \d + a n d \d + / i,
126
+ argon2 . hash ( password , { timeCost : Number . MAX_SAFE_INTEGER } ) ,
127
+ RangeError ,
128
+ "Time cost is too large" ,
135
129
) ;
136
130
} ) ;
137
131
@@ -140,17 +134,11 @@ describe("set options", () => {
140
134
assert . match ( await argon2 . hash ( password , { hashLength : 4 } ) , / \$ [ ^ $ ] { 6 } $ / ) ;
141
135
} ) ;
142
136
143
- it ( "hash with low hash length" , async ( ) => {
144
- assert . rejects (
145
- argon2 . hash ( password , { hashLength : limits . hashLength . min - 1 } ) ,
146
- / i n v a l i d h a s h L e n g t h .+ b e t w e e n \d + a n d \d + / i,
147
- ) ;
148
- } ) ;
149
-
150
- it ( "hash with high hash length" , async ( ) => {
137
+ it ( "hash with high hash length" , ( ) => {
151
138
assert . rejects (
152
- argon2 . hash ( password , { hashLength : limits . hashLength . max + 1 } ) ,
153
- / i n v a l i d h a s h L e n g t h .+ b e t w e e n \d + a n d \d + / i,
139
+ argon2 . hash ( password , { hashLength : Number . MAX_SAFE_INTEGER } ) ,
140
+ RangeError ,
141
+ "Hash length is too large" ,
154
142
) ;
155
143
} ) ;
156
144
@@ -161,35 +149,23 @@ describe("set options", () => {
161
149
) ;
162
150
} ) ;
163
151
164
- it ( "hash with low memory cost" , async ( ) => {
152
+ it ( "hash with high memory cost" , ( ) => {
165
153
assert . rejects (
166
- argon2 . hash ( password , { memoryCost : limits . memoryCost . min / 2 } ) ,
167
- / i n v a l i d m e m o r y C o s t .+ b e t w e e n \d + a n d \d + / i,
168
- ) ;
169
- } ) ;
170
-
171
- it ( "hash with high memory cost" , async ( ) => {
172
- assert . rejects (
173
- argon2 . hash ( password , { memoryCost : limits . memoryCost . max * 2 } ) ,
174
- / i n v a l i d m e m o r y C o s t .+ b e t w e e n \d + a n d \d + / i,
154
+ argon2 . hash ( password , { memoryCost : Number . MAX_SAFE_INTEGER } ) ,
155
+ RangeError ,
156
+ "Memory cost is too large" ,
175
157
) ;
176
158
} ) ;
177
159
178
160
it ( "hash with parallelism" , async ( ) => {
179
161
assert . match ( await argon2 . hash ( password , { parallelism : 2 } ) , / p = 2 / ) ;
180
162
} ) ;
181
163
182
- it ( "hash with low parallelism" , async ( ) => {
183
- assert . rejects (
184
- argon2 . hash ( password , { parallelism : limits . parallelism . min - 1 } ) ,
185
- / i n v a l i d p a r a l l e l i s m .+ b e t w e e n \d + a n d \d + / i,
186
- ) ;
187
- } ) ;
188
-
189
- it ( "hash with high parallelism" , async ( ) => {
164
+ it ( "hash with high parallelism" , ( ) => {
190
165
assert . rejects (
191
- argon2 . hash ( password , { parallelism : limits . parallelism . max + 1 } ) ,
192
- / i n v a l i d p a r a l l e l i s m .+ b e t w e e n \d + a n d \d + / i,
166
+ argon2 . hash ( password , { parallelism : Number . MAX_SAFE_INTEGER } ) ,
167
+ RangeError ,
168
+ "Parallelism is too large" ,
193
169
) ;
194
170
} ) ;
195
171
0 commit comments