Skip to content

Commit

Permalink
crypto: test webcrypto ec raw public key import
Browse files Browse the repository at this point in the history
PR-URL: #43405
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
panva authored and danielleadams committed Jun 16, 2022
1 parent 0a075cb commit 7f02e22
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/parallel/test-webcrypto-export-import-ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -291,6 +320,7 @@ async function testImportJwk(
tests.push(testImportPkcs8(vector, namedCurve, extractable));
tests.push(testImportJwk(vector, namedCurve, extractable));
});
tests.push(testImportRaw(vector, namedCurve));
});
});

Expand Down

0 comments on commit 7f02e22

Please sign in to comment.