mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 18:42:32 +00:00
Read large payload
This commit is contained in:
parent
a5ec8efd28
commit
4b2091be9f
@ -35,8 +35,17 @@ export function decryptStream(handshake: Handshake): ReturnEncryptionWrapper {
|
|||||||
return async function * (source) {
|
return async function * (source) {
|
||||||
for await (const chunk of source) {
|
for await (const chunk of source) {
|
||||||
const chunkBuffer = Buffer.from(chunk);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,8 @@ describe("Noise", () => {
|
|||||||
const largePlaintext = getRandomBuffer(100000);
|
const largePlaintext = getRandomBuffer(100000);
|
||||||
wrappedOutbound.writeLP(largePlaintext);
|
wrappedOutbound.writeLP(largePlaintext);
|
||||||
const response = await wrappedInbound.readLP();
|
const response = await wrappedInbound.readLP();
|
||||||
expect(response.equals(largePlaintext)).to.be.true;
|
|
||||||
|
expect(response.length).equals(largePlaintext.length);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
assert(false, e.message);
|
assert(false, e.message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user