(key, expectedSize)
| 37 | // Asserts that the size of the given key (in chars or bytes) is within 10% of |
| 38 | // the expected size. |
| 39 | function assertApproximateSize(key, expectedSize) { |
| 40 | const u = typeof key === 'string' ? 'chars' : 'bytes'; |
| 41 | const min = Math.floor(0.9 * expectedSize); |
| 42 | const max = Math.ceil(1.1 * expectedSize); |
| 43 | assert(key.length >= min, |
| 44 | `Key (${key.length} ${u}) is shorter than expected (${min} ${u})`); |
| 45 | assert(key.length <= max, |
| 46 | `Key (${key.length} ${u}) is longer than expected (${max} ${u})`); |
| 47 | } |
| 48 | |
| 49 | // Tests that a key pair can be used for encryption / decryption. |
| 50 | function testEncryptDecrypt(publicKey, privateKey) { |
no test coverage detected