Skip to content

Commit 0faf147

Browse files
committed
lib: refactor SubtleCrypto experimental warnings
1 parent 4a0ec20 commit 0faf147

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

lib/internal/crypto/cfrg.js

Lines changed: 0 additions & 5 deletions
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

lib/internal/crypto/util.js

Lines changed: 41 additions & 24 deletions
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');
@@ -168,15 +171,6 @@ const kNamedCurveAliases = {
168171

169172
const kAesKeyLengths = [128, 192, 256];
170173

171-
// These are the only hash algorithms we currently support via
172-
// the Web Crypto API.
173-
const kHashTypes = [
174-
'SHA-1',
175-
'SHA-256',
176-
'SHA-384',
177-
'SHA-512',
178-
];
179-
180174
const kSupportedAlgorithms = {
181175
'digest': {
182176
'SHA-1': null,
@@ -195,26 +189,18 @@ const kSupportedAlgorithms = {
195189
'AES-GCM': 'AesKeyGenParams',
196190
'AES-KW': 'AesKeyGenParams',
197191
'HMAC': 'HmacKeyGenParams',
198-
'X25519': null,
199-
'Ed25519': null,
200-
'X448': null,
201-
'Ed448': null,
202192
},
203193
'sign': {
204194
'RSASSA-PKCS1-v1_5': null,
205195
'RSA-PSS': 'RsaPssParams',
206196
'ECDSA': 'EcdsaParams',
207197
'HMAC': null,
208-
'Ed25519': null,
209-
'Ed448': 'Ed448Params',
210198
},
211199
'verify': {
212200
'RSASSA-PKCS1-v1_5': null,
213201
'RSA-PSS': 'RsaPssParams',
214202
'ECDSA': 'EcdsaParams',
215203
'HMAC': null,
216-
'Ed25519': null,
217-
'Ed448': 'Ed448Params',
218204
},
219205
'importKey': {
220206
'RSASSA-PKCS1-v1_5': 'RsaHashedImportParams',
@@ -229,17 +215,11 @@ const kSupportedAlgorithms = {
229215
'AES-CBC': null,
230216
'AES-GCM': null,
231217
'AES-KW': null,
232-
'Ed25519': null,
233-
'X25519': null,
234-
'Ed448': null,
235-
'X448': null,
236218
},
237219
'deriveBits': {
238220
'HKDF': 'HkdfParams',
239221
'PBKDF2': 'Pbkdf2Params',
240222
'ECDH': 'EcdhKeyDeriveParams',
241-
'X25519': 'EcdhKeyDeriveParams',
242-
'X448': 'EcdhKeyDeriveParams',
243223
},
244224
'encrypt': {
245225
'RSA-OAEP': 'RsaOaepParams',
@@ -270,6 +250,44 @@ const kSupportedAlgorithms = {
270250
},
271251
};
272252

253+
const experimentalAlgorithms = {
254+
'X25519': {
255+
generateKey: null,
256+
importKey: null,
257+
deriveBits: 'EcdhKeyDeriveParams',
258+
},
259+
'Ed25519': {
260+
generateKey: null,
261+
sign: null,
262+
verify: null,
263+
importKey: null,
264+
},
265+
'X448': {
266+
generateKey: null,
267+
importKey: null,
268+
deriveBits: 'EcdhKeyDeriveParams',
269+
},
270+
'Ed448': {
271+
generateKey: null,
272+
sign: 'Ed448Params',
273+
verify: 'Ed448Params',
274+
importKey: null,
275+
},
276+
};
277+
278+
for (const { 0: name, 1: ops } of ObjectEntries(experimentalAlgorithms)) {
279+
for (const { 0: op, 1: dict } of ObjectEntries(ops)) {
280+
ObjectDefineProperty(kSupportedAlgorithms[op], name, {
281+
get() {
282+
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
283+
return dict;
284+
},
285+
__proto__: null,
286+
enumerable: true,
287+
});
288+
}
289+
}
290+
273291
const simpleAlgorithmDictionaries = {
274292
AesGcmParams: { iv: 'BufferSource', additionalData: 'BufferSource' },
275293
RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
@@ -594,7 +612,6 @@ module.exports = {
594612
setEngine,
595613
toBuf,
596614

597-
kHashTypes,
598615
kNamedCurveAliases,
599616
kAesKeyLengths,
600617
normalizeAlgorithm,

0 commit comments

Comments
 (0)