mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 08:22:35 +00:00
Merge remote-tracking branch 'remotes/origin/master' into feature/ik-handshake
This commit is contained in:
commit
d050db41c7
@ -11,7 +11,7 @@ const maxPlaintextLength = 65519;
|
||||
export function encryptStream(handshake: Handshake): ReturnEncryptionWrapper {
|
||||
return async function * (source) {
|
||||
for await (const chunk of source) {
|
||||
const chunkBuffer = Buffer.from(chunk);
|
||||
const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length);
|
||||
|
||||
for (let i = 0; i < chunkBuffer.length; i += maxPlaintextLength) {
|
||||
let end = i + maxPlaintextLength;
|
||||
@ -31,7 +31,7 @@ export function encryptStream(handshake: Handshake): ReturnEncryptionWrapper {
|
||||
export function decryptStream(handshake: Handshake): ReturnEncryptionWrapper {
|
||||
return async function * (source) {
|
||||
for await (const chunk of source) {
|
||||
const chunkBuffer = Buffer.from(chunk);
|
||||
const chunkBuffer = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.length);
|
||||
|
||||
for (let i = 0; i < chunkBuffer.length; i += maxPlaintextLength) {
|
||||
let end = i + maxPlaintextLength;
|
||||
|
@ -4,6 +4,7 @@ import DuplexPair from 'it-pair/duplex';
|
||||
import { Noise } from "../src";
|
||||
import {createPeerIdsFromFixtures} from "./fixtures/peer";
|
||||
import Wrap from "it-pb-rpc";
|
||||
import { random } from "bcrypto";
|
||||
import {Handshake} from "../src/handshake";
|
||||
import {
|
||||
createHandshakePayload,
|
||||
@ -14,7 +15,7 @@ import {
|
||||
import { decodeMessageBuffer, encodeMessageBuffer } from "../src/encoder";
|
||||
import {XXHandshake} from "../src/handshakes/xx";
|
||||
import {Buffer} from "buffer";
|
||||
import {getKeyPairFromPeerId, getRandomBuffer} from "./utils";
|
||||
import {getKeyPairFromPeerId} from "./utils";
|
||||
|
||||
describe("Noise", () => {
|
||||
let remotePeer, localPeer;
|
||||
@ -113,7 +114,7 @@ describe("Noise", () => {
|
||||
const wrappedInbound = Wrap(inbound.conn);
|
||||
const wrappedOutbound = Wrap(outbound.conn);
|
||||
|
||||
const largePlaintext = getRandomBuffer(100000);
|
||||
const largePlaintext = random.randomBytes(100000);
|
||||
wrappedOutbound.writeLP(largePlaintext);
|
||||
const response = await wrappedInbound.readLP();
|
||||
|
||||
|
@ -12,15 +12,3 @@ export function getKeyPairFromPeerId(peerId: PeerId): KeyPair {
|
||||
publicKey: peerId.marshalPubKey(),
|
||||
}
|
||||
}
|
||||
|
||||
export function getRandomBuffer(size: number) : bytes {
|
||||
size = Math.max(1, size<<0);
|
||||
|
||||
const buf = Buffer.alloc(size);
|
||||
let i = 0;
|
||||
for (; i < size; ++i) {
|
||||
buf[i] = (Math.random() * 0xFF) << 0;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user