From b3444e0d3b3544816e0286dda3e861fd5debea65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=91=9E=E4=B8=B0?= Date: Mon, 3 Oct 2022 12:07:25 +0800 Subject: fix(ext/crypto): fix importKey error when leading zeroes (#16009) Co-authored-by: Jason --- cli/tests/unit/webcrypto_test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index a6cab93dd..6695b157a 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1827,3 +1827,30 @@ Deno.test(async function exportKeyNotExtractable() { await crypto.subtle.exportKey("raw", key); }, DOMException); }); + +// https://github.com/denoland/deno/issues/15126 +Deno.test(async function testImportLeadingZeroesKey() { + const alg = { name: "ECDSA", namedCurve: "P-256" }; + + const jwk = { + kty: "EC", + crv: "P-256", + alg: "ES256", + x: "EvidcdFB1xC6tgfakqZsU9aIURxAJkcX62zHe1Nt6xU", + y: "AHsk6BioGM7MZWeXOE_49AGmtuaXFT3Ill3DYtz9uYg", + d: "WDeYo4o1heCF9l_2VIaClRyIeO16zsMlN8UG6Le9dU8", + "key_ops": ["sign"], + ext: true, + }; + + const key = await crypto.subtle.importKey( + "jwk", + jwk, + alg, + true, + ["sign"], + ); + + assert(key instanceof CryptoKey); + assertEquals(key.type, "private"); +}); -- cgit v1.2.3