JavaScript generic ASN.1 parser (mirror)
1
fork

Configure Feed

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

Add new test to check for defs regressions.

+42 -2
+2
.github/workflows/node.js.yml
··· 21 21 with: 22 22 node-version: ${{ matrix.node-version }} 23 23 - run: npm test all 24 + - run: npm run testdefs 25 + if: matrix.node-version == 'latest' 24 26 - run: npm run lint 25 27 if: matrix.node-version == 'latest'
+8 -2
package.json
··· 15 15 "homepage": "https://lapo.it/asn1js/", 16 16 "files": [ "asn1.js", "base64.js", "hex.js", "int10.js", "oids.js" ], 17 17 "scripts": { 18 - "lint": "npx eslint asn1.js base64.js hex.js int10.js oids.js tags.js context.js index.js parseRFC.js dumpASN1.js", 18 + "lint": "npx eslint asn1.js base64.js hex.js int10.js oids.js tags.js context.js index.js parseRFC.js dumpASN1.js test.js testDefs.js", 19 19 "lint-action": "npx @action-validator/cli .github/workflows/node.js.yml", 20 20 "serve": "echo 'Connect to http://localhost:3000/' ; npx statik --port 3000 .", 21 - "test": "node test" 21 + "test": "node test", 22 + "testdefs": "node testDefs" 22 23 }, 23 24 "engines": { 24 25 "node": ">=12.20.0" ··· 80 81 "files": [ "defs.js" ], 81 82 "parserOptions": { 82 83 "ecmaVersion": 2021 84 + } 85 + }, { 86 + "files": [ "testDefs.js" ], 87 + "parserOptions": { 88 + "ecmaVersion": 2022 83 89 } 84 90 } 85 91 ]
+32
testDefs.js
··· 1 + #!/usr/bin/env node 2 + 3 + import { promises as fs } from 'node:fs'; 4 + import { ASN1 } from './asn1.js'; 5 + import { Base64 } from './base64.js'; 6 + import { Defs } from './defs.js'; 7 + 8 + const tot = []; 9 + for await (const file of await fs.opendir('examples')) { 10 + let content = await fs.readFile('examples/' + file.name); 11 + try { 12 + try { // try PEM first 13 + content = Base64.unarmor(content); 14 + } catch (e) { // try DER/BER then 15 + } 16 + let result = ASN1.decode(content); 17 + content = null; 18 + const types = Defs.commonTypes 19 + .map(type => { 20 + const stats = Defs.match(result, type); 21 + return { type, match: stats.recognized / stats.total }; 22 + }) 23 + .sort((a, b) => b.match - a.match); 24 + tot.push([ types[0].match, file.name, types[0].type.description ]); 25 + } catch (e) { 26 + tot.push([ 0, file.name, e.message ]); 27 + } 28 + } 29 + for (const f of tot) 30 + console.log(f[0].toFixed(3) + '\t' + f[1] + '\t' + f[2]); 31 + const avg = tot.map(f => f[0]).reduce((sum, val) => sum + val) / tot.length; 32 + console.log('\x1B[1m\x1B[32m' + (avg * 100).toFixed(3) + '\x1B[39m\x1B[22m%\tAVERAGE');