-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new test to check for defs regressions.
- Loading branch information
1 parent
8400fa7
commit fd1b6d0
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env node | ||
|
||
import { promises as fs } from 'node:fs'; | ||
import { ASN1 } from './asn1.js'; | ||
import { Base64 } from './base64.js'; | ||
import { Defs } from './defs.js'; | ||
|
||
const tot = []; | ||
for await (const file of await fs.opendir('examples')) { | ||
let content = await fs.readFile('examples/' + file.name); | ||
try { | ||
try { // try PEM first | ||
content = Base64.unarmor(content); | ||
} catch (e) { // try DER/BER then | ||
} | ||
let result = ASN1.decode(content); | ||
content = null; | ||
const types = Defs.commonTypes | ||
.map(type => { | ||
const stats = Defs.match(result, type); | ||
return { type, match: stats.recognized / stats.total }; | ||
}) | ||
.sort((a, b) => b.match - a.match); | ||
tot.push([ types[0].match, file.name, types[0].type.description ]); | ||
} catch (e) { | ||
tot.push([ 0, file.name, e.message ]); | ||
} | ||
} | ||
for (const f of tot) | ||
console.log(f[0].toFixed(3) + '\t' + f[1] + '\t' + f[2]); | ||
const avg = tot.map(f => f[0]).reduce((sum, val) => sum + val) / tot.length; | ||
console.log('\x1B[1m\x1B[32m' + (avg * 100).toFixed(3) + '\x1B[39m\x1B[22m%\tAVERAGE'); |