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.1.0-alpha.dc0cce4c to 0.1.1-0

LICENSE

51

package.json
{
"name": "node-opcua-chunkmanager",
"version": "0.1.0-alpha.dc0cce4c",
"description": "",
"main": "index.js",
"scripts": {
"test": "exit 0 "
},
"dependencies": {
"node-opcua-assert": "^0.1.0-alpha.dc0cce4c",
"node-opcua-binary-stream": "^0.1.0-alpha.dc0cce4c",
"node-opcua-buffer-utils": "^0.1.0-alpha.dc0cce4c",
"underscore": "^1.8.3"
},
"devDependencies": {
"node-opcua-debug": "^0.1.0-alpha.dc0cce4c",
"should": "^13.0.1"
},
"author": "etienne.rossignon@gadz.org",
"license": "MIT"
"name": "node-opcua-chunkmanager",
"version": "0.1.1-0",
"description": "pure nodejs OPCUA SDK - module -chunkmanager",
"main": "index.js",
"scripts": {
"test": "exit 0 "
},
"dependencies": {
"node-opcua-assert": "^0.1.1-0",
"node-opcua-binary-stream": "^0.1.1-0",
"node-opcua-buffer-utils": "^0.1.1-0",
"underscore": "^1.8.3"
},
"devDependencies": {
"node-opcua-debug": "^0.1.1-0",
"should": "13.2.0"
},
"author": "Etienne Rossignon",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/node-opcua/node-opcua.git"
},
"keywords": [
"OPCUA",
"opcua",
"m2m",
"iot",
"opc ua",
"internet of things"
],
"homepage": "http://node-opcua.github.io/"
}

@@ -51,4 +51,4 @@ "use strict";

// chunkSize = 8192
// plainBlockSize = 256
// cipherBlockSize = 256 - 11
// plainBlockSize = 256-11
// cipherBlockSize = 256
// headerSize = messageHeaderSize + securityHeaderSize

@@ -72,3 +72,3 @@ // maxBodySize = plainBlockSize*floor((chunkSize–headerSize–signatureLength-1)/cipherBlockSize)-sequenceHeaderSize;

if (properties.indexOf(key) < 0) {
console.log(" ERRROR".red, "invalid property :", key);
console.log(" ERROR".red, "invalid property :", key);
nbUnwanted++;

@@ -116,7 +116,7 @@ }

this.signatureLength = options.signatureLength || 0;
this.signatureLength = options.signatureLength || 0;
this.compute_signature = options.compute_signature;
this.plainBlockSize = options.plainBlockSize || 0; // 256-14;
this.cipherBlockSize = options.cipherBlockSize || 0; // 256;
this.plainBlockSize = options.plainBlockSize || 0; // 256-14;
this.cipherBlockSize = options.cipherBlockSize || 0; // 256;

@@ -145,2 +145,5 @@ if (this.cipherBlockSize === 0) {

if(this.plainBlockSize>256) {
this.maxBodySize -=1;
}
}

@@ -190,21 +193,3 @@ assert(this.maxBodySize > 0); // no space left to write data

/**
*
* @method _extra_encryption_bytes
* @return {Number} returns the number of extra bytes that will be added to the buffer
* during the encryption phase , or 0 if no encryption is envisaged.
* @private
*/
ChunkManager.prototype._extra_encryption_bytes = function () {
if (this.plainBlockSize > 0) {
var length_to_encrypt = this.dataEnd - this.headerSize + this.signatureLength;
assert(length_to_encrypt % this.plainBlockSize === 0); // padding should have been applied
var nbBlock = length_to_encrypt / this.plainBlockSize;
return nbBlock * (this.cipherBlockSize - this.plainBlockSize );
} else {
return 0;
}
};
ChunkManager.prototype._encrypt = function (chunk) {

@@ -262,30 +247,2 @@

ChunkManager.prototype._append_padding = function () {
if (this.plainBlockSize > 0) {
// write padding ( if encryption )
// +---------------+---------------+-------------+-------+
// |SequenceHeader | data | paddingByte | sign |
// +---------------+---------------+-------------+-------+
var curLength = this.sequenceHeaderSize + this.signatureLength + 1 + this.cursor;
var n = ( curLength % this.plainBlockSize);
var nbPaddingByte = (this.plainBlockSize - n) % this.plainBlockSize;
// write the padding byte
this.chunk.writeUInt8(nbPaddingByte, this.cursor + this.dataOffset);
this.cursor += 1;
for (var i = 0; i < nbPaddingByte; i++) {
this.chunk.writeUInt8(nbPaddingByte, this.cursor + this.dataOffset + i);
}
this.cursor += nbPaddingByte;
}
};
/**

@@ -331,17 +288,68 @@ * @method write

ChunkManager.prototype._write_padding_bytes = function(nbPaddingByteTotal) {
var nbPaddingByte = nbPaddingByteTotal % 256;
var extraNbPaddingByte = Math.floor( nbPaddingByteTotal / 256);
assert(extraNbPaddingByte === 0 || this.plainBlockSize>256 ,"extraNbPaddingByte only requested when key size > 2048" );
// write the padding byte
this.chunk.writeUInt8(nbPaddingByte, this.cursor + this.dataOffset);
this.cursor += 1;
for (var i = 0; i < nbPaddingByteTotal; i++) {
this.chunk.writeUInt8(nbPaddingByte, this.cursor + this.dataOffset + i);
}
this.cursor += nbPaddingByteTotal;
if (this.plainBlockSize>256) {
this.chunk.writeUInt8(extraNbPaddingByte, this.cursor + this.dataOffset);
this.cursor += 1;
}
};
ChunkManager.prototype._postprocess_current_chunk = function () {
var extra_encryption_bytes = 0;
// add padding bytes if needed
this._append_padding(this.chunk);
if (this.plainBlockSize > 0) {
// write padding ( if encryption )
// let's calculatee curLength = the length of the block to encrypt without padding yet
// +---------------+---------------+-------------+---------+--------------+------------+
// |SequenceHeader | data | paddingByte | padding | extraPadding | signature |
// +---------------+---------------+-------------+---------+--------------+------------+
var curLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
if (this.plainBlockSize>256) {
curLength +=2; // account for extraPadding Byte Number;
} else {
curLength +=1;
}
// let's calculate the required number of padding bytes
var n = (curLength % this.plainBlockSize);
var nbPaddingByteTotal = (this.plainBlockSize - n) % this.plainBlockSize;
this._write_padding_bytes(nbPaddingByteTotal);
var adjustedLength = this.sequenceHeaderSize + this.cursor + this.signatureLength;
assert(adjustedLength % this.plainBlockSize === 0);
var nbBlock = adjustedLength / this.plainBlockSize;
extra_encryption_bytes = nbBlock * (this.cipherBlockSize - this.plainBlockSize );
}
this.dataEnd = this.dataOffset + this.cursor;
// calculate the expected length of the chunk, once encrypted if encryption apply
var expected_length = this.dataEnd + this.signatureLength + this._extra_encryption_bytes();
var expected_length = this.dataEnd + this.signatureLength + extra_encryption_bytes;
this.pending_chunk = this.chunk.slice(0, expected_length);
// note : this.pending_chunk has the correct size but is not signed nor encrypted yet
// as we don't now what to write in the header yet
// note :
// - this.pending_chunk has the correct size but is not signed nor encrypted yet
// as we don't know what to write in the header yet
// - as a result,
this.cursor = 0;
};

@@ -348,0 +356,0 @@

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