Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-opcua-chunkmanager

Package Overview
Dependencies
Maintainers
1
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-chunkmanager - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

10

package.json
{
"name": "node-opcua-chunkmanager",
"version": "0.2.3",
"version": "0.3.0",
"description": "pure nodejs OPCUA SDK - module -chunkmanager",

@@ -10,9 +10,9 @@ "main": "index.js",

"dependencies": {
"node-opcua-assert": "^0.2.0",
"node-opcua-binary-stream": "^0.2.3",
"node-opcua-buffer-utils": "^0.2.0",
"node-opcua-assert": "^0.3.0",
"node-opcua-binary-stream": "^0.3.0",
"node-opcua-buffer-utils": "^0.3.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"node-opcua-debug": "^0.2.2",
"node-opcua-debug": "^0.3.0",
"should": "13.2.1"

@@ -19,0 +19,0 @@ },

@@ -6,16 +6,16 @@ "use strict";

var util = require("util");
var EventEmitter = require("events").EventEmitter;
var assert = require("node-opcua-assert");
var _ = require("underscore");
const util = require("util");
const EventEmitter = require("events").EventEmitter;
const assert = require("node-opcua-assert").assert;
const _ = require("underscore");
var readMessageHeader = require("./read_message_header").readMessageHeader;
var BinaryStream = require("node-opcua-binary-stream").BinaryStream;
const readMessageHeader = require("./read_message_header").readMessageHeader;
const BinaryStream = require("node-opcua-binary-stream").BinaryStream;
var buffer_utils = require("node-opcua-buffer-utils");
var createFastUninitializedBuffer = buffer_utils.createFastUninitializedBuffer;
const buffer_utils = require("node-opcua-buffer-utils");
const createFastUninitializedBuffer = buffer_utils.createFastUninitializedBuffer;
var do_debug = false;
const do_debug = false;

@@ -25,3 +25,3 @@ function verify_message_chunk(message_chunk) {

assert(message_chunk instanceof Buffer);
var header = readMessageHeader(new BinaryStream(message_chunk));
const header = readMessageHeader(new BinaryStream(message_chunk));
if (message_chunk.length !== header.length) {

@@ -68,3 +68,3 @@ throw new Error(" chunk length = " + message_chunk.length + " message length " + header.length);

var nbUnwanted = 0;
let nbUnwanted = 0;
/* istanbul ignore next */

@@ -82,3 +82,3 @@ if (do_debug) {

var ChunkManager_options = [
const ChunkManager_options = [
"chunkSize",

@@ -188,7 +188,7 @@ "headerSize",

var signature_start = this.dataEnd;
var section_to_sign = chunk.slice(0, signature_start);
const signature_start = this.dataEnd;
const section_to_sign = chunk.slice(0, signature_start);
var signature = this.compute_signature(section_to_sign);
const signature = this.compute_signature(section_to_sign);
assert(signature.length === this.signatureLength);

@@ -210,11 +210,11 @@

var startEncryptionPos = this.headerSize;
var endEncryptionPos = this.dataEnd + this.signatureLength;
const startEncryptionPos = this.headerSize;
const endEncryptionPos = this.dataEnd + this.signatureLength;
var area_to_encrypt = chunk.slice(startEncryptionPos, endEncryptionPos);
const area_to_encrypt = chunk.slice(startEncryptionPos, endEncryptionPos);
assert(area_to_encrypt.length % this.plainBlockSize === 0); // padding should have been applied
var nbBlock = area_to_encrypt.length / this.plainBlockSize;
const nbBlock = area_to_encrypt.length / this.plainBlockSize;
var encrypted_buf = this.encrypt_buffer(area_to_encrypt);
const encrypted_buf = this.encrypt_buffer(area_to_encrypt);
assert(encrypted_buf.length % this.cipherBlockSize === 0);

@@ -232,3 +232,3 @@ assert(encrypted_buf.length === nbBlock * this.cipherBlockSize);

var expected_length = this.pending_chunk.length;
const expected_length = this.pending_chunk.length;

@@ -271,4 +271,4 @@ if (this.headerSize > 0) {

var l = length;
var input_cursor = 0;
let l = length;
let input_cursor = 0;

@@ -283,5 +283,5 @@ while (l > 0) {

// space left in current chunk
var space_left = this.maxBodySize - this.cursor;
const space_left = this.maxBodySize - this.cursor;
var nb_to_write = Math.min(length - input_cursor, space_left);
const nb_to_write = Math.min(length - input_cursor, space_left);

@@ -308,4 +308,4 @@ this.chunk = this.chunk || createFastUninitializedBuffer(this.chunkSize);

var nbPaddingByte = nbPaddingByteTotal % 256;
var extraNbPaddingByte = Math.floor( nbPaddingByteTotal / 256);
const nbPaddingByte = nbPaddingByteTotal % 256;
const extraNbPaddingByte = Math.floor( nbPaddingByteTotal / 256);

@@ -318,3 +318,3 @@ assert(extraNbPaddingByte === 0 || this.plainBlockSize>256 ,"extraNbPaddingByte only requested when key size > 2048" );

for (var i = 0; i < nbPaddingByteTotal; i++) {
for (let i = 0; i < nbPaddingByteTotal; i++) {
this.chunk.writeUInt8(nbPaddingByte, this.cursor + this.dataOffset + i);

@@ -334,3 +334,3 @@ }

var extra_encryption_bytes = 0;
let extra_encryption_bytes = 0;
// add padding bytes if needed

@@ -344,3 +344,3 @@ if (this.plainBlockSize > 0) {

// +---------------+---------------+-------------+---------+--------------+------------+
var curLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
let curLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
if (this.plainBlockSize>256) {

@@ -352,10 +352,10 @@ curLength +=2; // account for extraPadding Byte Number;

// let's calculate the required number of padding bytes
var n = (curLength % this.plainBlockSize);
var nbPaddingByteTotal = (this.plainBlockSize - n) % this.plainBlockSize;
const n = (curLength % this.plainBlockSize);
const nbPaddingByteTotal = (this.plainBlockSize - n) % this.plainBlockSize;
this._write_padding_bytes(nbPaddingByteTotal);
var adjustedLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
const adjustedLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
assert(adjustedLength % this.plainBlockSize === 0);
var nbBlock = adjustedLength / this.plainBlockSize;
const nbBlock = adjustedLength / this.plainBlockSize;
extra_encryption_bytes = nbBlock * (this.cipherBlockSize - this.plainBlockSize );

@@ -367,3 +367,3 @@ }

// calculate the expected length of the chunk, once encrypted if encryption apply
var expected_length = this.dataEnd + this.signatureLength + extra_encryption_bytes;
const expected_length = this.dataEnd + this.signatureLength + extra_encryption_bytes;

@@ -370,0 +370,0 @@ this.pending_chunk = this.chunk.slice(0, expected_length);

"use strict";
var assert = require("node-opcua-assert");
var BinaryStream = require("node-opcua-binary-stream").BinaryStream;
const assert = require("node-opcua-assert").assert;
const BinaryStream = require("node-opcua-binary-stream").BinaryStream;
function readMessageHeader(stream) {

@@ -8,9 +8,9 @@

var msgType = String.fromCharCode(stream.readUInt8()) +
const msgType = String.fromCharCode(stream.readUInt8()) +
String.fromCharCode(stream.readUInt8()) +
String.fromCharCode(stream.readUInt8());
var isFinal = String.fromCharCode(stream.readUInt8());
const isFinal = String.fromCharCode(stream.readUInt8());
var length = stream.readUInt32();
const length = stream.readUInt32();

@@ -17,0 +17,0 @@ return {msgType: msgType, isFinal: isFinal, length: length};

"use strict";
var should = require("should");
var ChunkManager = require("..").ChunkManager;
const should = require("should");
const ChunkManager = require("..").ChunkManager;
var util = require("util");
var assert = require("node-opcua-assert");
var _ = require("underscore");
const util = require("util");
const assert = require("node-opcua-assert").assert;
const _ = require("underscore");
var hexDump = require("node-opcua-debug").hexDump;
const hexDump = require("node-opcua-debug").hexDump;
function make_packet(packet_length) {
var buf = new Buffer(packet_length);
const buf = new Buffer(packet_length);
buf.length.should.eql(packet_length);
for (var i = 0; i < buf.length; i++) {
for (let i = 0; i < buf.length; i++) {
buf.writeUInt8(i, i % 256);

@@ -20,8 +20,8 @@ }

var do_debug = false;
const do_debug = false;
function compute_fake_signature(section_to_sign) {
var signature = new Buffer(4);
for (var i = 0; i < signature.length; i++) {
const signature = new Buffer(4);
for (let i = 0; i < signature.length; i++) {
signature.writeUInt8(0xCC, i);

@@ -33,3 +33,3 @@ }

function write_fake_header(block, isLast, total_length) {
for (var i = 0; i < this.headerSize; i++) {
for (let i = 0; i < this.headerSize; i++) {
block.writeUInt8(0xAA, i);

@@ -40,3 +40,3 @@ }

function write_fake_sequence_header(block) {
for (var i = 0; i < this.sequenceHeaderSize; i++) {
for (let i = 0; i < this.sequenceHeaderSize; i++) {
block.writeUInt8(0xBB, i);

@@ -51,3 +51,3 @@ }

var encrypted_block = new Buffer(block.length + 2);
const encrypted_block = new Buffer(block.length + 2);
encrypted_block.writeUInt8(0xDE, 0);

@@ -65,10 +65,10 @@ block.copy(encrypted_block, 1, 0, block.length);

var nbBlocks = Math.ceil(buffer.length / (this.plainBlockSize));
const nbBlocks = Math.ceil(buffer.length / (this.plainBlockSize));
var outputBuffer = new Buffer(nbBlocks * this.cipherBlockSize);
const outputBuffer = new Buffer(nbBlocks * this.cipherBlockSize);
for (var i = 0; i < nbBlocks; i++) {
var currentBlock = buffer.slice(this.plainBlockSize * i, this.plainBlockSize * (i + 1));
for (let i = 0; i < nbBlocks; i++) {
const currentBlock = buffer.slice(this.plainBlockSize * i, this.plainBlockSize * (i + 1));
var encrypted_chunk = this.encrypt_block(currentBlock);
const encrypted_chunk = this.encrypt_block(currentBlock);

@@ -95,3 +95,3 @@ assert(encrypted_chunk.length === this.cipherBlockSize);

var chunkManager = new ChunkManager({
const chunkManager = new ChunkManager({
chunkSize: 48,

@@ -104,3 +104,3 @@ sequenceHeaderSize: 0

var chunk_counter = 0;
let chunk_counter = 0;
chunkManager.on("chunk", function (chunk) {

@@ -122,4 +122,4 @@

// create a large buffer ( 2.3 time bigger than chunksize)
var n = 48 * 2 + 12;
var buf = make_packet(n);
const n = 48 * 2 + 12;
const buf = make_packet(n);

@@ -136,3 +136,3 @@ // write this single buffer

var chunkManager = new ChunkManager({
const chunkManager = new ChunkManager({
chunkSize: 48,

@@ -144,3 +144,3 @@ sequenceHeaderSize: 0

var chunk_counter = 0;
let chunk_counter = 0;
chunkManager.on("chunk", function (chunk) {

@@ -159,5 +159,5 @@ // console.log(" chunk "+ chunk_counter + " " + chunk.toString("hex"));

// feed chunk-manager on byte at a time
var n = 48 * 2 + 12;
var buf = new Buffer(1);
for (var i = 0; i < n; i += 1) {
const n = 48 * 2 + 12;
const buf = new Buffer(1);
for (let i = 0; i < n; i += 1) {
buf.writeInt8(i, 0);

@@ -176,3 +176,3 @@ chunkManager.write(buf, 1);

var expected_chunks = null;
let expected_chunks = null;
if (typeof expected_chunk_lengths[0] === "string") {

@@ -184,3 +184,3 @@ expected_chunks = expected_chunk_lengths.map(make_hex_block);

}
var chunk_counter = 0;
let chunk_counter = 0;

@@ -216,3 +216,3 @@ chunkManager.on("chunk", function (chunk, is_last) {

var buf = make_packet(packet_length);
const buf = make_packet(packet_length);

@@ -227,3 +227,3 @@ chunkManager.write(buf);

var chunkManager;
let chunkManager;

@@ -261,3 +261,3 @@ beforeEach(function () {

var chunkManager;
let chunkManager;

@@ -301,3 +301,3 @@ beforeEach(function () {

var chunkManager;
let chunkManager;

@@ -426,3 +426,3 @@ beforeEach(function () {

var chunkManager;
let chunkManager;

@@ -457,3 +457,3 @@ beforeEach(function () {

// +-------+---------------+---------------+-------------+-------+
var expected = [
const expected = [
//0102030405060708 0910111213141516 17 1819202122 23242526

@@ -469,3 +469,3 @@ //0102030405060708 0102030405060708 01 0102030405 01020304

it("should transform a 2 byte message into a single chunk", function (done) {
var expected = [
const expected = [
"aaaaaaaaaaaaaaaaDEbbbbbbbbbbbbDFDEbbbb00010303DFDE0303ccccccccDF"

@@ -476,3 +476,3 @@ ];

it("should transform a 3 byte message into a single chunk", function (done) {
var expected = [
const expected = [
"aaaaaaaaaaaaaaaaDEbbbbbbbbbbbbDFDEbbbb00010202DFDE0202ccccccccDF"

@@ -483,3 +483,3 @@ ];

it("should transform a 4 byte message into a single chunk", function (done) {
var expected = [
const expected = [
"aaaaaaaaaaaaaaaaDEbbbbbbbbbbbbDFDEbbbb00010203DFDE0101ccccccccDF"

@@ -490,3 +490,3 @@ ];

it("should transform a 5 byte message into a single chunk", function (done) {
var expected = [
const expected = [
"aaaaaaaaaaaaaaaaDEbbbbbbbbbbbbDFDEbbbb00010203DFDE0400ccccccccDF"

@@ -497,3 +497,3 @@ ];

it("should transform a 6 byte message into a single chunk", function (done) {
var expected = [
const expected = [
"aaaaaaaaaaaaaaaaDEbbbbbbbbbbbbDFDEbbbb00010203DFDE040505050505DFDE0505ccccccccDF"

@@ -504,3 +504,3 @@ ];

it("should transform a 29 byte message into a single chunk", function (done) {
var expected = [
const expected = [
"aaaaaaaaaaaaaaaa" + "DEbbbbbbbbbbbbDF" + "DEbbbb00010203DF" + "DE040506070809DF" + "DE0A0B0C0D0E0FDF" +

@@ -512,3 +512,3 @@ "DE101112131415DF" + "DE161718191A1BDF" + "DE1C00ccccccccDF"];

it("should transform a 30 byte message into a single chunk", function (done) {
var expected = [
const expected = [
"aaaaaaaaaaaaaaaa" + "DEbbbbbbbbbbbbDF" + "DEbbbb00010203DF" + "DE040506070809DF" + "DE0A0B0C0D0E0FDF" +

@@ -515,0 +515,0 @@ "DE101112131415DF" + "DE161718191A1BDF" + "DE1C00ccccccccDF",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc