Skip to content

Commit 634a889

Browse files
Renegade334targos
authored andcommitted
crypto: use return await when returning Promises from async functions
This offers _some_ resistance to `%Promise.prototype%` pollution. Refs: #59699 PR-URL: #59841 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jordan Harband <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent 64cfb65 commit 634a889

File tree

9 files changed

+61
-41
lines changed

9 files changed

+61
-41
lines changed

lib/internal/crypto/aes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async function asyncAesGcmCipher(mode, key, data, algorithm) {
172172
break;
173173
}
174174

175-
return jobPromise(() => new AESCipherJob(
175+
return await jobPromise(() => new AESCipherJob(
176176
kCryptoJobAsync,
177177
mode,
178178
key[kKeyObject][kHandle],
@@ -209,7 +209,7 @@ async function asyncAesOcbCipher(mode, key, data, algorithm) {
209209
break;
210210
}
211211

212-
return jobPromise(() => new AESCipherJob(
212+
return await jobPromise(() => new AESCipherJob(
213213
kCryptoJobAsync,
214214
mode,
215215
key[kKeyObject][kHandle],

lib/internal/crypto/cfrg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ async function eddsaSignVerify(key, data, algorithm, signature) {
350350
if (key[kKeyType] !== type)
351351
throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError');
352352

353-
return jobPromise(() => new SignJob(
353+
return await jobPromise(() => new SignJob(
354354
kCryptoJobAsync,
355355
mode,
356356
key[kKeyObject][kHandle],

lib/internal/crypto/chacha20_poly1305.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function c20pCipher(mode, key, data, algorithm) {
6868
break;
6969
}
7070

71-
return jobPromise(() => new ChaCha20Poly1305CipherJob(
71+
return await jobPromise(() => new ChaCha20Poly1305CipherJob(
7272
kCryptoJobAsync,
7373
mode,
7474
key[kKeyObject][kHandle],

lib/internal/crypto/ec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) {
100100
let keyPair;
101101
try {
102102
keyPair = await generateKeyPair('ec', { namedCurve });
103-
} catch(err) {
103+
} catch (err) {
104104
throw lazyDOMException(
105105
'The operation failed for an operation-specific reason',
106106
{ name: 'OperationError', cause: err });
@@ -293,7 +293,7 @@ async function ecdsaSignVerify(key, data, { name, hash }, signature) {
293293

294294
const hashname = normalizeHashName(hash.name);
295295

296-
return jobPromise(() => new SignJob(
296+
return await jobPromise(() => new SignJob(
297297
kCryptoJobAsync,
298298
mode,
299299
key[kKeyObject][kHandle],

lib/internal/crypto/hash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ async function asyncDigest(algorithm, data) {
221221
case 'cSHAKE128':
222222
// Fall through
223223
case 'cSHAKE256':
224-
return jobPromise(() => new HashJob(
224+
return await jobPromise(() => new HashJob(
225225
kCryptoJobAsync,
226226
normalizeHashName(algorithm.name),
227227
data,

lib/internal/crypto/ml_dsa.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ async function mlDsaSignVerify(key, data, algorithm, signature) {
294294
if (key[kKeyType] !== type)
295295
throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError');
296296

297-
return jobPromise(() => new SignJob(
297+
return await jobPromise(() => new SignJob(
298298
kCryptoJobAsync,
299299
mode,
300300
key[kKeyObject][kHandle],

lib/internal/crypto/ml_kem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async function mlKemGenerateKey(algorithm, extractable, keyUsages) {
6262
let keyPair;
6363
try {
6464
keyPair = await generateKeyPair(name.toLowerCase());
65-
} catch(err) {
65+
} catch (err) {
6666
throw lazyDOMException(
6767
'The operation failed for an operation-specific reason',
6868
{ name: 'OperationError', cause: err });

lib/internal/crypto/rsa.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async function rsaOaepCipher(mode, key, data, algorithm) {
103103
'InvalidAccessError');
104104
}
105105

106-
return jobPromise(() => new RSACipherJob(
106+
return await jobPromise(() => new RSACipherJob(
107107
kCryptoJobAsync,
108108
mode,
109109
key[kKeyObject][kHandle],
@@ -337,7 +337,7 @@ async function rsaSignVerify(key, data, { saltLength }, signature) {
337337
if (key[kKeyType] !== type)
338338
throw lazyDOMException(`Key must be a ${type} key`, 'InvalidAccessError');
339339

340-
return jobPromise(() => {
340+
return await jobPromise(() => {
341341
if (key[kAlgorithm].name === 'RSA-PSS') {
342342
validateInt32(
343343
saltLength,

0 commit comments

Comments
 (0)