Skip to content

Commit

Permalink
crypto: add causes to applicable webcrypto's OperationError
Browse files Browse the repository at this point in the history
PR-URL: #44890
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
panva authored and danielleadams committed Oct 11, 2022
1 parent 803fbfb commit 99a2c16
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 12 deletions.
3 changes: 1 addition & 2 deletions lib/internal/crypto/aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,10 @@ async function aesGenerateKey(algorithm, extractable, keyUsages) {
}

const key = await generateKey('aes', { length }).catch((err) => {
// TODO(@panva): add err as cause to DOMException
throw lazyDOMException(
'The operation failed for an operation-specific reason' +
`[${err.message}]`,
'OperationError');
{ name: 'OperationError', cause: err });
});

return new InternalCryptoKey(
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/crypto/cfrg.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
}

const keyPair = await generateKeyPair(genKeyType).catch((err) => {
// TODO(@panva): add err as cause to DOMException
throw lazyDOMException(
'The operation failed for an operation-specific reason',
'OperationError');
{ name: 'OperationError', cause: err });
});

let publicUsages;
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/crypto/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ async function ecGenerateKey(algorithm, extractable, keyUsages) {
}

const keypair = await generateKeyPair('ec', { namedCurve }).catch((err) => {
// TODO(@panva): add err as cause to DOMException
throw lazyDOMException(
'The operation failed for an operation-specific reason',
'OperationError');
{ name: 'OperationError', cause: err });
});

let publicUsages;
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/crypto/mac.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ async function hmacGenerateKey(algorithm, extractable, keyUsages) {
}

const key = await generateKey('hmac', { length }).catch((err) => {
// TODO(@panva): add err as cause to DOMException
throw lazyDOMException(
'The operation failed for an operation-specific reason',
'OperationError');
{ name: 'OperationError', cause: err });
});

return new InternalCryptoKey(
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/crypto/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ async function rsaKeyGenerate(
modulusLength,
publicExponent: publicExponentConverted,
}).catch((err) => {
// TODO(@panva): add err as cause to DOMException
throw lazyDOMException(
'The operation failed for an operation-specific reason',
'OperationError');
{ name: 'OperationError', cause: err });
});

const keyAlgorithm = {
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,9 @@ const validateByteSource = hideStackFrames((val, name) => {

function onDone(resolve, reject, err, result) {
if (err) {
// TODO(@panva): add err as cause to DOMException
return reject(lazyDOMException(
'The operation failed for an operation-specific reason',
'OperationError'));
{ name: 'OperationError', cause: err }));
}
resolve(result);
}
Expand Down

0 comments on commit 99a2c16

Please sign in to comment.