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 <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 8e182e5 commit aed9fd5

5 files changed

Lines changed: 32 additions & 17 deletions

File tree

‎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-
constkey=awaitgenerateKey('aes',{ length }).catch((err)=>{
198+
letkey;
199+
try{
200+
key=awaitgenerateKey('aes',{ length });
201+
}catch(err){
199202
throwlazyDOMException(
200203
'The operation failed for an operation-specific reason'+
201204
`[${err.message}]`,
202205
{name: 'OperationError',cause: err});
203-
});
206+
}
204207

205208
returnnewInternalCryptoKey(
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-
constkeyPair=awaitgenerateKeyPair(genKeyType).catch((err)=>{
151+
letkeyPair;
152+
try{
153+
keyPair=awaitgenerateKeyPair(genKeyType);
154+
}catch(err){
152155
throwlazyDOMException(
153156
'The operation failed for an operation-specific reason',
154157
{name: 'OperationError',cause: err});
155-
});
158+
}
156159

157160
letpublicUsages;
158161
letprivateUsages;

‎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-
constkeypair=awaitgenerateKeyPair('ec',{ namedCurve }).catch((err)=>{
99+
letkeyPair;
100+
try{
101+
keyPair=awaitgenerateKeyPair('ec',{ namedCurve });
102+
}catch(err){
100103
throwlazyDOMException(
101104
'The operation failed for an operation-specific reason',
102105
{name: 'OperationError',cause: err});
103-
});
106+
}
104107

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

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

127130
constprivateKey=
128131
newInternalCryptoKey(
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-
constkey=awaitgenerateKey('hmac',{ length }).catch((err)=>{
57+
letkey;
58+
try{
59+
key=awaitgenerateKey('hmac',{ length });
60+
}catch(err){
5861
throwlazyDOMException(
5962
'The operation failed for an operation-specific reason',
6063
{name: 'OperationError',cause: err});
61-
});
64+
}
6265

6366
returnnewInternalCryptoKey(
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-
constkeypair=awaitgenerateKeyPair('rsa',{
152-
modulusLength,
153-
publicExponent: publicExponentConverted,
154-
}).catch((err)=>{
151+
letkeyPair;
152+
try{
153+
keyPair=awaitgenerateKeyPair('rsa',{
154+
modulusLength,
155+
publicExponent: publicExponentConverted,
156+
});
157+
}catch(err){
155158
throwlazyDOMException(
156159
'The operation failed for an operation-specific reason',
157160
{name: 'OperationError',cause: err});
158-
});
161+
}
159162

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

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

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

0 commit comments

Comments
 (0)