Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: test webcrypto ec raw public key import #43405

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -262,6 +262,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'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For hard-coded encoding/decoding mechanisms, it's usually a good idea to add a comment with a reference to a resource defining the relevant encoding.

]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note... It would be nice if Web Crypto supported using Blob for this kind of stuff.

{ 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 @@ -271,6 +300,7 @@ async function testImportJwk(
tests.push(testImportPkcs8(vector, namedCurve, extractable));
tests.push(testImportJwk(vector, namedCurve, extractable));
});
tests.push(testImportRaw(vector, namedCurve));
});
});

Expand Down