({ ciphertext,
algorithm,
plaintext,
hash,
publicKeyBuffer,
privateKeyBuffer })
| 30 | } |
| 31 | |
| 32 | async function testDecryption({ ciphertext, |
| 33 | algorithm, |
| 34 | plaintext, |
| 35 | hash, |
| 36 | publicKeyBuffer, |
| 37 | privateKeyBuffer }) { |
| 38 | if (ciphertext === undefined) |
| 39 | return; |
| 40 | |
| 41 | const { |
| 42 | privateKey |
| 43 | } = await importVectorKey( |
| 44 | publicKeyBuffer, |
| 45 | privateKeyBuffer, |
| 46 | algorithm.name, |
| 47 | hash, |
| 48 | ['encrypt'], |
| 49 | ['decrypt']); |
| 50 | |
| 51 | const encodedPlaintext = Buffer.from(plaintext).toString('hex'); |
| 52 | const result = await subtle.decrypt(algorithm, privateKey, ciphertext); |
| 53 | |
| 54 | assert.strictEqual( |
| 55 | Buffer.from(result).toString('hex'), |
| 56 | encodedPlaintext); |
| 57 | |
| 58 | const ciphercopy = Buffer.from(ciphertext); |
| 59 | |
| 60 | // Modifying the ciphercopy after calling decrypt should just work |
| 61 | const result2 = await subtle.decrypt(algorithm, privateKey, ciphercopy); |
| 62 | ciphercopy[0] = 255 - ciphercopy[0]; |
| 63 | |
| 64 | assert.strictEqual( |
| 65 | Buffer.from(result2).toString('hex'), |
| 66 | encodedPlaintext); |
| 67 | } |
| 68 | |
| 69 | async function testEncryption( |
| 70 | { |
no test coverage detected
searching dependent graphs…