summaryrefslogtreecommitdiff
path: root/tests/unit_node/crypto/crypto_key_test.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-03-14 06:39:46 -0700
committerGitHub <noreply@github.com>2024-03-14 14:39:46 +0100
commit9c348a0acd7d1bc288c2ce5b66016571b9603288 (patch)
tree631f24c5d2093e472eb6209ca6609702f0261fd4 /tests/unit_node/crypto/crypto_key_test.ts
parentcf3c6f9b0812ad487320834399bc4863dadd9655 (diff)
fix(ext/node): support `spki` format in createPublicKey (#22918)
Diffstat (limited to 'tests/unit_node/crypto/crypto_key_test.ts')
-rw-r--r--tests/unit_node/crypto/crypto_key_test.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit_node/crypto/crypto_key_test.ts b/tests/unit_node/crypto/crypto_key_test.ts
index 656c7bb24..bcb47b5a7 100644
--- a/tests/unit_node/crypto/crypto_key_test.ts
+++ b/tests/unit_node/crypto/crypto_key_test.ts
@@ -284,3 +284,32 @@ Deno.test("createPublicKey() EC", function () {
assertEquals(key.asymmetricKeyType, "ec");
assertEquals(key.asymmetricKeyDetails?.namedCurve, "p256");
});
+
+Deno.test("createPublicKey SPKI for DH", async function () {
+ const { publicKey, privateKey } = await crypto.subtle.generateKey(
+ {
+ name: "ECDH",
+ namedCurve: "P-384",
+ },
+ true,
+ ["deriveKey", "deriveBits"],
+ );
+
+ const exportedPublicKey = await crypto.subtle.exportKey("spki", publicKey);
+ const exportedPrivateKey = await crypto.subtle.exportKey("pkcs8", privateKey);
+
+ const pubKey = createPublicKey({
+ key: Buffer.from(exportedPublicKey),
+ format: "der",
+ type: "spki",
+ });
+
+ const privKey = createPrivateKey({
+ key: Buffer.from(exportedPrivateKey),
+ format: "der",
+ type: "pkcs8",
+ });
+
+ assertEquals(pubKey.asymmetricKeyType, "ec");
+ assertEquals(privKey.asymmetricKeyType, "ec");
+});