From 5065c7bcd9973056b9b0d9df71d139da83596acc Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 1 Oct 2021 15:09:49 +0530 Subject: feat(ext/crypto): implement wrapKey (#12125) --- cli/tests/unit/webcrypto_test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 56a23bfb5..493cf9517 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -499,3 +499,40 @@ unitTest(async function testHkdfDeriveBits() { ); assertEquals(result.byteLength, 128 / 8); }); + +unitTest(async function testWrapKey() { + // Test wrapKey + const key = await crypto.subtle.generateKey( + { + name: "RSA-OAEP", + modulusLength: 4096, + publicExponent: new Uint8Array([1, 0, 1]), + hash: "SHA-256", + }, + true, + ["wrapKey", "unwrapKey"], + ); + + const hmacKey = await crypto.subtle.generateKey( + { + name: "HMAC", + hash: "SHA-256", + length: 128, + }, + true, + ["sign"], + ); + + const wrappedKey = await crypto.subtle.wrapKey( + "raw", + hmacKey, + key.publicKey, + { + name: "RSA-OAEP", + label: new Uint8Array(8), + }, + ); + + assert(wrappedKey instanceof ArrayBuffer); + assertEquals(wrappedKey.byteLength, 512); +}); -- cgit v1.2.3