Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from UziTech/update-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech authored Jun 1, 2020
2 parents 3101569 + d0775aa commit dcd6806
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 1,283 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build
/coverage
/node_modules
*.log
/.nyc_output
/package-lock.json
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

7 changes: 1 addition & 6 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
*.log
/Makefile
/deps
/test
/tools
/.gitmodules
/.npmignore
/.nyc_output
/.eslintrc
/.travis.yml
/CONTRIBUTING.md
/build
/coverage
65 changes: 0 additions & 65 deletions Jenkinsfile

This file was deleted.

59 changes: 0 additions & 59 deletions Makefile

This file was deleted.

1 change: 0 additions & 1 deletion deps/jsstyle
Submodule jsstyle deleted from 52dc97
6 changes: 4 additions & 2 deletions lib/ber/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ module.exports = {
};

for (var t in types) {
if (types.hasOwnProperty(t))
if (Object.prototype.hasOwnProperty.call(types, t)) {
module.exports[t] = types[t];
}
}
for (var e in errors) {
if (errors.hasOwnProperty(e))
if (Object.prototype.hasOwnProperty.call(errors, e)) {
module.exports[e] = errors[e];
}
}
90 changes: 38 additions & 52 deletions lib/ber/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ var newInvalidAsn1Error = errors.newInvalidAsn1Error;
// --- API

function Reader(data) {
if (!data || !Buffer.isBuffer(data))
if (!data || !Buffer.isBuffer(data)) {
throw new TypeError('data must be a node Buffer');
}

this._buf = data;
this._size = data.length;
Expand Down Expand Up @@ -54,13 +55,11 @@ Object.defineProperty(Reader.prototype, 'buffer', {
* @return {Number} the next byte, null if not enough data.
*/
Reader.prototype.readByte = function (peek) {
if (this._size - this._offset < 1)
return null;
if (this._size - this._offset < 1) { return null; }

var b = this._buf[this._offset] & 0xff;

if (!peek)
this._offset += 1;
if (!peek) { this._offset += 1; }

return b;
};
Expand All @@ -83,32 +82,28 @@ Reader.prototype.peek = function () {
* @throws {InvalidAsn1Error} on bad ASN.1
*/
Reader.prototype.readLength = function (offset) {
if (offset === undefined)
offset = this._offset;
if (offset === undefined) { offset = this._offset; }

if (offset >= this._size)
return null;
if (offset >= this._size) { return null; }

var lenB = this._buf[offset++] & 0xff;
if (lenB === null)
return null;
if (lenB === null) { return null; }

if ((lenB & 0x80) === 0x80) {
lenB &= 0x7f;

if (lenB === 0)
if (lenB === 0) {
throw newInvalidAsn1Error('Indefinite length not supported');
}

if (lenB > 4)
throw newInvalidAsn1Error('encoding too long');
if (lenB > 4) { throw newInvalidAsn1Error('encoding too long'); }

if (this._size - offset < lenB)
return null;
if (this._size - offset < lenB) { return null; }

this._len = 0;
for (var i = 0; i < lenB; i++)
for (var i = 0; i < lenB; i++) {
this._len = (this._len << 8) + (this._buf[offset++] & 0xff);

}
} else {
// Wasn't a variable length
this._len = lenB;
Expand All @@ -127,15 +122,14 @@ Reader.prototype.readLength = function (offset) {
*/
Reader.prototype.readSequence = function (tag) {
var seq = this.peek();
if (seq === null)
return null;
if (tag !== undefined && tag !== seq)
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
if (seq === null) { return null; }
if (tag !== undefined && tag !== seq) {
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
': got 0x' + seq.toString(16));
}

var o = this.readLength(this._offset + 1); // stored in `length`
if (o === null)
return null;
if (o === null) { return null; }

this._offset = o;
return seq;
Expand All @@ -148,7 +142,7 @@ Reader.prototype.readInt = function () {


Reader.prototype.readBoolean = function () {
return (this._readTag(ASN1.Boolean) === 0 ? false : true);
return (this._readTag(ASN1.Boolean) !== 0);
};


Expand All @@ -158,29 +152,25 @@ Reader.prototype.readEnumeration = function () {


Reader.prototype.readString = function (tag, retbuf) {
if (!tag)
tag = ASN1.OctetString;
if (!tag) { tag = ASN1.OctetString; }

var b = this.peek();
if (b === null)
return null;
if (b === null) { return null; }

if (b !== tag)
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
if (b !== tag) {
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
': got 0x' + b.toString(16));
}

var o = this.readLength(this._offset + 1); // stored in `length`

if (o === null)
return null;
if (o === null) { return null; }

if (this.length > this._size - o)
return null;
if (this.length > this._size - o) { return null; }

this._offset = o;

if (this.length === 0)
return retbuf ? Buffer.alloc(0) : '';
if (this.length === 0) { return retbuf ? Buffer.alloc(0) : ''; }

var str = this._buf.slice(this._offset, this._offset + this.length);
this._offset += this.length;
Expand All @@ -189,12 +179,10 @@ Reader.prototype.readString = function (tag, retbuf) {
};

Reader.prototype.readOID = function (tag) {
if (!tag)
tag = ASN1.OID;
if (!tag) { tag = ASN1.OID; }

var b = this.readString(tag, true);
if (b === null)
return null;
if (b === null) { return null; }

var values = [];
var value = 0;
Expand Down Expand Up @@ -223,22 +211,21 @@ Reader.prototype._readTag = function (tag) {

var b = this.peek();

if (b === null)
return null;
if (b === null) { return null; }

if (b !== tag)
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
if (b !== tag) {
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
': got 0x' + b.toString(16));
}

var o = this.readLength(this._offset + 1); // stored in `length`
if (o === null)
return null;
if (o === null) { return null; }

if (this.length > 4)
if (this.length > 4) {
throw newInvalidAsn1Error('Integer too long: ' + this.length);
}

if (this.length > this._size - o)
return null;
if (this.length > this._size - o) { return null; }
this._offset = o;

var fb = this._buf[this._offset];
Expand All @@ -249,8 +236,7 @@ Reader.prototype._readTag = function (tag) {
value |= (this._buf[this._offset++] & 0xff);
}

if ((fb & 0x80) === 0x80 && i !== 4)
value -= (1 << (i * 8));
if ((fb & 0x80) === 0x80 && i !== 4) { value -= (1 << (i * 8)); }

return value >> 0;
};
Expand Down
Loading

0 comments on commit dcd6806

Please sign in to comment.