Comparing version 0.1.11 to 0.2.0
@@ -186,24 +186,11 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved. | ||
var b = this.peek(); | ||
var b = this.readString(tag, true); | ||
if (b === null) | ||
return null; | ||
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 (this.length > this._size - o) | ||
return null; | ||
this._offset = o; | ||
var values = []; | ||
var value = 0; | ||
for (var i = 0; i < this.length; i++) { | ||
var byte = this._buf[this._offset++] & 0xff; | ||
for (var i = 0; i < b.length; i++) { | ||
var byte = b[i] & 0xff; | ||
@@ -249,7 +236,6 @@ value <<= 7; | ||
var fb = this._buf[this._offset++]; | ||
var fb = this._buf[this._offset]; | ||
var value = 0; | ||
value = fb & 0x7F; | ||
for (var i = 1; i < this.length; i++) { | ||
for (var i = 0; i < this.length; i++) { | ||
value <<= 8; | ||
@@ -259,6 +245,6 @@ value |= (this._buf[this._offset++] & 0xff); | ||
if ((fb & 0x80) == 0x80) | ||
value = -value; | ||
if ((fb & 0x80) == 0x80 && i !== 4) | ||
value -= (1 << (i * 8)); | ||
return value; | ||
return value >> 0; | ||
}; | ||
@@ -265,0 +251,0 @@ |
@@ -81,3 +81,3 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved. | ||
while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000)) && | ||
while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000 >> 0)) && | ||
(sz > 1)) { | ||
@@ -96,3 +96,3 @@ sz--; | ||
while (sz-- > 0) { | ||
this._buf[this._offset++] = ((i & 0xff000000) >> 24); | ||
this._buf[this._offset++] = ((i & 0xff000000) >>> 24); | ||
i <<= 8; | ||
@@ -99,0 +99,0 @@ } |
@@ -9,3 +9,3 @@ { | ||
"description": "Contains parsers and serializers for ASN.1 (currently BER only)", | ||
"version": "0.1.11", | ||
"version": "0.2.0", | ||
"repository": { | ||
@@ -16,13 +16,9 @@ "type": "git", | ||
"main": "lib/index.js", | ||
"engines": { | ||
"node": ">=0.4.9" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"tap": "0.1.4" | ||
"tap": "0.4.8" | ||
}, | ||
"scripts": { | ||
"pretest": "which gjslint; if [[ \"$?\" = 0 ]] ; then gjslint --nojsdoc -r lib -r tst; else echo \"Missing gjslint. Skipping lint\"; fi", | ||
"test": "./node_modules/.bin/tap ./tst" | ||
} | ||
} |
@@ -72,2 +72,38 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved. | ||
test('read 1 byte negative int', function(t) { | ||
var reader = new BerReader(new Buffer([0x02, 0x01, 0xdc])); | ||
t.ok(reader); | ||
t.equal(reader.readInt(), -36, 'wrong value'); | ||
t.equal(reader.length, 0x01, 'wrong length'); | ||
t.end(); | ||
}); | ||
test('read 2 byte negative int', function(t) { | ||
var reader = new BerReader(new Buffer([0x02, 0x02, 0xc0, 0x4e])); | ||
t.ok(reader); | ||
t.equal(reader.readInt(), -16306, 'wrong value'); | ||
t.equal(reader.length, 0x02, 'wrong length'); | ||
t.end(); | ||
}); | ||
test('read 3 byte negative int', function(t) { | ||
var reader = new BerReader(new Buffer([0x02, 0x03, 0xff, 0x00, 0x19])); | ||
t.ok(reader); | ||
t.equal(reader.readInt(), -65511, 'wrong value'); | ||
t.equal(reader.length, 0x03, 'wrong length'); | ||
t.end(); | ||
}); | ||
test('read 4 byte negative int', function(t) { | ||
var reader = new BerReader(new Buffer([0x02, 0x04, 0x91, 0x7c, 0x22, 0x1f])); | ||
t.ok(reader); | ||
t.equal(reader.readInt(), -1854135777, 'wrong value'); | ||
t.equal(reader.length, 0x04, 'wrong length'); | ||
t.end(); | ||
}); | ||
test('read boolean true', function(t) { | ||
@@ -74,0 +110,0 @@ var reader = new BerReader(new Buffer([0x01, 0x01, 0xff])); |
@@ -108,2 +108,76 @@ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved. | ||
test('write 1 byte negative int', function(t) { | ||
var writer = new BerWriter(); | ||
writer.writeInt(-128); | ||
var ber = writer.buffer; | ||
t.ok(ber); | ||
t.equal(ber.length, 3, 'Wrong length for an int'); | ||
t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); | ||
t.equal(ber[1], 0x01, 'length wrong'); | ||
t.equal(ber[2], 0x80, 'value wrong (byte 1)'); | ||
t.end(); | ||
}); | ||
test('write 2 byte negative int', function(t) { | ||
var writer = new BerWriter(); | ||
writer.writeInt(-22400); | ||
var ber = writer.buffer; | ||
t.ok(ber); | ||
t.equal(ber.length, 4, 'Wrong length for an int'); | ||
t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); | ||
t.equal(ber[1], 0x02, 'length wrong'); | ||
t.equal(ber[2], 0xa8, 'value wrong (byte 1)'); | ||
t.equal(ber[3], 0x80, 'value wrong (byte 2)'); | ||
t.end(); | ||
}); | ||
test('write 3 byte negative int', function(t) { | ||
var writer = new BerWriter(); | ||
writer.writeInt(-481653); | ||
var ber = writer.buffer; | ||
t.ok(ber); | ||
t.equal(ber.length, 5, 'Wrong length for an int'); | ||
t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); | ||
t.equal(ber[1], 0x03, 'length wrong'); | ||
t.equal(ber[2], 0xf8, 'value wrong (byte 1)'); | ||
t.equal(ber[3], 0xa6, 'value wrong (byte 2)'); | ||
t.equal(ber[4], 0x8b, 'value wrong (byte 3)'); | ||
t.end(); | ||
}); | ||
test('write 4 byte negative int', function(t) { | ||
var writer = new BerWriter(); | ||
writer.writeInt(-1522904131); | ||
var ber = writer.buffer; | ||
t.ok(ber); | ||
t.equal(ber.length, 6, 'Wrong length for an int'); | ||
t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); | ||
t.equal(ber[1], 0x04, 'length wrong'); | ||
t.equal(ber[2], 0xa5, 'value wrong (byte 1)'); | ||
t.equal(ber[3], 0x3a, 'value wrong (byte 2)'); | ||
t.equal(ber[4], 0x53, 'value wrong (byte 3)'); | ||
t.equal(ber[5], 0xbd, 'value wrong (byte 4)'); | ||
t.end(); | ||
}); | ||
test('write boolean', function(t) { | ||
@@ -110,0 +184,0 @@ var writer = new BerWriter(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32749
13
938