summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/unit/webcrypto_test.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index 5087c7076..0660d9a7e 100644
--- a/cli/tests/unit/webcrypto_test.ts
+++ b/cli/tests/unit/webcrypto_test.ts
@@ -691,6 +691,60 @@ Deno.test(async function testAesKeyGen() {
assertEquals(algorithm.length, 256);
});
+Deno.test(async function testUnwrapKey() {
+ const subtle = crypto.subtle;
+
+ const AES_KEY: AesKeyAlgorithm & AesCbcParams = {
+ name: "AES-CBC",
+ length: 128,
+ iv: new Uint8Array(16),
+ };
+
+ const RSA_KEY: RsaHashedKeyGenParams & RsaOaepParams = {
+ name: "RSA-OAEP",
+ modulusLength: 2048,
+ publicExponent: new Uint8Array([1, 0, 1]),
+ hash: "SHA-1",
+ };
+
+ const aesKey = await subtle.generateKey(AES_KEY, true, [
+ "encrypt",
+ "decrypt",
+ ]);
+
+ const rsaKeyPair = await subtle.generateKey(
+ {
+ name: "RSA-OAEP",
+ hash: "SHA-1",
+ publicExponent: new Uint8Array([1, 0, 1]),
+ modulusLength: 2048,
+ },
+ false,
+ ["wrapKey", "encrypt", "unwrapKey", "decrypt"],
+ );
+
+ const enc = await subtle.wrapKey(
+ "raw",
+ aesKey,
+ rsaKeyPair.publicKey,
+ RSA_KEY,
+ );
+ const unwrappedKey = await subtle.unwrapKey(
+ "raw",
+ enc,
+ rsaKeyPair.privateKey,
+ RSA_KEY,
+ AES_KEY,
+ false,
+ ["encrypt", "decrypt"],
+ );
+
+ assert(unwrappedKey instanceof CryptoKey);
+ assertEquals(unwrappedKey.type, "secret");
+ assertEquals(unwrappedKey.extractable, false);
+ assertEquals(unwrappedKey.usages, ["encrypt", "decrypt"]);
+});
+
Deno.test(async function testDecryptWithInvalidIntializationVector() {
const data = new Uint8Array([42, 42, 42, 42]);
const key = await crypto.subtle.generateKey(