Skip to content

Commit

Permalink
crypto: fix webcrypto operation errors to be OperationError
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Aug 10, 2022
1 parent c3ff198 commit ff44998
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
6 changes: 5 additions & 1 deletion lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ const validateByteSource = hideStackFrames((val, name) => {
});

function onDone(resolve, reject, err, result) {
if (err) return reject(err);
if (err) {
return reject(lazyDOMException(
'The operation failed for an operation-specific reason',
'OperationError'));
}
resolve(result);
}

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-webcrypto-encrypt-decrypt-aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async function testDecrypt({ keyBuffer, algorithm, result }) {

decryptionFailing.forEach((vector) => {
variations.push(assert.rejects(testDecrypt(vector), {
message: /bad decrypt/
name: 'OperationError'
}));
});

Expand Down Expand Up @@ -158,7 +158,7 @@ async function testDecrypt({ keyBuffer, algorithm, result }) {

decryptionFailing.forEach((vector) => {
variations.push(assert.rejects(testDecrypt(vector), {
message: /bad decrypt/
name: 'OperationError'
}));
});

Expand Down Expand Up @@ -195,7 +195,7 @@ async function testDecrypt({ keyBuffer, algorithm, result }) {

decryptionFailing.forEach((vector) => {
variations.push(assert.rejects(testDecrypt(vector), {
message: /bad decrypt/
name: 'OperationError'
}));
});

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-webcrypto-encrypt-decrypt-rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async function testEncryptionLongPlaintext({ algorithm,

return assert.rejects(
subtle.encrypt(algorithm, publicKey, newplaintext), {
message: /data too large/
name: 'OperationError'
});
}

Expand Down
21 changes: 0 additions & 21 deletions test/wpt/status/WebCryptoAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -2654,33 +2654,12 @@
"encrypt_decrypt/aes_cbc.https.any.js": {
"fail": {
"expected": [
"AES-CBC 128-bit key, zeroPadChar",
"AES-CBC 128-bit key, bigPadChar",
"AES-CBC 128-bit key, inconsistentPadChars",
"AES-CBC 192-bit key, zeroPadChar",
"AES-CBC 192-bit key, bigPadChar",
"AES-CBC 192-bit key, inconsistentPadChars",
"AES-CBC 256-bit key, zeroPadChar",
"AES-CBC 256-bit key, bigPadChar",
"AES-CBC 256-bit key, inconsistentPadChars"
]
}
},
"encrypt_decrypt/rsa_oaep.https.any.js": {
"fail": {
"expected": [
"RSA-OAEP with SHA-1 and no label too long plaintext",
"RSA-OAEP with SHA-256 and no label too long plaintext",
"RSA-OAEP with SHA-384 and no label too long plaintext",
"RSA-OAEP with SHA-512 and no label too long plaintext",
"RSA-OAEP with SHA-1 and empty label too long plaintext",
"RSA-OAEP with SHA-256 and empty label too long plaintext",
"RSA-OAEP with SHA-384 and empty label too long plaintext",
"RSA-OAEP with SHA-512 and empty label too long plaintext",
"RSA-OAEP with SHA-1 and a label too long plaintext",
"RSA-OAEP with SHA-256 and a label too long plaintext",
"RSA-OAEP with SHA-384 and a label too long plaintext",
"RSA-OAEP with SHA-512 and a label too long plaintext"
]
}
},
Expand Down

0 comments on commit ff44998

Please sign in to comment.