MCPcopy Index your code
hub / github.com/nodejs/node / testImportSpki

Function testImportSpki

test/parallel/test-webcrypto-export-import-ml-dsa.js:59–96  ·  view source on GitHub ↗
({ name, publicUsages }, extractable)

Source from the content-addressed store, hash-verified

57];
58
59async function testImportSpki({ name, publicUsages }, extractable) {
60 const key = await subtle.importKey(
61 'spki',
62 keyData[name].spki,
63 { name },
64 extractable,
65 publicUsages);
66 assert.strictEqual(key.type, 'public');
67 assert.strictEqual(key.extractable, extractable);
68 assert.deepStrictEqual(key.usages, publicUsages);
69 assert.deepStrictEqual(key.algorithm.name, name);
70 assert.strictEqual(key.algorithm, key.algorithm);
71 assert.strictEqual(key.usages, key.usages);
72
73 if (extractable) {
74 // Test the roundtrip
75 const spki = await subtle.exportKey('spki', key);
76 assert.strictEqual(
77 Buffer.from(spki).toString('hex'),
78 keyData[name].spki.toString('hex'));
79 } else {
80 await assert.rejects(
81 subtle.exportKey('spki', key), {
82 message: /key is not extractable/,
83 name: 'InvalidAccessError',
84 });
85 }
86
87 // Bad usage
88 await assert.rejects(
89 subtle.importKey(
90 'spki',
91 keyData[name].spki,
92 { name },
93 extractable,
94 ['wrapKey']),
95 { message: /Unsupported key usage/ });
96}
97
98async function testImportPkcs8({ name, privateUsages }, extractable) {
99 let key;

Calls 2

toStringMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected