Skip to content

Commit f488b2f

Browse files
Renegade334aduh95
authored andcommitted
crypto: use async functions for non-stub Promise-returning functions
These were intended to mimic simple async functions, but exceptions thrown in the function body would be returned synchronously, not wrapped in a rejected Promise. 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 aed9fd5 commit f488b2f

5 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎lib/internal/crypto/aes.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {
55
ArrayBufferPrototypeSlice,
66
ArrayFrom,
77
ArrayPrototypePush,
8-
PromiseReject,
98
SafeSet,
109
TypedArrayPrototypeSlice,
1110
}=primordials;
@@ -132,7 +131,7 @@ function asyncAesKwCipher(mode, key, data) {
132131
getVariant('AES-KW',key.algorithm.length)));
133132
}
134133

135-
functionasyncAesGcmCipher(mode,key,data,algorithm){
134+
asyncfunctionasyncAesGcmCipher(mode,key,data,algorithm){
136135
const{ tagLength =128}=algorithm;
137136

138137
consttagByteLength=tagLength/8;
@@ -148,9 +147,9 @@ function asyncAesGcmCipher(mode, key, data, algorithm) {
148147
// > If *plaintext* has a length less than *tagLength* bits, then `throw`
149148
// > an `OperationError`.
150149
if(tagByteLength>tag.byteLength){
151-
returnPromiseReject(lazyDOMException(
150+
throwlazyDOMException(
152151
'The provided data is too small.',
153-
'OperationError'));
152+
'OperationError');
154153
}
155154

156155
data=slice(data,0,-tagByteLength);

‎lib/internal/crypto/cfrg.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ function cfrgImportKey(
342342
extractable);
343343
}
344344

345-
functioneddsaSignVerify(key,data,algorithm,signature){
345+
asyncfunctioneddsaSignVerify(key,data,algorithm,signature){
346346
constmode=signature===undefined ? kSignJobModeSign : kSignJobModeVerify;
347347
consttype=mode===kSignJobModeSign ? 'private' : 'public';
348348

‎lib/internal/crypto/ec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function ecImportKey(
283283
extractable);
284284
}
285285

286-
functionecdsaSignVerify(key,data,{ name, hash },signature){
286+
asyncfunctionecdsaSignVerify(key,data,{ name, hash },signature){
287287
constmode=signature===undefined ? kSignJobModeSign : kSignJobModeVerify;
288288
consttype=mode===kSignJobModeSign ? 'private' : 'public';
289289

‎lib/internal/crypto/rsa.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function validateRsaOaepAlgorithm(algorithm) {
9191
}
9292
}
9393

94-
functionrsaOaepCipher(mode,key,data,algorithm){
94+
asyncfunctionrsaOaepCipher(mode,key,data,algorithm){
9595
validateRsaOaepAlgorithm(algorithm);
9696

9797
consttype=mode===kWebCryptoCipherEncrypt ? 'public' : 'private';
@@ -328,7 +328,7 @@ function rsaImportKey(
328328
},keyUsages,extractable);
329329
}
330330

331-
functionrsaSignVerify(key,data,{ saltLength },signature){
331+
asyncfunctionrsaSignVerify(key,data,{ saltLength },signature){
332332
constmode=signature===undefined ? kSignJobModeSign : kSignJobModeVerify;
333333
consttype=mode===kSignJobModeSign ? 'private' : 'public';
334334

‎lib/internal/crypto/webcrypto.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ async function unwrapKey(
769769
);
770770
}
771771

772-
functionsignVerify(algorithm,key,data,signature){
772+
asyncfunctionsignVerify(algorithm,key,data,signature){
773773
letusage='sign';
774774
if(signature!==undefined){
775775
usage='verify';

0 commit comments

Comments
 (0)