JavaScript generic ASN.1 parser (mirror)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add somewhat support for `ContentInfo`.

+13 -4
+13 -4
dumpASN1.js
··· 29 29 return def ?? {}; 30 30 } 31 31 32 + function firstUpper(s) { 33 + return s[0].toUpperCase() + s.slice(1); 34 + } 35 + 32 36 function print(value, def, stats, indent) { 33 37 if (indent === undefined) indent = ''; 34 - if (stats) { 35 - stats.total ??= 0; 36 - stats.recognized ??= 0; 37 - } 38 + stats ??= {}; 39 + stats.total ??= 0; 40 + stats.recognized ??= 0; 41 + stats.defs ??= {}; 38 42 // console.log(def); 39 43 let deftype = translate(def); 40 44 let tn = value.typeName(); ··· 83 87 do { 84 88 type = deftype.content[j++]; 85 89 } while (type && ('optional' in type || 'default' in type) && type.name != tn); 90 + if (type?.type == 'defined') 91 + stats.defs[type.id] = subval.content().split(/\n/); 92 + else if (type?.type?.definedBy) // hope current OIDs contain the type name (will need to parse from RFC itself) 93 + type = searchType(firstUpper(stats.defs[type.type.definedBy][1])); 86 94 } 87 95 } 88 96 s += print(subval, type, stats, indent); ··· 101 109 let stats = {}; 102 110 console.log(print(result, searchType(process.argv[2]), stats)); 103 111 console.log('Stats:', (stats.recognized * 100 / stats.total).toFixed(2) + '%'); 112 + console.log('Defs:', stats.defs);