crypto: prepare webcrypto key import/export for modern algorithms · nodejs/node@a312e70 · GitHub
Skip to content

Commit a312e70

Browse files
panvaRafaelGSS
authored andcommitted
crypto: prepare webcrypto key import/export for modern algorithms
PR-URL: #59284 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 95b8b7e commit a312e70

8 files changed

Lines changed: 125 additions & 97 deletions

File tree

lib/internal/crypto/aes.js

Lines changed: 1 addition & 3 deletions

lib/internal/crypto/cfrg.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ function cfrgImportKey(
324324
keyObject = createCFRGRawKey(name, keyData, true);
325325
break;
326326
}
327+
default:
328+
return undefined;
327329
}
328330

329331
if (keyObject.asymmetricKeyType !== name.toLowerCase()) {

lib/internal/crypto/ec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ function ecImportKey(
250250
keyObject = createECPublicKeyRaw(namedCurve, keyData);
251251
break;
252252
}
253+
default:
254+
return undefined;
253255
}
254256

255257
switch (algorithm.name) {

lib/internal/crypto/keys.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -922,15 +922,11 @@ function importGenericSecretKey(
922922
keyObject = createSecretKey(keyData);
923923
break;
924924
}
925+
default:
926+
return undefined;
925927
}
926928

927-
if (keyObject) {
928-
return new InternalCryptoKey(keyObject, { name }, keyUsages, false);
929-
}
930-
931-
throw lazyDOMException(
932-
`Unable to import ${name} key with format ${format}`,
933-
'NotSupportedError');
929+
return new InternalCryptoKey(keyObject, { name }, keyUsages, false);
934930
}
935931

936932
module.exports = {

lib/internal/crypto/mac.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function hmacImportKey(
143143
break;
144144
}
145145
default:
146-
throw lazyDOMException(`Unable to import HMAC key with format ${format}`);
146+
return undefined;
147147
}
148148

149149
const { length } = keyObject[kHandle].keyDetail({});

lib/internal/crypto/rsa.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ function rsaImportKey(
305305
break;
306306
}
307307
default:
308-
throw lazyDOMException(
309-
`Unable to import RSA key with format ${format}`,
310-
'NotSupportedError');
308+
return undefined;
311309
}
312310

313311
if (keyObject.asymmetricKeyType !== 'rsa') {

lib/internal/crypto/util.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ const kSupportedAlgorithms = {
189189
'Ed25519': null,
190190
'X25519': null,
191191
},
192+
'exportKey': {
193+
'RSASSA-PKCS1-v1_5': null,
194+
'RSA-PSS': null,
195+
'RSA-OAEP': null,
196+
'ECDSA': null,
197+
'ECDH': null,
198+
'HMAC': null,
199+
'AES-CTR': null,
200+
'AES-CBC': null,
201+
'AES-GCM': null,
202+
'AES-KW': null,
203+
'Ed25519': null,
204+
'X25519': null,
205+
},
192206
'sign': {
193207
'RSASSA-PKCS1-v1_5': null,
194208
'RSA-PSS': 'RsaPssParams',
@@ -259,12 +273,14 @@ const experimentalAlgorithms = ObjectEntries({
259273
generateKey: null,
260274
importKey: null,
261275
deriveBits: 'EcdhKeyDeriveParams',
276+
exportKey: null,
262277
},
263278
'Ed448': {
264279
generateKey: null,
265280
sign: 'Ed448Params',
266281
verify: 'Ed448Params',
267282
importKey: null,
283+
exportKey: null,
268284
},
269285
});
270286

lib/internal/crypto/webcrypto.js

Lines changed: 99 additions & 83 deletions

0 commit comments

Comments
 (0)