(setup, expected)
| 22 | } |
| 23 | |
| 24 | function testGenerateKeysChangesKeys(setup, expected) { |
| 25 | const dh = crypto.createDiffieHellman(size); |
| 26 | setup(dh); |
| 27 | const firstPublicKey = unlessInvalidState(() => dh.getPublicKey()); |
| 28 | const firstPrivateKey = unlessInvalidState(() => dh.getPrivateKey()); |
| 29 | dh.generateKeys(); |
| 30 | const secondPublicKey = dh.getPublicKey(); |
| 31 | const secondPrivateKey = dh.getPrivateKey(); |
| 32 | function changed(shouldChange, first, second) { |
| 33 | if (shouldChange) { |
| 34 | assert.notDeepStrictEqual(first, second); |
| 35 | } else { |
| 36 | assert.deepStrictEqual(first, second); |
| 37 | } |
| 38 | } |
| 39 | changed(expected.includes('public'), firstPublicKey, secondPublicKey); |
| 40 | changed(expected.includes('private'), firstPrivateKey, secondPrivateKey); |
| 41 | } |
| 42 | |
| 43 | // Both the private and the public key are missing: generateKeys() generates both. |
| 44 | testGenerateKeysChangesKeys(() => { |
no test coverage detected
searching dependent graphs…