From 7f02e22998881b747d0d96e130eb64348cbe59f2 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 15 Jun 2022 15:33:44 +0200 Subject: [PATCH] crypto: test webcrypto ec raw public key import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43405 Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- .../test-webcrypto-export-import-ec.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/parallel/test-webcrypto-export-import-ec.js b/test/parallel/test-webcrypto-export-import-ec.js index ff3cb1e445cec3..79f82a3d4adc26 100644 --- a/test/parallel/test-webcrypto-export-import-ec.js +++ b/test/parallel/test-webcrypto-export-import-ec.js @@ -282,6 +282,35 @@ async function testImportJwk( } } +async function testImportRaw({ name, publicUsages }, namedCurve) { + const jwk = keyData[namedCurve].jwk; + + const [publicKey] = await Promise.all([ + subtle.importKey( + 'raw', + Buffer.concat([ + Buffer.alloc(1, 0x04), + Buffer.from(jwk.x, 'base64url'), + Buffer.from(jwk.y, 'base64url'), + ]), + { name, namedCurve }, + true, publicUsages), + subtle.importKey( + 'raw', + Buffer.concat([ + Buffer.alloc(1, 0x03), + Buffer.from(jwk.x, 'base64url'), + ]), + { name, namedCurve }, + true, publicUsages), + ]); + + assert.strictEqual(publicKey.type, 'public'); + assert.deepStrictEqual(publicKey.usages, publicUsages); + assert.strictEqual(publicKey.algorithm.name, name); + assert.strictEqual(publicKey.algorithm.namedCurve, namedCurve); +} + (async function() { const tests = []; testVectors.forEach((vector) => { @@ -291,6 +320,7 @@ async function testImportJwk( tests.push(testImportPkcs8(vector, namedCurve, extractable)); tests.push(testImportJwk(vector, namedCurve, extractable)); }); + tests.push(testImportRaw(vector, namedCurve)); }); });