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

Function testImportPkcs8SeedOnly

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

Source from the content-addressed store, hash-verified

145}
146
147async function testImportPkcs8SeedOnly({ name, privateUsages }, extractable) {
148 const key = await subtle.importKey(
149 'pkcs8',
150 keyData[name].pkcs8_seed_only,
151 { name },
152 extractable,
153 privateUsages);
154 assert.strictEqual(key.type, 'private');
155 assert.strictEqual(key.extractable, extractable);
156 assert.deepStrictEqual(key.usages, privateUsages);
157 assert.deepStrictEqual(key.algorithm.name, name);
158 assert.strictEqual(key.algorithm, key.algorithm);
159 assert.strictEqual(key.usages, key.usages);
160
161 if (extractable) {
162 // Test the roundtrip
163 const pkcs8 = await subtle.exportKey('pkcs8', key);
164 assert.strictEqual(
165 Buffer.from(pkcs8).toString('hex'),
166 keyData[name].pkcs8_seed_only.toString('hex'));
167 } else {
168 await assert.rejects(
169 subtle.exportKey('pkcs8', key), {
170 message: /key is not extractable/,
171 name: 'InvalidAccessError',
172 });
173 }
174
175 await assert.rejects(
176 subtle.importKey(
177 'pkcs8',
178 keyData[name].pkcs8_seed_only,
179 { name },
180 extractable,
181 [/* empty usages */]),
182 { name: 'SyntaxError', message: 'Usages cannot be empty when importing a private key.' });
183}
184
185async function testImportPkcs8PrivOnly({ name, privateUsages }, extractable) {
186 await assert.rejects(

Calls 2

toStringMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected