crypto: use async functions for non-stub Promise-returning functions · nodejs/node@8ed4587
@@ -5,7 +5,6 @@ const {
55 ArrayBufferPrototypeSlice,
66 ArrayFrom,
77 ArrayPrototypePush,
8- PromiseReject,
98 SafeSet,
109 TypedArrayPrototypeSlice,
1110} = primordials;
@@ -144,7 +143,7 @@ function asyncAesKwCipher(mode, key, data) {
144143getVariant('AES-KW', key[kAlgorithm].length)));
145144}
146145147-function asyncAesGcmCipher(mode, key, data, algorithm) {
146+async function asyncAesGcmCipher(mode, key, data, algorithm) {
148147const { tagLength = 128 } = algorithm;
149148150149const tagByteLength = tagLength / 8;
@@ -160,9 +159,9 @@ function asyncAesGcmCipher(mode, key, data, algorithm) {
160159// > If *plaintext* has a length less than *tagLength* bits, then `throw`
161160// > an `OperationError`.
162161if (tagByteLength > tag.byteLength) {
163-return PromiseReject(lazyDOMException(
162+throw lazyDOMException(
164163'The provided data is too small.',
165-'OperationError'));
164+'OperationError');
166165}
167166168167data = slice(data, 0, -tagByteLength);
@@ -184,7 +183,7 @@ function asyncAesGcmCipher(mode, key, data, algorithm) {
184183algorithm.additionalData));
185184}
186185187-function asyncAesOcbCipher(mode, key, data, algorithm) {
186+async function asyncAesOcbCipher(mode, key, data, algorithm) {
188187const { tagLength = 128 } = algorithm;
189188190189const tagByteLength = tagLength / 8;
@@ -197,9 +196,9 @@ function asyncAesOcbCipher(mode, key, data, algorithm) {
197196198197// Similar to GCM, OCB requires the tag to be present for decryption
199198if (tagByteLength > tag.byteLength) {
200-return PromiseReject(lazyDOMException(
199+throw lazyDOMException(
201200'The provided data is too small.',
202-'OperationError'));
201+'OperationError');
203202}
204203205204data = slice(data, 0, -tagByteLength);