-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Expand file tree
/
Copy pathsupports-modern.tentative.https.any.js
More file actions
160 lines (144 loc) Β· 4.72 KB
/
Copy pathsupports-modern.tentative.https.any.js
File metadata and controls
160 lines (144 loc) Β· 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// META: title=WebCrypto API: supports method tests for algorithms in https://wicg.github.io/webcrypto-modern-algos/
// META: script=util/helpers.js
'use strict';
const modernAlgorithms = {
// Asymmetric algorithms
'ML-DSA-44': {
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
},
'ML-DSA-65': {
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
},
'ML-DSA-87': {
operations: ['generateKey', 'importKey', 'sign', 'verify', 'getPublicKey'],
},
'ML-KEM-512': {
operations: [
'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits',
'decapsulateKey', 'decapsulateBits', 'getPublicKey'
],
},
'ML-KEM-768': {
operations: [
'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits',
'decapsulateKey', 'decapsulateBits', 'getPublicKey'
],
},
'ML-KEM-1024': {
operations: [
'generateKey', 'importKey', 'encapsulateKey', 'encapsulateBits',
'decapsulateKey', 'decapsulateBits', 'getPublicKey'
],
},
// Symmetric algorithms
'ChaCha20-Poly1305': {
operations: ['generateKey', 'importKey', 'encrypt', 'decrypt'],
encryptParams: {name: 'ChaCha20-Poly1305', iv: new Uint8Array(12)},
},
};
const operations = [
'generateKey',
'importKey',
'sign',
'verify',
'encrypt',
'decrypt',
'deriveBits',
'digest',
'encapsulateKey',
'encapsulateBits',
'decapsulateKey',
'decapsulateBits',
'getPublicKey',
];
// Test that supports method exists and is a static method
test(() => {
assert_true(
typeof SubtleCrypto.supports === 'function',
'SubtleCrypto.supports should be a function');
}, 'SubtleCrypto.supports method exists');
// Test standard WebCrypto algorithms for requested operations
for (const [algorithmName, algorithmInfo] of Object.entries(modernAlgorithms)) {
for (const operation of operations) {
promise_test(async (t) => {
const isSupported = algorithmInfo.operations.includes(operation);
// Use appropriate algorithm parameters for each operation
let algorithm;
let lengthOrAdditionalAlgorithm;
switch (operation) {
case 'generateKey':
algorithm = algorithmInfo.keyGenParams || algorithmName;
break;
case 'importKey':
algorithm = algorithmInfo.importParams || algorithmName;
break;
case 'sign':
case 'verify':
algorithm = algorithmInfo.signParams || algorithmName;
break;
case 'encrypt':
case 'decrypt':
algorithm = algorithmInfo.encryptParams || algorithmName;
break;
case 'deriveBits':
algorithm = algorithmInfo.deriveBitsParams || algorithmName;
if (algorithm?.public instanceof Promise) {
algorithm.public = (await algorithm.public).publicKey;
}
if (algorithmName === 'PBKDF2' || algorithmName === 'HKDF') {
lengthOrAdditionalAlgorithm = 256;
}
break;
case 'digest':
algorithm = algorithmName;
break;
case 'encapsulateKey':
case 'encapsulateBits':
case 'decapsulateKey':
case 'decapsulateBits':
algorithm = algorithmName;
if (operation === 'encapsulateKey' || operation === 'decapsulateKey') {
lengthOrAdditionalAlgorithm = { name: 'AES-GCM', length: 256 };
}
break;
default:
algorithm = algorithmName;
}
const result = SubtleCrypto.supports(operation, algorithm, lengthOrAdditionalAlgorithm);
if (isSupported) {
assert_true(result, `${algorithmName} should support ${operation}`);
} else {
assert_false(
result, `${algorithmName} should not support ${operation}`);
}
}, `supports(${operation}, ${algorithmName})`);
}
}
// Test some algorithm objects with valid parameters
test(() => {
assert_true(
SubtleCrypto.supports('encrypt', {
name: 'ChaCha20-Poly1305',
iv: new Uint8Array(12),
tagLength: 128,
}),
'ChaCha20-Poly1305 encrypt with valid tagLength');
}, 'supports returns true for algorithm objects with valid parameters');
// Test some algorithm objects with invalid parameters
test(() => {
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'ChaCha20-Poly1305',
iv: new Uint8Array(12),
tagLength: 100,
}),
'ChaCha20-Poly1305 encrypt with invalid tagLength');
assert_false(
SubtleCrypto.supports('encrypt', {
name: 'ChaCha20-Poly1305',
iv: new Uint8Array(10),
tagLength: 128,
}),
'ChaCha20-Poly1305 encrypt with invalid iv');
}, 'supports returns false for algorithm objects with invalid parameters');
done();