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

Function testFormat

test/fixtures/wpt/WebCryptoAPI/import_export/ML-KEM_importKey.js:48–105  ·  view source on GitHub ↗
(format, algorithm, keyData, keySize, usages, extractable)

Source from the content-addressed store, hash-verified

46// Test importKey with a given key format and other parameters. If
47// extrable is true, export the key and verify that it matches the input.
48function testFormat(format, algorithm, keyData, keySize, usages, extractable) {
49 [algorithm, algorithm.name].forEach((alg) => {
50 promise_test(function (test) {
51 return subtle
52 .importKey(format, keyData[format], alg, extractable, usages)
53 .then(
54 function (key) {
55 assert_equals(
56 key.constructor,
57 CryptoKey,
58 'Imported a CryptoKey object'
59 );
60 assert_goodCryptoKey(
61 key,
62 algorithm,
63 extractable,
64 usages,
65 format === 'pkcs8' ||
66 format === 'raw-seed' ||
67 (format === 'jwk' && keyData[format].priv)
68 ? 'private'
69 : 'public'
70 );
71 if (!extractable) {
72 return;
73 }
74
75 return subtle.exportKey(format, key).then(
76 function (result) {
77 if (format !== 'jwk') {
78 assert_true(
79 equalBuffers(keyData[format], result),
80 'Round trip works'
81 );
82 } else {
83 assert_true(
84 equalJwk(keyData[format], result),
85 'Round trip works'
86 );
87 }
88 },
89 function (err) {
90 assert_unreached(
91 'Threw an unexpected error: ' + err.toString()
92 );
93 }
94 );
95 },
96 function (err) {
97 assert_unreached('Threw an unexpected error: ' + err.toString());
98 }
99 );
100 }, 'Good parameters: ' +
101 keySize.toString() +
102 ' bits ' +
103 parameterString(format, keyData[format], alg, extractable, usages));
104 });
105}

Callers 1

runTestsFunction · 0.70

Calls 11

assert_goodCryptoKeyFunction · 0.85
equalBuffersFunction · 0.85
equalJwkFunction · 0.85
parameterStringFunction · 0.70
forEachMethod · 0.65
promise_testFunction · 0.50
assert_equalsFunction · 0.50
assert_trueFunction · 0.50
assert_unreachedFunction · 0.50
thenMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected