(
{
ciphertext,
algorithm,
plaintext,
hash,
publicKeyBuffer,
privateKeyBuffer
},
modify = false)
| 67 | } |
| 68 | |
| 69 | async function testEncryption( |
| 70 | { |
| 71 | ciphertext, |
| 72 | algorithm, |
| 73 | plaintext, |
| 74 | hash, |
| 75 | publicKeyBuffer, |
| 76 | privateKeyBuffer |
| 77 | }, |
| 78 | modify = false) { |
| 79 | const { |
| 80 | publicKey, |
| 81 | privateKey |
| 82 | } = await importVectorKey( |
| 83 | publicKeyBuffer, |
| 84 | privateKeyBuffer, |
| 85 | algorithm.name, |
| 86 | hash, |
| 87 | ['encrypt'], |
| 88 | ['decrypt']); |
| 89 | |
| 90 | if (modify) |
| 91 | plaintext = Buffer.from(plaintext); // make a copy |
| 92 | |
| 93 | const encodedPlaintext = Buffer.from(plaintext).toString('hex'); |
| 94 | |
| 95 | const result = await subtle.encrypt(algorithm, publicKey, plaintext); |
| 96 | if (modify) |
| 97 | plaintext[0] = 255 - plaintext[0]; |
| 98 | |
| 99 | assert.strictEqual( |
| 100 | result.byteLength * 8, |
| 101 | privateKey.algorithm.modulusLength); |
| 102 | |
| 103 | const out = await subtle.decrypt(algorithm, privateKey, result); |
| 104 | |
| 105 | assert.strictEqual( |
| 106 | Buffer.from(out).toString('hex'), |
| 107 | encodedPlaintext); |
| 108 | } |
| 109 | |
| 110 | async function testEncryptionLongPlaintext({ algorithm, |
| 111 | plaintext, |
no test coverage detected
searching dependent graphs…