|
| 1 | +var enforceRangeTestCases = [ |
| 2 | + // These cases should throw an error in all algorithms due to [EnforceRange] |
| 3 | + {length: NaN, expected: "TypeError"}, |
| 4 | + {length: Infinity, expected: "TypeError"}, |
| 5 | + {length: -8, expected: "TypeError"}, |
| 6 | + {length: 2**32 + 8, expected: "TypeError"}, |
| 7 | +]; |
1 | 8 | var testCases = { |
2 | 9 | "HKDF": [ |
3 | 10 | {length: 256, expected: algorithms["HKDF"].derivation}, |
4 | 11 | {length: 384, expected: algorithms["HKDF"].derivation384}, |
5 | | - {length: 230, expected: undefined}, // should throw an exception, not multiple of 8 |
| 12 | + {length: 230, expected: "OperationError"}, // should throw an exception, not multiple of 8 |
6 | 13 | {length: 0, expected: emptyArray}, |
7 | | - {length: null, expected: undefined }, // should throw an exception |
8 | | - {length: undefined, expected: undefined }, // should throw an exception |
9 | | - {length: "omitted", expected: undefined }, // default value is null, so should throw |
| 14 | + {length: null, expected: "OperationError"}, // should throw an exception |
| 15 | + {length: undefined, expected: "OperationError"}, // should throw an exception |
| 16 | + {length: "omitted", expected: "OperationError"}, // default value is null, so should throw |
| 17 | + ...enforceRangeTestCases, |
10 | 18 | ], |
11 | 19 | "PBKDF2": [ |
12 | 20 | {length: 256, expected: algorithms["PBKDF2"].derivation}, |
13 | 21 | {length: 384, expected: algorithms["PBKDF2"].derivation384}, |
14 | | - {length: 230, expected: undefined}, // should throw an exception, not multiple of 8 |
| 22 | + {length: 230, expected: "OperationError"}, // should throw an exception, not multiple of 8 |
15 | 23 | {length: 0, expected: emptyArray}, |
16 | | - {length: null, expected: undefined }, // should throw an exception |
17 | | - {length: undefined, expected: undefined }, // should throw an exception |
18 | | - {length: "omitted", expected: undefined }, // default value is null, so should throw |
| 24 | + {length: null, expected: "OperationError"}, // should throw an exception |
| 25 | + {length: undefined, expected: "OperationError"}, // should throw an exception |
| 26 | + {length: "omitted", expected: "OperationError"}, // default value is null, so should throw |
| 27 | + ...enforceRangeTestCases, |
19 | 28 | ], |
20 | 29 | "ECDH": [ |
21 | 30 | {length: 256, expected: algorithms["ECDH"].derivation}, |
22 | | - {length: 384, expected: undefined}, // should throw an exception, bigger than the output size |
| 31 | + {length: 384, expected: "OperationError"}, // should throw an exception, bigger than the output size |
23 | 32 | {length: 230, expected: algorithms["ECDH"].derivation230}, |
24 | 33 | {length: 0, expected: emptyArray}, |
25 | 34 | {length: null, expected: algorithms["ECDH"].derivation}, |
26 | 35 | {length: undefined, expected: algorithms["ECDH"].derivation}, |
27 | | - {length: "omitted", expected: algorithms["ECDH"].derivation }, // default value is null |
| 36 | + {length: "omitted", expected: algorithms["ECDH"].derivation}, // default value is null |
| 37 | + ...enforceRangeTestCases, |
28 | 38 | ], |
29 | 39 | "X25519": [ |
30 | 40 | {length: 256, expected: algorithms["X25519"].derivation}, |
31 | | - {length: 384, expected: undefined}, // should throw an exception, bigger than the output size |
| 41 | + {length: 384, expected: "OperationError"}, // should throw an exception, bigger than the output size |
32 | 42 | {length: 230, expected: algorithms["X25519"].derivation230}, |
33 | 43 | {length: 0, expected: emptyArray}, |
34 | 44 | {length: null, expected: algorithms["X25519"].derivation}, |
35 | 45 | {length: undefined, expected: algorithms["X25519"].derivation}, |
36 | | - {length: "omitted", expected: algorithms["X25519"].derivation }, // default value is null |
| 46 | + {length: "omitted", expected: algorithms["X25519"].derivation}, // default value is null |
| 47 | + ...enforceRangeTestCases, |
37 | 48 | ], |
38 | 49 | } |
0 commit comments