@@ -12,80 +12,80 @@ import 'package:test/test.dart';
12
12
void main () {
13
13
// Argon2i test group
14
14
group ('Hash Tests - Argon2i' , () {
15
- test ('v = ${0x13 }, t = 2, m = 16, p = 1,' , () {
16
- var code = hashTest (Argon2Version .V13 , 2 , 16 , 1 , 'password' , 'somesalt' ,
15
+ test ('v = ${0x13 }, t = 2, m = 16, p = 1,' , () async {
16
+ var code = await hashTest (Argon2Version .V13 , 2 , 16 , 1 , 'password' , 'somesalt' ,
17
17
'03df1d13e10203bcc663405e31ab1687939730c9152459bca28fd10c23e38f50' ,
18
18
'\$ argon2i\$ v=19\$ m=16,t=2,p=1\$ c29tZXNhbHQ\$ A98dE+ECA7zGY0BeMasWh5OXMMkVJFm8oo/RDCPjj1A' , Argon2Type .i);
19
19
expect (code, DArgon2ErrorCode .ARGON2_OK );
20
20
});
21
- test ('v = ${0x13 }, t = 2, m = 18, p = 1,' , () {
22
- var code = hashTest (Argon2Version .V13 , 2 , 18 , 1 , 'password' , 'somesalt' ,
21
+ test ('v = ${0x13 }, t = 2, m = 18, p = 1,' , () async {
22
+ var code = await hashTest (Argon2Version .V13 , 2 , 18 , 1 , 'password' , 'somesalt' ,
23
23
'3b1b4ad0a66b3f00b4cd04225e4e6da950ee152bf0d29aabcb123c2f1a90567a' ,
24
24
'\$ argon2i\$ v=19\$ m=18,t=2,p=1\$ c29tZXNhbHQ\$ OxtK0KZrPwC0zQQiXk5tqVDuFSvw0pqryxI8LxqQVno' , Argon2Type .i);
25
25
expect (code, DArgon2ErrorCode .ARGON2_OK );
26
26
});
27
- test ('v = ${0x13 }, t = 2, m = 8, p = 1,' , () {
28
- var code = hashTest (Argon2Version .V13 , 2 , 8 , 1 , 'password' , 'somesalt' ,
27
+ test ('v = ${0x13 }, t = 2, m = 8, p = 1,' , () async {
28
+ var code = await hashTest (Argon2Version .V13 , 2 , 8 , 1 , 'password' , 'somesalt' ,
29
29
'48cc13c16c5a2d254a278e2c44420ba0fb2d0f070661e35d6486604a7a2ff1a9' ,
30
30
'\$ argon2i\$ v=19\$ m=8,t=2,p=1\$ c29tZXNhbHQ\$ SMwTwWxaLSVKJ44sREILoPstDwcGYeNdZIZgSnov8ak' , Argon2Type .i);
31
31
expect (code, DArgon2ErrorCode .ARGON2_OK );
32
32
});
33
- test ('v = ${0x13 }, t = 2, m = 16, p = 2,' , () {
34
- var code = hashTest (Argon2Version .V13 , 2 , 16 , 2 , 'password' , 'somesalt' ,
33
+ test ('v = ${0x13 }, t = 2, m = 16, p = 2,' , () async {
34
+ var code = await hashTest (Argon2Version .V13 , 2 , 16 , 2 , 'password' , 'somesalt' ,
35
35
'7fbb85db7e9636115f2fd0f29ea4214baaada18b39fffed7875eeb9fa9b308c5' ,
36
36
'\$ argon2i\$ v=19\$ m=16,t=2,p=2\$ c29tZXNhbHQ\$ f7uF236WNhFfL9DynqQhS6qtoYs5//7Xh17rn6mzCMU' , Argon2Type .i);
37
37
expect (code, DArgon2ErrorCode .ARGON2_OK );
38
38
});
39
39
});
40
40
// Argon2d test group
41
41
group ('Hash Tests - Argon2d' , () {
42
- test ('v = ${0x13 }, t = 2, m = 16, p = 1,' , () {
43
- var code = hashTest (Argon2Version .V13 , 2 , 16 , 1 , 'password' , 'somesalt' ,
42
+ test ('v = ${0x13 }, t = 2, m = 16, p = 1,' , () async {
43
+ var code = await hashTest (Argon2Version .V13 , 2 , 16 , 1 , 'password' , 'somesalt' ,
44
44
'e742c05880c44c4df5fe79937be77897a6e41ca758affc42301f1e4040e35bd2' ,
45
45
'\$ argon2d\$ v=19\$ m=16,t=2,p=1\$ c29tZXNhbHQ\$ 50LAWIDETE31/nmTe+d4l6bkHKdYr/xCMB8eQEDjW9I' , Argon2Type .d);
46
46
expect (code, DArgon2ErrorCode .ARGON2_OK );
47
47
});
48
- test ('v = ${0x13 }, t = 2, m = 18, p = 1,' , () {
49
- var code = hashTest (Argon2Version .V13 , 2 , 18 , 1 , 'password' , 'somesalt' ,
48
+ test ('v = ${0x13 }, t = 2, m = 18, p = 1,' , () async {
49
+ var code = await hashTest (Argon2Version .V13 , 2 , 18 , 1 , 'password' , 'somesalt' ,
50
50
'd24d7d614122db6458d66b4f35dc45b1cca59f9b71945db207e78062601d2dd5' ,
51
51
'\$ argon2d\$ v=19\$ m=18,t=2,p=1\$ c29tZXNhbHQ\$ 0k19YUEi22RY1mtPNdxFscyln5txlF2yB+eAYmAdLdU' , Argon2Type .d);
52
52
expect (code, DArgon2ErrorCode .ARGON2_OK );
53
53
});
54
- test ('v = ${0x13 }, t = 2, m = 8, p = 1,' , () {
55
- var code = hashTest (Argon2Version .V13 , 2 , 8 , 1 , 'password' , 'somesalt' ,
54
+ test ('v = ${0x13 }, t = 2, m = 8, p = 1,' , () async {
55
+ var code = await hashTest (Argon2Version .V13 , 2 , 8 , 1 , 'password' , 'somesalt' ,
56
56
'7d124315b3ba588668393b2e2d6867bd9f211a4eebd240d0023e540a783a69f0' ,
57
57
'\$ argon2d\$ v=19\$ m=8,t=2,p=1\$ c29tZXNhbHQ\$ fRJDFbO6WIZoOTsuLWhnvZ8hGk7r0kDQAj5UCng6afA' , Argon2Type .d);
58
58
expect (code, DArgon2ErrorCode .ARGON2_OK );
59
59
});
60
- test ('v = ${0x13 }, t = 2, m = 16, p = 2,' , () {
61
- var code = hashTest (Argon2Version .V13 , 2 , 16 , 2 , 'password' , 'somesalt' ,
60
+ test ('v = ${0x13 }, t = 2, m = 16, p = 2,' , () async {
61
+ var code = await hashTest (Argon2Version .V13 , 2 , 16 , 2 , 'password' , 'somesalt' ,
62
62
'59f20a66a4c31bf0438a2f494867c32120409a91380f0687aefee984ba86bda8' ,
63
63
'\$ argon2d\$ v=19\$ m=16,t=2,p=2\$ c29tZXNhbHQ\$ WfIKZqTDG/BDii9JSGfDISBAmpE4DwaHrv7phLqGvag' , Argon2Type .d);
64
64
expect (code, DArgon2ErrorCode .ARGON2_OK );
65
65
});
66
66
});
67
67
// Argon2id test group
68
68
group ('Hash Tests - Argon2id' , () {
69
- test ('v = ${0x13 }, t = 2, m = 16, p = 1,' , () {
70
- var code = hashTest (Argon2Version .V13 , 2 , 16 , 1 , 'password' , 'somesalt' ,
69
+ test ('v = ${0x13 }, t = 2, m = 16, p = 1,' , () async {
70
+ var code = await hashTest (Argon2Version .V13 , 2 , 16 , 1 , 'password' , 'somesalt' ,
71
71
'058202c0723cd88c24408ccac1cbf828dee63bcf3843a150ea364a1e0b4e1ff8' ,
72
72
'\$ argon2id\$ v=19\$ m=16,t=2,p=1\$ c29tZXNhbHQ\$ BYICwHI82IwkQIzKwcv4KN7mO884Q6FQ6jZKHgtOH/g' , Argon2Type .id);
73
73
expect (code, DArgon2ErrorCode .ARGON2_OK );
74
74
});
75
- test ('v = ${0x13 }, t = 2, m = 18, p = 1,' , () {
76
- var code = hashTest (Argon2Version .V13 , 2 , 18 , 1 , 'password' , 'somesalt' ,
75
+ test ('v = ${0x13 }, t = 2, m = 18, p = 1,' , () async {
76
+ var code = await hashTest (Argon2Version .V13 , 2 , 18 , 1 , 'password' , 'somesalt' ,
77
77
'0e6408c954c4980f6313756ea01ee7ddebb362efbb20d49d08a6859787024e3f' ,
78
78
'\$ argon2id\$ v=19\$ m=18,t=2,p=1\$ c29tZXNhbHQ\$ DmQIyVTEmA9jE3VuoB7n3euzYu+7INSdCKaFl4cCTj8' , Argon2Type .id);
79
79
expect (code, DArgon2ErrorCode .ARGON2_OK );
80
80
});
81
- test ('v = ${0x13 }, t = 2, m = 8, p = 1,' , () {
82
- var code = hashTest (Argon2Version .V13 , 2 , 8 , 1 , 'password' , 'somesalt' ,
81
+ test ('v = ${0x13 }, t = 2, m = 8, p = 1,' , () async {
82
+ var code = await hashTest (Argon2Version .V13 , 2 , 8 , 1 , 'password' , 'somesalt' ,
83
83
'fdb4ddb6d5887131b66f0b2a3740c077dd05b755845861f6b5a1dde8b1071646' ,
84
84
'\$ argon2id\$ v=19\$ m=8,t=2,p=1\$ c29tZXNhbHQ\$ /bTdttWIcTG2bwsqN0DAd90Ft1WEWGH2taHd6LEHFkY' , Argon2Type .id);
85
85
expect (code, DArgon2ErrorCode .ARGON2_OK );
86
86
});
87
- test ('v = ${0x13 }, t = 2, m = 16, p = 2,' , () {
88
- var code = hashTest (Argon2Version .V13 , 2 , 16 , 2 , 'password' , 'somesalt' ,
87
+ test ('v = ${0x13 }, t = 2, m = 16, p = 2,' , () async {
88
+ var code = await hashTest (Argon2Version .V13 , 2 , 16 , 2 , 'password' , 'somesalt' ,
89
89
'747d7631b182faf749d7efc31aec31df4ecfe3b57c792f53800ac2c9978b4888' ,
90
90
'\$ argon2id\$ v=19\$ m=16,t=2,p=2\$ c29tZXNhbHQ\$ dH12MbGC+vdJ1+/DGuwx307P47V8eS9TgArCyZeLSIg' , Argon2Type .id);
91
91
expect (code, DArgon2ErrorCode .ARGON2_OK );
@@ -94,42 +94,43 @@ void main() {
94
94
}
95
95
96
96
//Testing method to check the argon2 tester hashes
97
- DArgon2ErrorCode hashTest (Argon2Version version, int iterations, int memory, int parallelism, String password, String salt, String hexHash, String encodedHash, Argon2Type type) {
97
+ Future < DArgon2ErrorCode > hashTest (Argon2Version version, int iterations, int memory, int parallelism, String password, String salt, String hexHash, String encodedHash, Argon2Type type) async {
98
98
var s = Salt (utf8.encode (salt));
99
99
DArgon2Result resultString;
100
100
DArgon2Result resultBytes;
101
101
// get hashed results
102
102
try {
103
- resultString = argon2.hashPasswordStringSync (password, salt: s,
103
+ resultString = await argon2.hashPasswordString (password, salt: s,
104
104
iterations: iterations,
105
105
memory: memory,
106
106
parallelism: parallelism,
107
107
version: version,
108
108
type: type);
109
- resultBytes = argon2.hashPasswordBytesSync (utf8.encode (password), salt: s,
109
+ resultBytes = await argon2.hashPasswordBytes (utf8.encode (password), salt: s,
110
110
iterations: iterations,
111
111
memory: memory,
112
112
parallelism: parallelism,
113
113
version: version,
114
114
type: type);
115
+ // Test both bytes and string for equaluty
116
+ if (resultString.encodedString != resultBytes.encodedString) {
117
+ return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
118
+ }
119
+ // Check if both hex strings are equivalent to the one given
120
+ if (resultBytes.hexString != hexHash || resultString.hexString != hexHash) {
121
+ return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
122
+ }
123
+ // Check if both are verified
124
+ if (! await argon2.verifyHashString (password, encodedHash, type: type) || ! await argon2.verifyHashBytes (utf8.encode (password), utf8.encode (encodedHash), type: type)) {
125
+ return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
126
+ }
127
+ // Check if both are verified against each other
128
+ if (! await argon2.verifyHashString (password, resultBytes.encodedString, type: type) || ! await argon2.verifyHashString (password, resultString.encodedString, type: type)) {
129
+ return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
130
+ }
131
+ return DArgon2ErrorCode .ARGON2_OK ;
132
+
115
133
} on DArgon2Exception catch (e) {
116
134
return e.errorCode;
117
135
}
118
- // Test both bytes and string for equaluty
119
- if (resultString.encodedString != resultBytes.encodedString) {
120
- return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
121
- }
122
- // Check if both hex strings are equivalent to the one given
123
- if (resultBytes.hexString != hexHash || resultString.hexString != hexHash) {
124
- return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
125
- }
126
- // Check if both are verified
127
- if (! argon2.verifyHashStringSync (password, encodedHash, type: type) || ! argon2.verifyHashBytesSync (utf8.encode (password), utf8.encode (encodedHash), type: type)) {
128
- return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
129
- }
130
- // Check if both are verified against each other
131
- if (! argon2.verifyHashStringSync (password, resultBytes.encodedString, type: type) || ! argon2.verifyHashStringSync (password, resultString.encodedString, type: type)) {
132
- return DArgon2ErrorCode .ARGON2_UNKNOWN_ERROR ;
133
- }
134
- return DArgon2ErrorCode .ARGON2_OK ;
135
- }
136
+ }
0 commit comments