Skip to content

Commit

Permalink
Add somewhat support for ContentInfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
lapo-luchini committed Nov 1, 2022
1 parent 398defa commit c29661d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions dumpASN1.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ function translate(def) {
return def ?? {};
}

function firstUpper(s) {
return s[0].toUpperCase() + s.slice(1);
}

function print(value, def, stats, indent) {
if (indent === undefined) indent = '';
if (stats) {
stats.total ??= 0;
stats.recognized ??= 0;
}
stats ??= {};
stats.total ??= 0;
stats.recognized ??= 0;
stats.defs ??= {};
// console.log(def);
let deftype = translate(def);
let tn = value.typeName();
Expand Down Expand Up @@ -83,6 +87,10 @@ function print(value, def, stats, indent) {
do {
type = deftype.content[j++];
} while (type && ('optional' in type || 'default' in type) && type.name != tn);
if (type?.type == 'defined')
stats.defs[type.id] = subval.content().split(/\n/);
else if (type?.type?.definedBy) // hope current OIDs contain the type name (will need to parse from RFC itself)
type = searchType(firstUpper(stats.defs[type.type.definedBy][1]));
}
}
s += print(subval, type, stats, indent);
Expand All @@ -101,3 +109,4 @@ content = null;
let stats = {};
console.log(print(result, searchType(process.argv[2]), stats));
console.log('Stats:', (stats.recognized * 100 / stats.total).toFixed(2) + '%');
console.log('Defs:', stats.defs);

0 comments on commit c29661d

Please sign in to comment.