diff options
Diffstat (limited to 'cli/tests/unit/webcrypto_test.ts')
-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); |