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

Function testFormat

test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey.js:42–68  ·  view source on GitHub ↗
(format, algorithm, keyData, keySize, usages, extractable)

Source from the content-addressed store, hash-verified

40// Test importKey with a given key format and other parameters. If
41// extrable is true, export the key and verify that it matches the input.
42function testFormat(format, algorithm, keyData, keySize, usages, extractable) {
43 [algorithm, algorithm.name].forEach((alg) => {
44 promise_test(function(test) {
45 return subtle.importKey(format, keyData[format], alg, extractable, usages).
46 then(function(key) {
47 assert_equals(key.constructor, CryptoKey, "Imported a CryptoKey object");
48 assert_goodCryptoKey(key, algorithm, extractable, usages, (format === 'pkcs8' || (format === 'jwk' && keyData[format].d)) ? 'private' : 'public');
49 if (!extractable) {
50 return;
51 }
52
53 return subtle.exportKey(format, key).
54 then(function(result) {
55 if (format !== "jwk") {
56 assert_true(equalBuffers(keyData[format], result), "Round trip works");
57 } else {
58 assert_true(equalJwk(keyData[format], result), "Round trip works");
59 }
60 }, function(err) {
61 assert_unreached("Threw an unexpected error: " + err.toString());
62 });
63 }, function(err) {
64 assert_unreached("Threw an unexpected error: " + err.toString());
65 });
66 }, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData[format], alg, extractable, usages));
67 });
68}
69
70// Test importKey/exportKey "alg" behaviours (https://github.com/w3c/webcrypto/pull/401)
71// - alg is ignored for ECDH import

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