diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2021-07-12 18:15:36 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-12 14:45:36 +0200 |
commit | 00484d24ba93418bbdde8e42483d56e3714efaa0 (patch) | |
tree | a01e26ed9f6bf7f8d1bf66dae92fd8e10a00c738 /cli/tests | |
parent | e95c0c85fae565bb403329d9918321a507986e56 (diff) |
feat(extensions/crypto): implement verify() for RSA (#11312)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/webcrypto_test.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index b507a0c58..4af31789a 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1,5 +1,54 @@ import { assert, assertEquals, unitTest } from "./test_util.ts"; +// TODO(@littledivy): Remove this when we enable WPT for sign_verify +unitTest(async function testSignVerify() { + const subtle = window.crypto.subtle; + assert(subtle); + for (const algorithm of ["RSA-PSS", "RSASSA-PKCS1-v1_5"]) { + for ( + const hash of [ + "SHA-1", + "SHA-256", + "SHA-384", + "SHA-512", + ] + ) { + const keyPair = await subtle.generateKey( + { + name: algorithm, + modulusLength: 2048, + publicExponent: new Uint8Array([1, 0, 1]), + hash, + }, + true, + ["sign", "verify"], + ); + + const data = new Uint8Array([1, 2, 3]); + const signAlgorithm = { name: algorithm, saltLength: 32 }; + + const signature = await subtle.sign( + signAlgorithm, + keyPair.privateKey, + data, + ); + + assert(signature); + assert(signature.byteLength > 0); + assert(signature.byteLength % 8 == 0); + assert(signature instanceof ArrayBuffer); + + const verified = await subtle.verify( + signAlgorithm, + keyPair.publicKey, + signature, + data, + ); + assert(verified); + } + } +}); + unitTest(async function testGenerateRSAKey() { const subtle = window.crypto.subtle; assert(subtle); |