Skip to content

Commit 7f02e22

Browse files
panvadanielleadams
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 0a075cb commit 7f02e22

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
@@ -282,6 +282,35 @@ async function testImportJwk(
282282
}
283283
}
284284

285+
async function testImportRaw({ name, publicUsages }, namedCurve) {
286+
const jwk = keyData[namedCurve].jwk;
287+
288+
const [publicKey] = await Promise.all([
289+
subtle.importKey(
290+
'raw',
291+
Buffer.concat([
292+
Buffer.alloc(1, 0x04),
293+
Buffer.from(jwk.x, 'base64url'),
294+
Buffer.from(jwk.y, 'base64url'),
295+
]),
296+
{ name, namedCurve },
297+
true, publicUsages),
298+
subtle.importKey(
299+
'raw',
300+
Buffer.concat([
301+
Buffer.alloc(1, 0x03),
302+
Buffer.from(jwk.x, 'base64url'),
303+
]),
304+
{ name, namedCurve },
305+
true, publicUsages),
306+
]);
307+
308+
assert.strictEqual(publicKey.type, 'public');
309+
assert.deepStrictEqual(publicKey.usages, publicUsages);
310+
assert.strictEqual(publicKey.algorithm.name, name);
311+
assert.strictEqual(publicKey.algorithm.namedCurve, namedCurve);
312+
}
313+
285314
(async function() {
286315
const tests = [];
287316
testVectors.forEach((vector) => {
@@ -291,6 +320,7 @@ async function testImportJwk(
291320
tests.push(testImportPkcs8(vector, namedCurve, extractable));
292321
tests.push(testImportJwk(vector, namedCurve, extractable));
293322
});
323+
tests.push(testImportRaw(vector, namedCurve));
294324
});
295325
});
296326

0 commit comments

Comments
 (0)