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