-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathsupports.ts
More file actions
236 lines (189 loc) · 7.05 KB
/
supports.ts
File metadata and controls
236 lines (189 loc) · 7.05 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import { expect } from 'chai';
import { Subtle } from 'react-native-quick-crypto';
import { test } from '../util';
const SUITE = 'subtle.supports';
// --- Encrypt ---
test(SUITE, 'encrypt: AES-GCM is supported', () => {
expect(Subtle.supports('encrypt', 'AES-GCM')).to.equal(true);
});
test(SUITE, 'encrypt: RSA-OAEP is supported', () => {
expect(Subtle.supports('encrypt', 'RSA-OAEP')).to.equal(true);
});
test(SUITE, 'encrypt: ChaCha20-Poly1305 is supported', () => {
expect(Subtle.supports('encrypt', 'ChaCha20-Poly1305')).to.equal(true);
});
test(SUITE, 'encrypt: HMAC is not supported', () => {
expect(Subtle.supports('encrypt', 'HMAC')).to.equal(false);
});
test(SUITE, 'encrypt: Ed25519 is not supported', () => {
expect(Subtle.supports('encrypt', 'Ed25519')).to.equal(false);
});
// --- Sign ---
test(SUITE, 'sign: Ed25519 is supported', () => {
expect(Subtle.supports('sign', 'Ed25519')).to.equal(true);
});
test(SUITE, 'sign: ECDSA is supported', () => {
expect(Subtle.supports('sign', 'ECDSA')).to.equal(true);
});
test(SUITE, 'sign: HMAC is supported', () => {
expect(Subtle.supports('sign', 'HMAC')).to.equal(true);
});
test(SUITE, 'sign: ML-DSA-65 is supported', () => {
expect(Subtle.supports('sign', 'ML-DSA-65')).to.equal(true);
});
test(SUITE, 'sign: AES-GCM is not supported', () => {
expect(Subtle.supports('sign', 'AES-GCM')).to.equal(false);
});
// --- Digest ---
test(SUITE, 'digest: SHA-256 is supported', () => {
expect(Subtle.supports('digest', 'SHA-256')).to.equal(true);
});
test(SUITE, 'digest: SHA-512 is supported', () => {
expect(Subtle.supports('digest', 'SHA-512')).to.equal(true);
});
// --- GenerateKey ---
test(SUITE, 'generateKey: Ed25519 is supported', () => {
expect(Subtle.supports('generateKey', 'Ed25519')).to.equal(true);
});
test(SUITE, 'generateKey: X25519 is supported', () => {
expect(Subtle.supports('generateKey', 'X25519')).to.equal(true);
});
test(SUITE, 'generateKey: HKDF is not supported', () => {
expect(Subtle.supports('generateKey', 'HKDF')).to.equal(false);
});
// --- DeriveBits ---
// HKDF/PBKDF2/Argon2 require an explicit length per Node webcrypto.js:1689-1714.
test(SUITE, 'deriveBits: HKDF with length is supported', () => {
expect(Subtle.supports('deriveBits', 'HKDF', 256)).to.equal(true);
});
test(SUITE, 'deriveBits: PBKDF2 with length is supported', () => {
expect(Subtle.supports('deriveBits', 'PBKDF2', 256)).to.equal(true);
});
test(SUITE, 'deriveBits: HKDF without length is not supported', () => {
expect(Subtle.supports('deriveBits', 'HKDF')).to.equal(false);
});
test(SUITE, 'deriveBits: X25519 is supported', () => {
expect(Subtle.supports('deriveBits', 'X25519')).to.equal(true);
});
test(SUITE, 'deriveBits: AES-GCM is not supported', () => {
expect(Subtle.supports('deriveBits', 'AES-GCM')).to.equal(false);
});
// --- DeriveKey ---
test(SUITE, 'deriveKey: HKDF + AES-GCM with length 256 is supported', () => {
expect(
Subtle.supports('deriveKey', 'HKDF', { name: 'AES-GCM', length: 256 }),
).to.equal(true);
});
// AES key length is required for getKeyLength — Node webcrypto.js:269-279.
test(SUITE, 'deriveKey: HKDF + AES-GCM without length is not supported', () => {
expect(Subtle.supports('deriveKey', 'HKDF', 'AES-GCM')).to.equal(false);
});
test(
SUITE,
'deriveKey: HKDF without additional algorithm returns false',
() => {
expect(Subtle.supports('deriveKey', 'HKDF')).to.equal(false);
},
);
// --- GetPublicKey ---
test(SUITE, 'getPublicKey: Ed25519 is supported', () => {
expect(Subtle.supports('getPublicKey', 'Ed25519')).to.equal(true);
});
test(SUITE, 'getPublicKey: RSA-PSS is supported', () => {
expect(Subtle.supports('getPublicKey', 'RSA-PSS')).to.equal(true);
});
test(SUITE, 'getPublicKey: X25519 is supported', () => {
expect(Subtle.supports('getPublicKey', 'X25519')).to.equal(true);
});
test(SUITE, 'getPublicKey: HMAC is not supported', () => {
expect(Subtle.supports('getPublicKey', 'HMAC')).to.equal(false);
});
test(SUITE, 'getPublicKey: AES-GCM is not supported', () => {
expect(Subtle.supports('getPublicKey', 'AES-GCM')).to.equal(false);
});
// --- WrapKey ---
test(SUITE, 'wrapKey: AES-KW is supported', () => {
expect(Subtle.supports('wrapKey', 'AES-KW')).to.equal(true);
});
test(SUITE, 'wrapKey: Ed25519 is not supported', () => {
expect(Subtle.supports('wrapKey', 'Ed25519')).to.equal(false);
});
test(SUITE, 'wrapKey: AES-KW with AES-GCM exportKey decomposition', () => {
expect(Subtle.supports('wrapKey', 'AES-KW', 'AES-GCM')).to.equal(true);
});
test(SUITE, 'wrapKey: AES-KW with FAKE exportKey decomposition', () => {
expect(Subtle.supports('wrapKey', 'AES-KW', 'FAKE' as never)).to.equal(false);
});
// --- UnwrapKey ---
test(SUITE, 'unwrapKey: AES-KW is supported', () => {
expect(Subtle.supports('unwrapKey', 'AES-KW')).to.equal(true);
});
test(SUITE, 'unwrapKey: AES-KW with AES-GCM importKey decomposition', () => {
expect(Subtle.supports('unwrapKey', 'AES-KW', 'AES-GCM')).to.equal(true);
});
test(SUITE, 'unwrapKey: AES-KW with FAKE importKey decomposition', () => {
expect(Subtle.supports('unwrapKey', 'AES-KW', 'FAKE' as never)).to.equal(
false,
);
});
// --- EncapsulateKey ---
test(SUITE, 'encapsulateKey: ML-KEM-768 + AES-GCM is supported', () => {
expect(Subtle.supports('encapsulateKey', 'ML-KEM-768', 'AES-GCM')).to.equal(
true,
);
});
test(SUITE, 'encapsulateKey: ML-KEM-768 + Ed25519 is not supported', () => {
expect(Subtle.supports('encapsulateKey', 'ML-KEM-768', 'Ed25519')).to.equal(
false,
);
});
test(
SUITE,
'encapsulateKey: ML-KEM-768 + HMAC default length supported',
() => {
expect(Subtle.supports('encapsulateKey', 'ML-KEM-768', 'HMAC')).to.equal(
true,
);
},
);
test(SUITE, 'encapsulateKey: ML-KEM-768 + HMAC length 256 supported', () => {
expect(
Subtle.supports('encapsulateKey', 'ML-KEM-768', {
name: 'HMAC',
length: 256,
}),
).to.equal(true);
});
test(
SUITE,
'encapsulateKey: ML-KEM-768 + HMAC non-default length not supported',
() => {
expect(
Subtle.supports('encapsulateKey', 'ML-KEM-768', {
name: 'HMAC',
length: 512,
}),
).to.equal(false);
},
);
// --- DeriveBits per-algorithm length validators ---
test(SUITE, 'deriveBits: HKDF with non-multiple-of-8 length rejected', () => {
expect(Subtle.supports('deriveBits', 'HKDF', 257)).to.equal(false);
});
test(SUITE, 'deriveBits: PBKDF2 with non-multiple-of-8 length rejected', () => {
expect(Subtle.supports('deriveBits', 'PBKDF2', 257)).to.equal(false);
});
test(SUITE, 'deriveBits: Argon2id length below 32 rejected', () => {
expect(Subtle.supports('deriveBits', 'Argon2id', 16)).to.equal(false);
});
test(SUITE, 'deriveBits: Argon2id length 32 supported', () => {
expect(Subtle.supports('deriveBits', 'Argon2id', 32)).to.equal(true);
});
// --- Invalid operation ---
test(SUITE, 'invalid operation returns false', () => {
expect(Subtle.supports('nonexistent', 'AES-GCM')).to.equal(false);
});
// --- Invalid algorithm ---
test(SUITE, 'invalid algorithm returns false', () => {
expect(Subtle.supports('encrypt', 'FAKE-ALGO' as never)).to.equal(false);
});