From b6769f373471e255924c3b690f0a6178c0974a3b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 22 Nov 2018 23:07:03 -0700 Subject: [PATCH] update builder function --- lib/asn1.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/asn1.js b/lib/asn1.js index 36cf592..83a28b3 100644 --- a/lib/asn1.js +++ b/lib/asn1.js @@ -153,7 +153,7 @@ ASN1._stringify = function(asn1) { ASN1.tpl = function (asn1) { //console.log(JSON.stringify(asn1, null, 2)); //console.log(asn1); - var ws = ''; + var ws = '\t'; var i = 0; var vars = []; var str = ws; @@ -177,12 +177,12 @@ ASN1.tpl = function (asn1) { if (0x05 !== asn1.type) { if (0x06 !== asn1.type) { val = Buffer.from(asn1.value || ''); - vars.push("// 0x" + Enc.numToHex(val.byteLength) + " (" + val.byteLength + " bytes)\nvar tpl" + i + " = '" + vars.push("// 0x" + Enc.numToHex(val.byteLength) + " (" + val.byteLength + " bytes)\nopts.tpl" + i + " = '" + Enc.bufToHex(val) + "';"); if (0x02 !== asn1.type && 0x03 !== asn1.type) { str += ", "; } - str += "tpl" + i; + str += "opts.tpl" + i; } else { str += ", " + Enc.bufToHex(asn1.value); } @@ -200,8 +200,12 @@ ASN1.tpl = function (asn1) { } write(asn1); + console.log('var opts = {};'); console.log(vars.join('\n') + '\n'); - console.log(str + ';'); + console.log(); + console.log('function buildSchema(opts) {'); + console.log('\treturn ' + str.slice(3) + ';'); + console.log('}'); }; module.exports = ASN1;