Skip to content

Commit b85c8ce

Browse files
panvatargos
authored andcommittedOct 2, 2024
lib: refactor SubtleCrypto experimental warnings
PR-URL: #54620 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 7c83c15 commit b85c8ce

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed
 

Diff for: ‎lib/internal/crypto/cfrg.js

-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const {
2727
} = require('internal/crypto/util');
2828

2929
const {
30-
emitExperimentalWarning,
3130
lazyDOMException,
3231
promisify,
3332
} = require('internal/util');
@@ -105,7 +104,6 @@ function createCFRGRawKey(name, keyData, isPublic) {
105104

106105
async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
107106
const { name } = algorithm;
108-
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
109107

110108
const usageSet = new SafeSet(keyUsages);
111109
switch (name) {
@@ -187,7 +185,6 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
187185
}
188186

189187
function cfrgExportKey(key, format) {
190-
emitExperimentalWarning(`The ${key.algorithm.name} Web Crypto API algorithm`);
191188
return jobPromise(() => new ECKeyExportJob(
192189
kCryptoJobAsync,
193190
format,
@@ -202,7 +199,6 @@ async function cfrgImportKey(
202199
keyUsages) {
203200

204201
const { name } = algorithm;
205-
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
206202
let keyObject;
207203
const usagesSet = new SafeSet(keyUsages);
208204
switch (format) {
@@ -319,7 +315,6 @@ async function cfrgImportKey(
319315
}
320316

321317
function eddsaSignVerify(key, data, { name, context }, signature) {
322-
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
323318
const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
324319
const type = mode === kSignJobModeSign ? 'private' : 'public';
325320

Diff for: ‎lib/internal/crypto/util.js

+44-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const {
1111
DataViewPrototypeGetByteOffset,
1212
FunctionPrototypeBind,
1313
Number,
14+
ObjectDefineProperty,
15+
ObjectEntries,
1416
ObjectKeys,
1517
ObjectPrototypeHasOwnProperty,
1618
Promise,
@@ -63,6 +65,7 @@ const { Buffer } = require('buffer');
6365

6466
const {
6567
cachedResult,
68+
emitExperimentalWarning,
6669
filterDuplicateStrings,
6770
lazyDOMException,
6871
} = require('internal/util');
@@ -195,26 +198,18 @@ const kSupportedAlgorithms = {
195198
'AES-GCM': 'AesKeyGenParams',
196199
'AES-KW': 'AesKeyGenParams',
197200
'HMAC': 'HmacKeyGenParams',
198-
'X25519': null,
199-
'Ed25519': null,
200-
'X448': null,
201-
'Ed448': null,
202201
},
203202
'sign': {
204203
'RSASSA-PKCS1-v1_5': null,
205204
'RSA-PSS': 'RsaPssParams',
206205
'ECDSA': 'EcdsaParams',
207206
'HMAC': null,
208-
'Ed25519': null,
209-
'Ed448': 'Ed448Params',
210207
},
211208
'verify': {
212209
'RSASSA-PKCS1-v1_5': null,
213210
'RSA-PSS': 'RsaPssParams',
214211
'ECDSA': 'EcdsaParams',
215212
'HMAC': null,
216-
'Ed25519': null,
217-
'Ed448': 'Ed448Params',
218213
},
219214
'importKey': {
220215
'RSASSA-PKCS1-v1_5': 'RsaHashedImportParams',
@@ -229,17 +224,11 @@ const kSupportedAlgorithms = {
229224
'AES-CBC': null,
230225
'AES-GCM': null,
231226
'AES-KW': null,
232-
'Ed25519': null,
233-
'X25519': null,
234-
'Ed448': null,
235-
'X448': null,
236227
},
237228
'deriveBits': {
238229
'HKDF': 'HkdfParams',
239230
'PBKDF2': 'Pbkdf2Params',
240231
'ECDH': 'EcdhKeyDeriveParams',
241-
'X25519': 'EcdhKeyDeriveParams',
242-
'X448': 'EcdhKeyDeriveParams',
243232
},
244233
'encrypt': {
245234
'RSA-OAEP': 'RsaOaepParams',
@@ -270,6 +259,47 @@ const kSupportedAlgorithms = {
270259
},
271260
};
272261

262+
const experimentalAlgorithms = ObjectEntries({
263+
'X25519': {
264+
generateKey: null,
265+
importKey: null,
266+
deriveBits: 'EcdhKeyDeriveParams',
267+
},
268+
'Ed25519': {
269+
generateKey: null,
270+
sign: null,
271+
verify: null,
272+
importKey: null,
273+
},
274+
'X448': {
275+
generateKey: null,
276+
importKey: null,
277+
deriveBits: 'EcdhKeyDeriveParams',
278+
},
279+
'Ed448': {
280+
generateKey: null,
281+
sign: 'Ed448Params',
282+
verify: 'Ed448Params',
283+
importKey: null,
284+
},
285+
});
286+
287+
for (let i = 0; i < experimentalAlgorithms.length; i++) {
288+
const name = experimentalAlgorithms[i][0];
289+
const ops = ObjectEntries(experimentalAlgorithms[i][1]);
290+
for (let j = 0; j < ops.length; j++) {
291+
const { 0: op, 1: dict } = ops[j];
292+
ObjectDefineProperty(kSupportedAlgorithms[op], name, {
293+
get() {
294+
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
295+
return dict;
296+
},
297+
__proto__: null,
298+
enumerable: true,
299+
});
300+
}
301+
}
302+
273303
const simpleAlgorithmDictionaries = {
274304
AesGcmParams: { iv: 'BufferSource', additionalData: 'BufferSource' },
275305
RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier' },

0 commit comments

Comments
 (0)