diff --git a/defs.js b/defs.js index 2a85ef1..2e485c3 100644 --- a/defs.js +++ b/defs.js @@ -21,10 +21,15 @@ const rfc = require('./rfcdef'); -function translate(def, tn) { +function translate(def, tn, stats) { if (def?.type == 'tag' && !def.explicit) // def.type = def.content[0].type; def = def.content[0].type; + if (def?.definedBy) + try { + // hope current OIDs contain the type name (will need to parse from RFC itself) + def = Defs.searchType(firstUpper(stats.defs[def.definedBy][1])); + } catch (e) {} while (def?.type == 'defined' || def?.type?.type == 'defined') { const name = def?.type?.type ? def.type.name : def.name; def = Object.assign({}, def); @@ -69,7 +74,7 @@ class Defs { static match(value, def, stats = { total: 0, recognized: 0, defs: {} }) { value.def = {}; let tn = value.typeName().replaceAll('_', ' '); - def = translate(def, tn); + def = translate(def, tn, stats); ++stats.total; if (def?.type) { // if (def.id || def.name) ++stats.recognized; @@ -101,8 +106,7 @@ class Defs { if (typeof v == 'string') v = v.split(/\n/); stats.defs[type.id] = v; - } else if (type?.definedBy && stats.defs?.[type.definedBy]?.[1]) // hope current OIDs contain the type name (will need to parse from RFC itself) - type = Defs.searchType(firstUpper(stats.defs[type.definedBy][1])); + } } } Defs.match(subval, type, stats); diff --git a/dumpASN1.js b/dumpASN1.js index d43872f..c937469 100755 --- a/dumpASN1.js +++ b/dumpASN1.js @@ -58,7 +58,7 @@ const t1 = performance.now(); console.log('Parsed in ' + (t1 - t0).toFixed(2) + ' ms; possible types:'); for (const t of types) console.log((t.match * 100).toFixed(2).padStart(6) + '% ' + t.type.description); -const stats = Defs.match(result, types[0].match >= 0.1 ? types[0].type : null); +const stats = Defs.match(result, types[0].type); // console.log('Stats:', stats); console.log('Parsed as:', result.def); // const type = searchType(process.argv[2]);