fix buffer length bug

This commit is contained in:
AJ ONeal 2018-11-21 19:04:49 -07:00
parent 71960b48ce
commit f804728831
2 changed files with 5 additions and 2 deletions

View File

@ -71,5 +71,6 @@ function write(asn1) {
ws = ws.slice(1); ws = ws.slice(1);
}); });
} }
console.log(asn1); console.log(JSON.stringify(asn1, null, 2));
//console.log(asn1);
write(asn1); write(asn1);

View File

@ -29,6 +29,7 @@ ASN1.parse = function parseAsn1(buf, depth) {
// this is a primitive value type // this is a primitive value type
if (-1 !== VTYPES.indexOf(asn1.type)) { if (-1 !== VTYPES.indexOf(asn1.type)) {
//console.log('t', asn1.type);
asn1.value = buf.slice(index, index + asn1.length); asn1.value = buf.slice(index, index + asn1.length);
return asn1; return asn1;
} }
@ -36,8 +37,9 @@ ASN1.parse = function parseAsn1(buf, depth) {
asn1.children = []; asn1.children = [];
while (iters < 100 && index < buf.byteLength) { while (iters < 100 && index < buf.byteLength) {
iters += 1; iters += 1;
child = ASN1.parse(buf.slice(index), (depth || 0) + 1); child = ASN1.parse(buf.slice(index, index + asn1.length), (depth || 0) + 1);
index += (2 + child.lengthSize + child.length); index += (2 + child.lengthSize + child.length);
//console.log('buflen', buf.byteLength, 'index', index);
asn1.children.push(child); asn1.children.push(child);
} }
if (iters >= 100) { throw new Error(ELOOP); } if (iters >= 100) { throw new Error(ELOOP); }