Skip to content

Commit 1cb2672

Browse files
panvatargos
authored andcommitted
crypto: test webcrypto ec raw public key import
PR-URL: #43405 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 053347c commit 1cb2672

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/parallel/test-webcrypto-export-import-ec.js

+30
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,35 @@ async function testImportJwk(
262262
}
263263
}
264264

265+
async function testImportRaw({ name, publicUsages }, namedCurve) {
266+
const jwk = keyData[namedCurve].jwk;
267+
268+
const [publicKey] = await Promise.all([
269+
subtle.importKey(
270+
'raw',
271+
Buffer.concat([
272+
Buffer.alloc(1, 0x04),
273+
Buffer.from(jwk.x, 'base64url'),
274+
Buffer.from(jwk.y, 'base64url'),
275+
]),
276+
{ name, namedCurve },
277+
true, publicUsages),
278+
subtle.importKey(
279+
'raw',
280+
Buffer.concat([
281+
Buffer.alloc(1, 0x03),
282+
Buffer.from(jwk.x, 'base64url'),
283+
]),
284+
{ name, namedCurve },
285+
true, publicUsages),
286+
]);
287+
288+
assert.strictEqual(publicKey.type, 'public');
289+
assert.deepStrictEqual(publicKey.usages, publicUsages);
290+
assert.strictEqual(publicKey.algorithm.name, name);
291+
assert.strictEqual(publicKey.algorithm.namedCurve, namedCurve);
292+
}
293+
265294
(async function() {
266295
const tests = [];
267296
testVectors.forEach((vector) => {
@@ -271,6 +300,7 @@ async function testImportJwk(
271300
tests.push(testImportPkcs8(vector, namedCurve, extractable));
272301
tests.push(testImportJwk(vector, namedCurve, extractable));
273302
});
303+
tests.push(testImportRaw(vector, namedCurve));
274304
});
275305
});
276306

0 commit comments

Comments
 (0)