diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2021-10-11 20:07:51 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-11 16:37:51 +0200 |
commit | 3b2cb8e7113b19344209eddc8bc1bd447fcec4ea (patch) | |
tree | 616169290b703184047ad7beb4b9c79011a2a6ef /cli/tests/unit/webcrypto_test.ts | |
parent | 426ebf854a82c63cdaa2413fbd1b005025dba95b (diff) |
feat(ext/crypto): implement AES-CBC encryption & decryption (#12123)
* initial stuff
* stuff
* merge stuff
* cleanup
* fmt
* length
* update lockfile
* decrypt
* fixy
* clippy hello?
* hmm
* fixs
* fix lint
* add AesCbcParams
* fixes
* fixy
* lockfile fixy
* fix dumb assertions
* re run CI
* rerun CI
* rerun CI
Diffstat (limited to 'cli/tests/unit/webcrypto_test.ts')
-rw-r--r-- | cli/tests/unit/webcrypto_test.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 80275b002..420fa2a7f 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -513,6 +513,40 @@ unitTest(async function testHkdfDeriveBits() { assertEquals(result.byteLength, 128 / 8); }); +unitTest(async function testAesCbcEncryptDecrypt() { + const key = await crypto.subtle.generateKey( + { name: "AES-CBC", length: 128 }, + true, + ["encrypt", "decrypt"], + ); + + const iv = await crypto.getRandomValues(new Uint8Array(16)); + const encrypted = await crypto.subtle.encrypt( + { + name: "AES-CBC", + iv, + }, + key as CryptoKey, + new Uint8Array([1, 2, 3, 4, 5, 6]), + ); + + assert(encrypted instanceof ArrayBuffer); + assertEquals(encrypted.byteLength, 16); + + const decrypted = await crypto.subtle.decrypt( + { + name: "AES-CBC", + iv, + }, + key as CryptoKey, + encrypted, + ); + + assert(decrypted instanceof ArrayBuffer); + assertEquals(decrypted.byteLength, 6); + assertEquals(new Uint8Array(decrypted), new Uint8Array([1, 2, 3, 4, 5, 6])); +}); + // TODO(@littledivy): Enable WPT when we have importKey support unitTest(async function testECDH() { const namedCurve = "P-256"; |