@nivinjoseph/n-sec 5.0.4 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/.eslintrc +13 -4
  2. package/.vscode/settings.json +103 -0
  3. package/.yarn/releases/yarn-4.0.2.cjs +893 -0
  4. package/.yarnrc.yml +3 -0
  5. package/dist/api-security/alg-type.d.ts +1 -0
  6. package/dist/api-security/alg-type.d.ts.map +1 -0
  7. package/dist/api-security/alg-type.js +2 -5
  8. package/dist/api-security/alg-type.js.map +1 -1
  9. package/dist/api-security/claim.d.ts +1 -0
  10. package/dist/api-security/claim.d.ts.map +1 -0
  11. package/dist/api-security/claim.js +5 -9
  12. package/dist/api-security/claim.js.map +1 -1
  13. package/dist/api-security/claims-identity.d.ts +2 -1
  14. package/dist/api-security/claims-identity.d.ts.map +1 -0
  15. package/dist/api-security/claims-identity.js +4 -8
  16. package/dist/api-security/claims-identity.js.map +1 -1
  17. package/dist/api-security/expired-token-exception.d.ts +1 -0
  18. package/dist/api-security/expired-token-exception.d.ts.map +1 -0
  19. package/dist/api-security/expired-token-exception.js +5 -9
  20. package/dist/api-security/expired-token-exception.js.map +1 -1
  21. package/dist/api-security/invalid-token-exception.d.ts +1 -0
  22. package/dist/api-security/invalid-token-exception.d.ts.map +1 -0
  23. package/dist/api-security/invalid-token-exception.js +7 -11
  24. package/dist/api-security/invalid-token-exception.js.map +1 -1
  25. package/dist/api-security/json-web-token.d.ts +3 -2
  26. package/dist/api-security/json-web-token.d.ts.map +1 -0
  27. package/dist/api-security/json-web-token.js +39 -43
  28. package/dist/api-security/json-web-token.js.map +1 -1
  29. package/dist/api-security/security-token.d.ts +1 -0
  30. package/dist/api-security/security-token.d.ts.map +1 -0
  31. package/dist/api-security/security-token.js +6 -10
  32. package/dist/api-security/security-token.js.map +1 -1
  33. package/dist/bin.d.ts +1 -0
  34. package/dist/bin.d.ts.map +1 -0
  35. package/dist/bin.js +15 -20
  36. package/dist/bin.js.map +1 -1
  37. package/dist/crypto/asymmetric-encryption.d.ts +2 -0
  38. package/dist/crypto/asymmetric-encryption.d.ts.map +1 -0
  39. package/dist/crypto/asymmetric-encryption.js +1 -1
  40. package/dist/crypto/asymmetric-encryption.js.map +1 -1
  41. package/dist/crypto/crypto-exception.d.ts +1 -0
  42. package/dist/crypto/crypto-exception.d.ts.map +1 -0
  43. package/dist/crypto/crypto-exception.js +2 -6
  44. package/dist/crypto/crypto-exception.js.map +1 -1
  45. package/dist/crypto/digital-signature.d.ts +2 -0
  46. package/dist/crypto/digital-signature.d.ts.map +1 -0
  47. package/dist/crypto/digital-signature.js +1 -1
  48. package/dist/crypto/digital-signature.js.map +1 -1
  49. package/dist/crypto/hash.d.ts +1 -0
  50. package/dist/crypto/hash.d.ts.map +1 -0
  51. package/dist/crypto/hash.js +9 -12
  52. package/dist/crypto/hash.js.map +1 -1
  53. package/dist/crypto/hmac.d.ts +1 -0
  54. package/dist/crypto/hmac.d.ts.map +1 -0
  55. package/dist/crypto/hmac.js +6 -10
  56. package/dist/crypto/hmac.js.map +1 -1
  57. package/dist/crypto/symmetric-encryption.d.ts +1 -0
  58. package/dist/crypto/symmetric-encryption.d.ts.map +1 -0
  59. package/dist/crypto/symmetric-encryption.js +13 -17
  60. package/dist/crypto/symmetric-encryption.js.map +1 -1
  61. package/dist/index.d.ts +14 -12
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +17 -27
  64. package/dist/index.js.map +1 -1
  65. package/dist/tsconfig.json +2 -1
  66. package/package.json +23 -24
  67. package/src/api-security/claims-identity.ts +1 -1
  68. package/src/api-security/json-web-token.ts +21 -21
  69. package/src/bin.ts +1 -1
  70. package/src/crypto/hash.ts +11 -9
  71. package/src/crypto/hmac.ts +7 -7
  72. package/src/crypto/symmetric-encryption.ts +11 -11
  73. package/src/index.ts +19 -18
  74. package/test/asymmetric-encryption.test.ts +37 -37
  75. package/test/digital-signature.test.ts +22 -22
  76. package/test/hash.test.ts +120 -105
  77. package/test/hmac.test.ts +56 -55
  78. package/test/json-web-token.test.ts +95 -95
  79. package/test/other.test.ts +8 -7
  80. package/test/symmetric-encryption.test.ts +49 -48
  81. package/tsconfig.json +8 -5
package/test/hash.test.ts CHANGED
@@ -1,49 +1,50 @@
1
- import * as Assert from "assert";
2
- import { Hash } from "./../src/index";
1
+ import { describe, test } from "node:test";
2
+ import assert from "node:assert";
3
+ import { Hash } from "./../src/index.js";
3
4
  import "@nivinjoseph/n-ext";
4
5
  // import { CryptoException } from "./../src/crypto-exception";
5
6
 
6
- suite("Hash", () =>
7
+ await describe("Hash", async () =>
7
8
  {
8
- suite("create", () =>
9
+ await describe("create", async () =>
9
10
  {
10
- test("must return a string value that is not null, empty, whitespace or same as input when called with a valid input", () =>
11
+ await test("must return a string value that is not null, empty, whitespace or same as input when called with a valid input", () =>
11
12
  {
12
13
  const input = "hello world";
13
14
  const hash = Hash.create(input);
14
15
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15
- Assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
16
- Assert.notStrictEqual(hash, input);
16
+ assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
17
+ assert.notStrictEqual(hash, input);
17
18
  });
18
-
19
- test("multiple invocations with the same input must return the same output", () =>
19
+
20
+ await test("multiple invocations with the same input must return the same output", () =>
20
21
  {
21
22
  const input = "hello world";
22
23
  const hash1 = Hash.create(input);
23
24
  const hash2 = Hash.create(input);
24
- Assert.strictEqual(hash1, hash2);
25
+ assert.strictEqual(hash1, hash2);
25
26
  });
26
-
27
- test("multiple invocations with the different inputs must return different outputs", () =>
27
+
28
+ await test("multiple invocations with the different inputs must return different outputs", () =>
28
29
  {
29
30
  const input1 = "hello world";
30
31
  const hash1 = Hash.create(input1);
31
32
  const input2 = "goodbye world";
32
33
  const hash2 = Hash.create(input2);
33
- Assert.notStrictEqual(hash1, hash2);
34
+ assert.notStrictEqual(hash1, hash2);
34
35
  });
35
-
36
-
37
- // test("successfully create a hash twice with different values", async () =>
36
+
37
+
38
+ // await test("successfully create a hash twice with different values", async () =>
38
39
  // {
39
40
  // let hash1 = await Hash.create("hello world");
40
41
  // let hash2 = await Hash.create("hello world2");
41
- // Assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
42
- // Assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
43
- // Assert.notStrictEqual(hash1, hash2);
42
+ // assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
43
+ // assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
44
+ // assert.notStrictEqual(hash1, hash2);
44
45
  // });
45
-
46
- // test("should throw CryptoException when value is null", async () =>
46
+
47
+ // await test("should throw CryptoException when value is null", async () =>
47
48
  // {
48
49
  // try
49
50
  // {
@@ -51,14 +52,14 @@ suite("Hash", () =>
51
52
  // }
52
53
  // catch (exception)
53
54
  // {
54
- // Assert.ok(exception instanceof CryptoException);
55
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
55
+ // assert.ok(exception instanceof CryptoException);
56
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
56
57
  // return;
57
58
  // }
58
- // Assert.ok(false);
59
+ // assert.ok(false);
59
60
  // });
60
-
61
- // test("should throw CryptoException when value is undefined", async () =>
61
+
62
+ // await test("should throw CryptoException when value is undefined", async () =>
62
63
  // {
63
64
  // try
64
65
  // {
@@ -66,14 +67,14 @@ suite("Hash", () =>
66
67
  // }
67
68
  // catch (exception)
68
69
  // {
69
- // Assert.ok(exception instanceof CryptoException);
70
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
70
+ // assert.ok(exception instanceof CryptoException);
71
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
71
72
  // return;
72
73
  // }
73
- // Assert.ok(false);
74
+ // assert.ok(false);
74
75
  // });
75
-
76
- // test("should throw CryptoException when value is empty string", async () =>
76
+
77
+ // await test("should throw CryptoException when value is empty string", async () =>
77
78
  // {
78
79
  // try
79
80
  // {
@@ -81,51 +82,51 @@ suite("Hash", () =>
81
82
  // }
82
83
  // catch (exception)
83
84
  // {
84
- // Assert.ok(exception instanceof CryptoException);
85
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
85
+ // assert.ok(exception instanceof CryptoException);
86
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
86
87
  // return;
87
88
  // }
88
- // Assert.ok(false);
89
+ // assert.ok(false);
89
90
  // });
90
-
91
+
91
92
  });
92
-
93
- suite("createUsingSalt", () =>
93
+
94
+ await describe("createUsingSalt", async () =>
94
95
  {
95
- test("must return a string value that is not null, empty, whitespace or same as input or salt when called with a valid input and salt", () =>
96
+ await test("must return a string value that is not null, empty, whitespace or same as input or salt when called with a valid input and salt", () =>
96
97
  {
97
98
  const input = "hello world";
98
99
  const salt = "salt";
99
100
  const hash = Hash.createUsingSalt(input, salt);
100
101
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
101
- Assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
102
- Assert.notStrictEqual(hash, input);
103
- Assert.notStrictEqual(hash, salt);
102
+ assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
103
+ assert.notStrictEqual(hash, input);
104
+ assert.notStrictEqual(hash, salt);
104
105
  });
105
106
 
106
- test("multiple invocations with the same input and salt must return the same output", () =>
107
+ await test("multiple invocations with the same input and salt must return the same output", () =>
107
108
  {
108
109
  const input = "hello world";
109
110
  const salt = "salt";
110
111
  const hash1 = Hash.createUsingSalt(input, salt);
111
112
  const hash2 = Hash.createUsingSalt(input, salt);
112
- Assert.strictEqual(hash1, hash2);
113
+ assert.strictEqual(hash1, hash2);
113
114
  });
114
115
 
115
- test("multiple invocations with different inputs and different salts must return different outputs", () =>
116
+ await test("multiple invocations with different inputs and different salts must return different outputs", () =>
116
117
  {
117
118
  const input1 = "hello world";
118
119
  const salt1 = "salt-1";
119
120
  const hash1 = Hash.createUsingSalt(input1, salt1);
120
-
121
+
121
122
  const input2 = "goodbye world";
122
123
  const salt2 = "salt-2";
123
124
  const hash2 = Hash.createUsingSalt(input2, salt2);
124
-
125
- Assert.notStrictEqual(hash1, hash2);
125
+
126
+ assert.notStrictEqual(hash1, hash2);
126
127
  });
127
-
128
- test("multiple invocations with different inputs and the same salt must return different outputs", () =>
128
+
129
+ await test("multiple invocations with different inputs and the same salt must return different outputs", () =>
129
130
  {
130
131
  const input1 = "hello world";
131
132
  const salt1 = "salt-1";
@@ -134,10 +135,10 @@ suite("Hash", () =>
134
135
  const input2 = "goodbye world";
135
136
  const hash2 = Hash.createUsingSalt(input2, salt1);
136
137
 
137
- Assert.notStrictEqual(hash1, hash2);
138
+ assert.notStrictEqual(hash1, hash2);
138
139
  });
139
-
140
- test("multiple invocations with the same input and different salts must return different outputs", () =>
140
+
141
+ await test("multiple invocations with the same input and different salts must return different outputs", () =>
141
142
  {
142
143
  const input = "hello world";
143
144
  const salt1 = "salt-1";
@@ -146,48 +147,62 @@ suite("Hash", () =>
146
147
  const salt2 = "salt-2";
147
148
  const hash2 = Hash.createUsingSalt(input, salt2);
148
149
 
149
- Assert.notStrictEqual(hash1, hash2);
150
+ assert.notStrictEqual(hash1, hash2);
150
151
  });
151
-
152
-
153
-
154
-
155
-
156
- // test("successfully create a hash", async () =>
152
+
153
+ await test("regex issue", () =>
154
+ {
155
+ let password = "YQAt3TPI7s1YXyClbQ2$&JdHOKZJ@z4!";
156
+ password = password.trim();
157
+
158
+ const createdAt = Date.now();
159
+ const username = "defaultUser";
160
+
161
+ const salt = (createdAt % 2) === 0
162
+ ? `${username.base64Decode()}${createdAt}`
163
+ : `${createdAt}${username.base64Decode()}`;
164
+
165
+ Hash.createUsingSalt(password, salt);
166
+ });
167
+
168
+
169
+
170
+
171
+ // await test("successfully create a hash", async () =>
157
172
  // {
158
173
  // let hash = await Hash.createUsingSalt("hello world", "some-salt");
159
- // Assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
160
- // Assert.notStrictEqual("hello world", hash);
174
+ // assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
175
+ // assert.notStrictEqual("hello world", hash);
161
176
  // });
162
177
 
163
- // test("successfully create a hash twice with same values and same salt", async () =>
178
+ // await test("successfully create a hash twice with same values and same salt", async () =>
164
179
  // {
165
180
  // let hash1 = await Hash.createUsingSalt("hello world", "some-salt");
166
181
  // let hash2 = await Hash.createUsingSalt("hello world", "some-salt");
167
- // Assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
168
- // Assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
169
- // Assert.strictEqual(hash1, hash2);
182
+ // assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
183
+ // assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
184
+ // assert.strictEqual(hash1, hash2);
170
185
  // });
171
-
172
- // test("successfully create a hash twice with same values and different salt", async () =>
186
+
187
+ // await test("successfully create a hash twice with same values and different salt", async () =>
173
188
  // {
174
189
  // let hash1 = await Hash.createUsingSalt("hello world", "some-salt");
175
190
  // let hash2 = await Hash.createUsingSalt("hello world", "some-other-salt");
176
- // Assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
177
- // Assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
178
- // Assert.notStrictEqual(hash1, hash2);
191
+ // assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
192
+ // assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
193
+ // assert.notStrictEqual(hash1, hash2);
179
194
  // });
180
-
181
- // test("successfully create a hash twice with different values same salt", async () =>
195
+
196
+ // await test("successfully create a hash twice with different values same salt", async () =>
182
197
  // {
183
198
  // let hash1 = await Hash.createUsingSalt("hello world", "some-salt");
184
199
  // let hash2 = await Hash.createUsingSalt("hello world2", "some-salt");
185
- // Assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
186
- // Assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
187
- // Assert.notStrictEqual(hash1, hash2);
200
+ // assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
201
+ // assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
202
+ // assert.notStrictEqual(hash1, hash2);
188
203
  // });
189
-
190
- // test("should throw CryptoException when value is null", async () =>
204
+
205
+ // await test("should throw CryptoException when value is null", async () =>
191
206
  // {
192
207
  // try
193
208
  // {
@@ -195,14 +210,14 @@ suite("Hash", () =>
195
210
  // }
196
211
  // catch (exception)
197
212
  // {
198
- // Assert.ok(exception instanceof CryptoException);
199
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
213
+ // assert.ok(exception instanceof CryptoException);
214
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
200
215
  // return;
201
216
  // }
202
- // Assert.ok(false);
217
+ // assert.ok(false);
203
218
  // });
204
-
205
- // test("should throw CryptoException when value is undefined", async () =>
219
+
220
+ // await test("should throw CryptoException when value is undefined", async () =>
206
221
  // {
207
222
  // try
208
223
  // {
@@ -210,14 +225,14 @@ suite("Hash", () =>
210
225
  // }
211
226
  // catch (exception)
212
227
  // {
213
- // Assert.ok(exception instanceof CryptoException);
214
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
228
+ // assert.ok(exception instanceof CryptoException);
229
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
215
230
  // return;
216
231
  // }
217
- // Assert.ok(false);
232
+ // assert.ok(false);
218
233
  // });
219
-
220
- // test("should throw CryptoException when salt is null", async () =>
234
+
235
+ // await test("should throw CryptoException when salt is null", async () =>
221
236
  // {
222
237
  // try
223
238
  // {
@@ -225,14 +240,14 @@ suite("Hash", () =>
225
240
  // }
226
241
  // catch (exception)
227
242
  // {
228
- // Assert.ok(exception instanceof CryptoException);
229
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
243
+ // assert.ok(exception instanceof CryptoException);
244
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
230
245
  // return;
231
246
  // }
232
- // Assert.ok(false);
247
+ // assert.ok(false);
233
248
  // });
234
-
235
- // test("should throw CryptoException when salt is undefined", async () =>
249
+
250
+ // await test("should throw CryptoException when salt is undefined", async () =>
236
251
  // {
237
252
  // try
238
253
  // {
@@ -240,14 +255,14 @@ suite("Hash", () =>
240
255
  // }
241
256
  // catch (exception)
242
257
  // {
243
- // Assert.ok(exception instanceof CryptoException);
244
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
258
+ // assert.ok(exception instanceof CryptoException);
259
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
245
260
  // return;
246
261
  // }
247
- // Assert.ok(false);
262
+ // assert.ok(false);
248
263
  // });
249
-
250
- // test("should throw CryptoException when salt is empty string", async () =>
264
+
265
+ // await test("should throw CryptoException when salt is empty string", async () =>
251
266
  // {
252
267
  // try
253
268
  // {
@@ -255,14 +270,14 @@ suite("Hash", () =>
255
270
  // }
256
271
  // catch (exception)
257
272
  // {
258
- // Assert.ok(exception instanceof CryptoException);
259
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
273
+ // assert.ok(exception instanceof CryptoException);
274
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
260
275
  // return;
261
276
  // }
262
- // Assert.ok(false);
277
+ // assert.ok(false);
263
278
  // });
264
-
265
- // test("should throw CryptoException when value is empty string", async () =>
279
+
280
+ // await test("should throw CryptoException when value is empty string", async () =>
266
281
  // {
267
282
  // try
268
283
  // {
@@ -270,11 +285,11 @@ suite("Hash", () =>
270
285
  // }
271
286
  // catch (exception)
272
287
  // {
273
- // Assert.ok(exception instanceof CryptoException);
274
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
288
+ // assert.ok(exception instanceof CryptoException);
289
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
275
290
  // return;
276
291
  // }
277
- // Assert.ok(false);
292
+ // assert.ok(false);
278
293
  // });
279
294
  });
280
295
  });
package/test/hmac.test.ts CHANGED
@@ -1,79 +1,80 @@
1
- import * as Assert from "assert";
2
- import { Hmac, SymmetricEncryption } from "./../src/index";
1
+ import { describe, test } from "node:test";
2
+ import assert from "node:assert";
3
+ import { Hmac, SymmetricEncryption } from "./../src/index.js";
3
4
  // import { CryptoException } from "./../src/crypto-exception";
4
5
  import "@nivinjoseph/n-ext";
5
6
 
6
- suite("Hmac", () =>
7
+ await describe("Hmac", async () =>
7
8
  {
8
- suite("create", () =>
9
+ await describe("create", async () =>
9
10
  {
10
- test("should return string value that is not null, empty, whitespace or same as the key or input", async () =>
11
+ await test("should return string value that is not null, empty, whitespace or same as the key or input", async () =>
11
12
  {
12
13
  const key = await SymmetricEncryption.generateKey();
13
14
  const value = "hello world";
14
15
  const hmac = Hmac.create(key, value);
15
16
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
16
- Assert.ok(hmac !== null && !hmac.isEmptyOrWhiteSpace());
17
- Assert.notStrictEqual(hmac, key);
18
- Assert.notStrictEqual(hmac, value);
17
+ assert.ok(hmac !== null && !hmac.isEmptyOrWhiteSpace());
18
+ assert.notStrictEqual(hmac, key);
19
+ assert.notStrictEqual(hmac, value);
19
20
  });
20
-
21
- test("multiple invocations with the same key and value must return the same output", async () =>
21
+
22
+ await test("multiple invocations with the same key and value must return the same output", async () =>
22
23
  {
23
24
  const key = await SymmetricEncryption.generateKey();
24
25
  const value = "hello world";
25
26
  const hmac1 = Hmac.create(key, value);
26
27
  const hmac2 = Hmac.create(key, value);
27
- Assert.strictEqual(hmac1, hmac2);
28
+ assert.strictEqual(hmac1, hmac2);
28
29
  });
29
-
30
- test("multiple invocations with different keys and different values must return different outputs", async () =>
30
+
31
+ await test("multiple invocations with different keys and different values must return different outputs", async () =>
31
32
  {
32
33
  const key1 = await SymmetricEncryption.generateKey();
33
34
  const value1 = "hello world";
34
35
  const hmac1 = Hmac.create(key1, value1);
35
-
36
+
36
37
  const key2 = await SymmetricEncryption.generateKey();
37
38
  const value2 = "goodbye world";
38
39
  const hmac2 = Hmac.create(key2, value2);
39
- Assert.notStrictEqual(hmac1, hmac2);
40
+ assert.notStrictEqual(hmac1, hmac2);
40
41
  });
41
-
42
- test("multiple invocations with the same key and different values must return different outputs", async () =>
42
+
43
+ await test("multiple invocations with the same key and different values must return different outputs", async () =>
43
44
  {
44
45
  const key = await SymmetricEncryption.generateKey();
45
46
  const value1 = "hello world";
46
47
  const value2 = "goodbye world";
47
48
  const hmac1 = Hmac.create(key, value1);
48
49
  const hmac2 = Hmac.create(key, value2);
49
- Assert.notStrictEqual(hmac1, hmac2);
50
+ assert.notStrictEqual(hmac1, hmac2);
50
51
  });
51
-
52
- test("multiple invocations with different keys and the same value must return different outputs", async () =>
52
+
53
+ await test("multiple invocations with different keys and the same value must return different outputs", async () =>
53
54
  {
54
55
  const key1 = await SymmetricEncryption.generateKey();
55
56
  const key2 = await SymmetricEncryption.generateKey();
56
57
  const value = "hello world";
57
58
  const hmac1 = Hmac.create(key1, value);
58
59
  const hmac2 = Hmac.create(key2, value);
59
- Assert.notStrictEqual(hmac1, hmac2);
60
+ assert.notStrictEqual(hmac1, hmac2);
60
61
  });
61
-
62
-
63
-
64
- // test("should create same Hmacs for a given value and key", async () =>
62
+
63
+
64
+
65
+ // await test("should create same Hmacs for a given value and key", async () =>
65
66
  // {
66
67
  // let key = await SymmetricEncryption.generateKey();
67
68
  // let hmac1 = await Hmac.create(key, "some-string");
68
69
  // let hmac2 = await Hmac.create(key, "some-string");
69
- // Assert.ok(hmac1 !== null && !hmac1.isEmptyOrWhiteSpace());
70
- // Assert.ok(hmac2 !== null && !hmac2.isEmptyOrWhiteSpace());
71
- // Assert.notStrictEqual(hmac1, "some-string");
72
- // Assert.notStrictEqual(hmac2, "some-string");
73
- // Assert.strictEqual(hmac1, hmac2);
70
+ // assert.ok(hmac1 !== null && !hmac1.isEmptyOrWhiteSpace());
71
+ // assert.ok(hmac2 !== null && !hmac2.isEmptyOrWhiteSpace());
72
+ // assert.notStrictEqual(hmac1, "some-string");
73
+ // assert.notStrictEqual(hmac2, "some-string");
74
+ // assert.strictEqual(hmac1, hmac2);
74
75
  // });
75
-
76
- // test("should throw CryptoException when key is null", async () =>
76
+
77
+ // await test("should throw CryptoException when key is null", async () =>
77
78
  // {
78
79
  // try
79
80
  // {
@@ -81,14 +82,14 @@ suite("Hmac", () =>
81
82
  // }
82
83
  // catch (exception)
83
84
  // {
84
- // Assert.ok(exception instanceof CryptoException);
85
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
85
+ // assert.ok(exception instanceof CryptoException);
86
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
86
87
  // return;
87
88
  // }
88
- // Assert.ok(false);
89
+ // assert.ok(false);
89
90
  // });
90
-
91
- // test("should throw CryptoException when value is null", async () =>
91
+
92
+ // await test("should throw CryptoException when value is null", async () =>
92
93
  // {
93
94
  // try
94
95
  // {
@@ -97,14 +98,14 @@ suite("Hmac", () =>
97
98
  // }
98
99
  // catch (exception)
99
100
  // {
100
- // Assert.ok(exception instanceof CryptoException);
101
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
101
+ // assert.ok(exception instanceof CryptoException);
102
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
102
103
  // return;
103
104
  // }
104
- // Assert.ok(false);
105
+ // assert.ok(false);
105
106
  // });
106
-
107
- // test("should throw CryptoException when key is undefined", async () =>
107
+
108
+ // await test("should throw CryptoException when key is undefined", async () =>
108
109
  // {
109
110
  // try
110
111
  // {
@@ -112,14 +113,14 @@ suite("Hmac", () =>
112
113
  // }
113
114
  // catch (exception)
114
115
  // {
115
- // Assert.ok(exception instanceof CryptoException);
116
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
116
+ // assert.ok(exception instanceof CryptoException);
117
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
117
118
  // return;
118
119
  // }
119
- // Assert.ok(false);
120
+ // assert.ok(false);
120
121
  // });
121
122
 
122
- // test("should throw CryptoException when value is undefined", async () =>
123
+ // await test("should throw CryptoException when value is undefined", async () =>
123
124
  // {
124
125
  // try
125
126
  // {
@@ -128,14 +129,14 @@ suite("Hmac", () =>
128
129
  // }
129
130
  // catch (exception)
130
131
  // {
131
- // Assert.ok(exception instanceof CryptoException);
132
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
132
+ // assert.ok(exception instanceof CryptoException);
133
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
133
134
  // return;
134
135
  // }
135
- // Assert.ok(false);
136
+ // assert.ok(false);
136
137
  // });
137
-
138
- // test("should throw CryptoException when invalid key", async () =>
138
+
139
+ // await test("should throw CryptoException when invalid key", async () =>
139
140
  // {
140
141
  // try
141
142
  // {
@@ -143,12 +144,12 @@ suite("Hmac", () =>
143
144
  // }
144
145
  // catch (exception)
145
146
  // {
146
- // Assert.ok(exception instanceof CryptoException);
147
- // Assert.strictEqual(exception.message, "Parameter count mismatch.");
147
+ // assert.ok(exception instanceof CryptoException);
148
+ // assert.strictEqual(exception.message, "Parameter count mismatch.");
148
149
  // return;
149
150
  // }
150
- // Assert.ok(false);
151
+ // assert.ok(false);
151
152
  // });
152
153
  });
153
-
154
+
154
155
  });