Read large payload

This commit is contained in:
Belma Gutlic 2019-12-24 20:36:16 +01:00
parent a5ec8efd28
commit 4b2091be9f
2 changed files with 13 additions and 3 deletions

View File

@ -35,8 +35,17 @@ export function decryptStream(handshake: Handshake): ReturnEncryptionWrapper {
return async function * (source) {
for await (const chunk of source) {
const chunkBuffer = Buffer.from(chunk);
const decrypted = await handshake.decrypt(chunkBuffer, handshake.session);
yield decrypted
for (let i = 0; i < chunkBuffer.length; i += maxPlaintextLength) {
let end = i + maxPlaintextLength;
if (end > chunkBuffer.length) {
end = chunkBuffer.length;
}
const chunk = chunkBuffer.slice(i, end);
const decrypted = await handshake.decrypt(chunk, handshake.session);
yield decrypted;
}
}
}
}

View File

@ -116,7 +116,8 @@ describe("Noise", () => {
const largePlaintext = getRandomBuffer(100000);
wrappedOutbound.writeLP(largePlaintext);
const response = await wrappedInbound.readLP();
expect(response.equals(largePlaintext)).to.be.true;
expect(response.length).equals(largePlaintext.length);
} catch (e) {
console.error(e);
assert(false, e.message);