Skip to content

Commit b96f8f0

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 <[email protected]> Reviewed-By: Jordan Harband <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent c75e683 commit b96f8f0

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

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-
function asyncAesGcmCipher(mode, key, data, algorithm) {
134+
async function asyncAesGcmCipher(mode, key, data, algorithm) {
136135
const { tagLength = 128 } = algorithm;
137136

138137
const tagByteLength = 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-
return PromiseReject(lazyDOMException(
150+
throw lazyDOMException(
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-
function eddsaSignVerify(key, data, algorithm, signature) {
345+
async function eddsaSignVerify(key, data, algorithm, signature) {
346346
const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
347347
const type = 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-
function ecdsaSignVerify(key, data, { name, hash }, signature) {
286+
async function ecdsaSignVerify(key, data, { name, hash }, signature) {
287287
const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
288288
const type = 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-
function rsaOaepCipher(mode, key, data, algorithm) {
94+
async function rsaOaepCipher(mode, key, data, algorithm) {
9595
validateRsaOaepAlgorithm(algorithm);
9696

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

331-
function rsaSignVerify(key, data, { saltLength }, signature) {
331+
async function rsaSignVerify(key, data, { saltLength }, signature) {
332332
const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
333333
const type = 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-
function signVerify(algorithm, key, data, signature) {
772+
async function signVerify(algorithm, key, data, signature) {
773773
let usage = 'sign';
774774
if (signature !== undefined) {
775775
usage = 'verify';

0 commit comments

Comments
 (0)