diff options
author | Luca Casonato <hello@lcas.dev> | 2021-11-22 23:58:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 23:58:21 +0100 |
commit | 71ceca0ffc4239b62431550b4d9952d909d342ec (patch) | |
tree | 6db6a18e1d88adbaabfa37f69cd4de8a8d277943 /cli/tests/unit/webcrypto_test.ts | |
parent | 3cc724c9bae94c2f79dd4a902782a66f688a1e61 (diff) |
fix(ext/crypto): don't panic on decryption failure (#12840)
Diffstat (limited to 'cli/tests/unit/webcrypto_test.ts')
-rw-r--r-- | cli/tests/unit/webcrypto_test.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 0828f0716..b1d4e9637 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -690,3 +690,26 @@ unitTest(async function testAesKeyGen() { assertEquals(algorithm.name, "AES-GCM"); assertEquals(algorithm.length, 256); }); + +unitTest(async function testDecryptWithInvalidIntializationVector() { + const data = new Uint8Array([42, 42, 42, 42]); + const key = await crypto.subtle.generateKey( + { name: "AES-CBC", length: 256 }, + true, + ["encrypt", "decrypt"], + ); + const initVector = crypto.getRandomValues(new Uint8Array(16)); + const encrypted = await crypto.subtle.encrypt( + { name: "AES-CBC", iv: initVector }, + key, + data, + ); + const initVector2 = crypto.getRandomValues(new Uint8Array(16)); + assertRejects(async () => { + await crypto.subtle.decrypt( + { name: "AES-CBC", iv: initVector2 }, + key, + encrypted, + ); + }, DOMException); +}); |