Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _feed_messageChunk(chunk: Buffer) {
assert(chunk);
const messageHeader = readMessageHeader(new BinaryStream(chunk));
/**
* notify the observers that new message chunk has been received
* @event chunk
* @param messageChunk the raw message chunk
*/
this.emit("chunk", chunk);
if (messageHeader.isFinal === "F") {
// last message
this._append(chunk);
if (this._hasReceivedError) {
return false;
}
const fullMessageBody: Buffer = this.blocks.length === 1 ? this.blocks[0] : Buffer.concat(this.blocks);
private _handle_ACK_response(messageChunk: Buffer, callback: ErrorCallback) {
const _stream = new BinaryStream(messageChunk);
const messageHeader = readMessageHeader(_stream);
let err;
/* istanbul ignore next */
if (messageHeader.isFinal !== "F") {
err = new Error(" invalid ACK message");
return callback(err);
}
let responseClass;
let response;
if (messageHeader.msgType === "ERR") {
responseClass = TCPErrorMessage;
_stream.rewind();
response = decodeMessage(_stream, responseClass) as TCPErrorMessage;
err = new Error("ACK: ERR received " + response.statusCode.toString() + " : " + response.reason);
ClientSecureChannelLayer.prototype._on_receive_message_chunk = function (message_chunk) {
const self = this;
/* istanbul ignore next */
if (doDebug) {
const _stream = new BinaryStream(message_chunk);
const messageHeader = readMessageHeader(_stream);
debugLog("CLIENT RECEIVED " + (JSON.stringify(messageHeader) + "").yellow);
debugLog("\n" + hexDump(message_chunk).blue);
debugLog(messageHeaderToString(message_chunk));
}
self.messageBuilder.feed(message_chunk);
};
private _on_receive_message_chunk(messageChunk: Buffer) {
/* istanbul ignore next */
if (doDebug1) {
const _stream = new BinaryStream(messageChunk);
const messageHeader = readMessageHeader(_stream);
debugLog("CLIENT RECEIVED " + chalk.yellow(JSON.stringify(messageHeader) + ""));
debugLog("\n" + hexDump(messageChunk));
debugLog(messageHeaderToString(messageChunk));
}
this.messageBuilder.feed(messageChunk);
}
protected _read_headers(binaryStream: BinaryStream): boolean {
this.messageHeader = readMessageHeader(binaryStream);
assert(binaryStream.length === 8, "expecting message header to be 8 bytes");
this.channelId = binaryStream.readUInt32();
assert(binaryStream.length === 12);
// verifying secure ChannelId
if (this._expectedChannelId && this.channelId !== this._expectedChannelId) {
return this._report_error("Invalid secure channel Id");
}
return true;
}
function readRawMessageHeader(data) {
const messageHeader = readMessageHeader(new BinaryStream(data));
return {
length: messageHeader.length,
messageHeader: messageHeader
};
}
exports.readRawMessageHeader = readRawMessageHeader;
export function messageHeaderToString(messageChunk: Buffer): string {
const stream = new BinaryStream(messageChunk);
const messageHeader = readMessageHeader(stream);
if (messageHeader.msgType === "ERR" || messageHeader.msgType === "HEL") {
return messageHeader.msgType + " " + messageHeader.isFinal + " length = " + messageHeader.length;
}
const securityHeader = chooseSecurityHeader(messageHeader.msgType);
const sequenceHeader = new SequenceHeader();
assert(stream.length === 8);
const channelId = stream.readUInt32();
securityHeader.decode(stream);
sequenceHeader.decode(stream);
const slice = messageChunk.slice(0, stream.length);
return messageHeader.msgType + " " +