(format, algorithm, keyData, keySize, usages, extractable)
| 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. |
| 42 | function 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 |
no test coverage detected