From f80472883152938a515a4ba1f538af2384a88ac6 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 21 Nov 2018 19:04:49 -0700 Subject: [PATCH] fix buffer length bug --- bin/rasha.js | 3 ++- lib/uasn1.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/rasha.js b/bin/rasha.js index f35e338..9485428 100755 --- a/bin/rasha.js +++ b/bin/rasha.js @@ -71,5 +71,6 @@ function write(asn1) { ws = ws.slice(1); }); } -console.log(asn1); +console.log(JSON.stringify(asn1, null, 2)); +//console.log(asn1); write(asn1); diff --git a/lib/uasn1.js b/lib/uasn1.js index f5ae5fc..1916a16 100644 --- a/lib/uasn1.js +++ b/lib/uasn1.js @@ -29,6 +29,7 @@ ASN1.parse = function parseAsn1(buf, depth) { // this is a primitive value type if (-1 !== VTYPES.indexOf(asn1.type)) { + //console.log('t', asn1.type); asn1.value = buf.slice(index, index + asn1.length); return asn1; } @@ -36,8 +37,9 @@ ASN1.parse = function parseAsn1(buf, depth) { asn1.children = []; while (iters < 100 && index < buf.byteLength) { 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); + //console.log('buflen', buf.byteLength, 'index', index); asn1.children.push(child); } if (iters >= 100) { throw new Error(ELOOP); }