Skip to content

Commit aed9fd5

Browse files
Renegade334aduh95
authored andcommitted
crypto: avoid calls to promise.catch()
This avoids explicit calls to the user-mutable `%Promise.prototype%.catch`, and by association, implicit calls to the user-mutable `%Promise.prototype%.then`. PR-URL: #59841 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jordan Harband <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent 8e182e5 commit aed9fd5

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

lib/internal/crypto/aes.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) {
195195
'SyntaxError');
196196
}
197197

198-
const key = await generateKey('aes', { length }).catch((err) => {
198+
let key;
199+
try {
200+
key = await generateKey('aes', { length });
201+
} catch (err) {
199202
throw lazyDOMException(
200203
'The operation failed for an operation-specific reason' +
201204
`[${err.message}]`,
202205
{ name: 'OperationError', cause: err });
203-
});
206+
}
204207

205208
return new InternalCryptoKey(
206209
key,

lib/internal/crypto/cfrg.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,14 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
148148
break;
149149
}
150150

151-
const keyPair = await generateKeyPair(genKeyType).catch((err) => {
151+
let keyPair;
152+
try {
153+
keyPair = await generateKeyPair(genKeyType);
154+
} catch (err) {
152155
throw lazyDOMException(
153156
'The operation failed for an operation-specific reason',
154157
{ name: 'OperationError', cause: err });
155-
});
158+
}
156159

157160
let publicUsages;
158161
let privateUsages;

lib/internal/crypto/ec.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) {
9696
// Fall through
9797
}
9898

99-
const keypair = await generateKeyPair('ec', { namedCurve }).catch((err) => {
99+
let keyPair;
100+
try {
101+
keyPair = await generateKeyPair('ec', { namedCurve });
102+
} catch(err) {
100103
throw lazyDOMException(
101104
'The operation failed for an operation-specific reason',
102105
{ name: 'OperationError', cause: err });
103-
});
106+
}
104107

105108
let publicUsages;
106109
let privateUsages;
@@ -119,14 +122,14 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) {
119122

120123
const publicKey =
121124
new InternalCryptoKey(
122-
keypair.publicKey,
125+
keyPair.publicKey,
123126
keyAlgorithm,
124127
publicUsages,
125128
true);
126129

127130
const privateKey =
128131
new InternalCryptoKey(
129-
keypair.privateKey,
132+
keyPair.privateKey,
130133
keyAlgorithm,
131134
privateUsages,
132135
extractable);

lib/internal/crypto/mac.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ async function hmacGenerateKey(algorithm, extractable, keyUsages) {
5454
'SyntaxError');
5555
}
5656

57-
const key = await generateKey('hmac', { length }).catch((err) => {
57+
let key;
58+
try {
59+
key = await generateKey('hmac', { length });
60+
} catch (err) {
5861
throw lazyDOMException(
5962
'The operation failed for an operation-specific reason',
6063
{ name: 'OperationError', cause: err });
61-
});
64+
}
6265

6366
return new InternalCryptoKey(
6467
key,

lib/internal/crypto/rsa.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,17 @@ async function rsaKeyGenerate(
148148
}
149149
}
150150

151-
const keypair = await generateKeyPair('rsa', {
152-
modulusLength,
153-
publicExponent: publicExponentConverted,
154-
}).catch((err) => {
151+
let keyPair;
152+
try {
153+
keyPair = await generateKeyPair('rsa', {
154+
modulusLength,
155+
publicExponent: publicExponentConverted,
156+
});
157+
} catch (err) {
155158
throw lazyDOMException(
156159
'The operation failed for an operation-specific reason',
157160
{ name: 'OperationError', cause: err });
158-
});
161+
}
159162

160163
const keyAlgorithm = {
161164
name,
@@ -181,14 +184,14 @@ async function rsaKeyGenerate(
181184

182185
const publicKey =
183186
new InternalCryptoKey(
184-
keypair.publicKey,
187+
keyPair.publicKey,
185188
keyAlgorithm,
186189
publicUsages,
187190
true);
188191

189192
const privateKey =
190193
new InternalCryptoKey(
191-
keypair.privateKey,
194+
keyPair.privateKey,
192195
keyAlgorithm,
193196
privateUsages,
194197
extractable);

0 commit comments

Comments
 (0)