@lapo/asn1js 2.0.6 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/asn1.js +5 -2
- package/defs.js +9 -6
- package/dumpASN1.js +1 -1
- package/int10.js +13 -7
- package/package.json +34 -76
package/README.md
CHANGED
|
@@ -101,8 +101,10 @@ credits
|
|
|
101
101
|
links
|
|
102
102
|
-----
|
|
103
103
|
|
|
104
|
-
- [official website](https://
|
|
105
|
-
- [
|
|
106
|
-
- [
|
|
104
|
+
- [official website](https://asn1js.eu/)
|
|
105
|
+
- [alternate website](https://lapo.it/asn1js/)
|
|
106
|
+
- [single-file version working locally](https://asn1js.eu/index-local.html) (just save this link)
|
|
107
|
+
- [InDefero tracker](http://idf.lapo.it/p/asn1js/) (currently offline)
|
|
107
108
|
- [GitHub mirror](https://github.com/lapo-luchini/asn1js)
|
|
109
|
+
- [ChangeLog on GitHub](https://github.com/lapo-luchini/asn1js/blob/trunk/CHANGELOG.md)
|
|
108
110
|
- [Ohloh code stats](https://www.openhub.net/p/asn1js)
|
package/asn1.js
CHANGED
|
@@ -295,7 +295,7 @@ export class Stream {
|
|
|
295
295
|
s = this.parseStringUTF(start, end, maxLength);
|
|
296
296
|
checkPrintable(s.str);
|
|
297
297
|
return { size: end - start, str: s.str };
|
|
298
|
-
} catch (
|
|
298
|
+
} catch (ignore) {
|
|
299
299
|
// ignore
|
|
300
300
|
}
|
|
301
301
|
maxLength /= 2; // we work in bytes
|
|
@@ -461,8 +461,10 @@ export class ASN1 {
|
|
|
461
461
|
}
|
|
462
462
|
switch (this.tag.tagNumber) {
|
|
463
463
|
case 0x01: // BOOLEAN
|
|
464
|
+
if (len != 1) return 'invalid length ' + len;
|
|
464
465
|
return (this.stream.get(content) === 0) ? 'false' : 'true';
|
|
465
466
|
case 0x02: // INTEGER
|
|
467
|
+
if (len < 1) return 'invalid length ' + len;
|
|
466
468
|
return this.stream.parseInteger(content, content + len);
|
|
467
469
|
case 0x03: { // BIT_STRING
|
|
468
470
|
let d = recurse(this, 'parseBitString', maxLength);
|
|
@@ -474,6 +476,7 @@ export class ASN1 {
|
|
|
474
476
|
}
|
|
475
477
|
//case 0x05: // NULL
|
|
476
478
|
case 0x06: // OBJECT_IDENTIFIER
|
|
479
|
+
if (len < 1) return 'invalid length ' + len; // pgut001's dumpasn1.c enforces a minimum lenght of 3
|
|
477
480
|
return this.stream.parseOID(content, content + len, maxLength);
|
|
478
481
|
//case 0x07: // ObjectDescriptor
|
|
479
482
|
//case 0x08: // EXTERNAL
|
|
@@ -638,7 +641,7 @@ export class ASN1 {
|
|
|
638
641
|
throw new Error('Unable to parse content: ' + e);
|
|
639
642
|
}
|
|
640
643
|
}
|
|
641
|
-
} catch (
|
|
644
|
+
} catch (ignore) {
|
|
642
645
|
// but silently ignore when they don't
|
|
643
646
|
sub = null;
|
|
644
647
|
//DEBUG console.log('Could not decode structure at ' + start + ':', e);
|
package/defs.js
CHANGED
|
@@ -23,7 +23,7 @@ function translate(def, tn, stats) {
|
|
|
23
23
|
try {
|
|
24
24
|
// hope current OIDs contain the type name (will need to parse from RFC itself)
|
|
25
25
|
def = Defs.searchType(firstUpper(stats.defs[def.definedBy][1]));
|
|
26
|
-
} catch (
|
|
26
|
+
} catch (ignore) { /*ignore*/ }
|
|
27
27
|
while (def?.type == 'defined' || def?.type?.type == 'defined') {
|
|
28
28
|
const name = def?.type?.type ? def.type.name : def.name;
|
|
29
29
|
def = Object.assign({}, def);
|
|
@@ -35,7 +35,8 @@ function translate(def, tn, stats) {
|
|
|
35
35
|
c = translate(c);
|
|
36
36
|
if (tn == c.type.name || tn == c.name) {
|
|
37
37
|
def = Object.assign({}, def);
|
|
38
|
-
if (c.id)
|
|
38
|
+
if (c.id) // show the CHOICE id, but add it to existing one if present
|
|
39
|
+
def.id = def.id ? def.id + ' ' + c.id : c.id;
|
|
39
40
|
def.type = c.type.name ? c.type : c;
|
|
40
41
|
break;
|
|
41
42
|
}
|
|
@@ -69,7 +70,7 @@ export class Defs {
|
|
|
69
70
|
|
|
70
71
|
static match(value, def, stats = { total: 0, recognized: 0, defs: {} }) {
|
|
71
72
|
value.def = {};
|
|
72
|
-
let tn = value.typeName().
|
|
73
|
+
let tn = value.typeName().replace(/_/g, ' ');
|
|
73
74
|
def = translate(def, tn, stats);
|
|
74
75
|
++stats.total;
|
|
75
76
|
if (def?.type) {
|
|
@@ -90,12 +91,13 @@ export class Defs {
|
|
|
90
91
|
if (def.typeOf)
|
|
91
92
|
type = def.content[0];
|
|
92
93
|
else {
|
|
93
|
-
let tn = subval.typeName().
|
|
94
|
+
let tn = subval.typeName().replace(/_/g, ' ');
|
|
94
95
|
for (;;) {
|
|
95
96
|
type = def.content[j++];
|
|
96
97
|
if (!type || typeof type != 'object') break;
|
|
97
98
|
if (type?.type?.type)
|
|
98
|
-
type = type.type;
|
|
99
|
+
// type = type.type;
|
|
100
|
+
type = Object.assign({}, type.type, {id: type.id});
|
|
99
101
|
if (type.type == 'defined') {
|
|
100
102
|
let t2 = translate(type, tn);
|
|
101
103
|
if (t2.type.name == tn) break; // exact match
|
|
@@ -113,7 +115,7 @@ export class Defs {
|
|
|
113
115
|
} else if (type?.definedBy && stats.defs?.[type.definedBy]?.[1]) { // hope current OIDs contain the type name (will need to parse from RFC itself)
|
|
114
116
|
try {
|
|
115
117
|
type = Defs.searchType(firstUpper(stats.defs[type.definedBy][1]));
|
|
116
|
-
} catch (
|
|
118
|
+
} catch (ignore) { /*ignore*/ }
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
}
|
|
@@ -138,4 +140,5 @@ Defs.commonTypes = [
|
|
|
138
140
|
[ 'PKCS#10 certification request', '1.2.840.113549.1.10.1.1', 'CertificationRequest' ],
|
|
139
141
|
[ 'CMP PKI Message', '1.3.6.1.5.5.7.0.16', 'PKIMessage' ],
|
|
140
142
|
[ 'LDAP Message', '1.3.6.1.1.18', 'LDAPMessage' ],
|
|
143
|
+
[ 'Time Stamp Request', '1.3.6.1.5.5.7.0.13', 'TimeStampReq' ],
|
|
141
144
|
].map(arr => ({ description: arr[0], ...Defs.moduleAndType(rfcdef[arr[1]], arr[2]) }));
|
package/dumpASN1.js
CHANGED
package/int10.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
14
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/** Biggest 10^n integer that can still fit 2^53 when multiplied by 256. */
|
|
17
|
+
const max = 10000000000000;
|
|
17
18
|
|
|
18
19
|
export class Int10 {
|
|
19
20
|
/**
|
|
@@ -26,11 +27,13 @@ export class Int10 {
|
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Multiply value by m and add c.
|
|
29
|
-
* @param {number} m - multiplier, must be <
|
|
30
|
-
* @param {number} c - value to add
|
|
30
|
+
* @param {number} m - multiplier, must be 0<m<=256
|
|
31
|
+
* @param {number} c - value to add, must be c>=0
|
|
31
32
|
*/
|
|
32
33
|
mulAdd(m, c) {
|
|
34
|
+
// assert(m > 0)
|
|
33
35
|
// assert(m <= 256)
|
|
36
|
+
// assert(c >= 0)
|
|
34
37
|
let b = this.buf,
|
|
35
38
|
l = b.length,
|
|
36
39
|
i, t;
|
|
@@ -71,11 +74,12 @@ export class Int10 {
|
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
76
|
* Convert to decimal string representation.
|
|
74
|
-
* @param {
|
|
77
|
+
* @param {number} [base=10] - optional value, only value accepted is 10
|
|
78
|
+
* @returns {string} The decimal string representation.
|
|
75
79
|
*/
|
|
76
|
-
toString(base) {
|
|
77
|
-
if (
|
|
78
|
-
throw 'only base 10 is supported';
|
|
80
|
+
toString(base = 10) {
|
|
81
|
+
if (base != 10)
|
|
82
|
+
throw new Error('only base 10 is supported');
|
|
79
83
|
let b = this.buf,
|
|
80
84
|
s = b[b.length - 1].toString();
|
|
81
85
|
for (let i = b.length - 2; i >= 0; --i)
|
|
@@ -86,6 +90,7 @@ export class Int10 {
|
|
|
86
90
|
/**
|
|
87
91
|
* Convert to Number value representation.
|
|
88
92
|
* Will probably overflow 2^53 and thus become approximate.
|
|
93
|
+
* @returns {number} The numeric value.
|
|
89
94
|
*/
|
|
90
95
|
valueOf() {
|
|
91
96
|
let b = this.buf,
|
|
@@ -97,6 +102,7 @@ export class Int10 {
|
|
|
97
102
|
|
|
98
103
|
/**
|
|
99
104
|
* Return value as a simple Number (if it is <= 10000000000000), or return this.
|
|
105
|
+
* @returns {number | Int10} The simplified value.
|
|
100
106
|
*/
|
|
101
107
|
simplify() {
|
|
102
108
|
let b = this.buf;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lapo/asn1js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Generic ASN.1 parser/decoder that can decode any valid ASN.1 DER or BER structures.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "asn1.js",
|
|
@@ -8,12 +8,29 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/lapo-luchini/asn1js.git"
|
|
10
10
|
},
|
|
11
|
-
"keywords": [
|
|
11
|
+
"keywords": [
|
|
12
|
+
"asn1",
|
|
13
|
+
"ber",
|
|
14
|
+
"der",
|
|
15
|
+
"pem"
|
|
16
|
+
],
|
|
12
17
|
"author": "Lapo Luchini <lapo@lapo.it>",
|
|
13
18
|
"license": "ISC",
|
|
14
|
-
"bugs": {
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/lapo-luchini/asn1js/issues"
|
|
21
|
+
},
|
|
15
22
|
"homepage": "https://lapo.it/asn1js/",
|
|
16
|
-
"files": [
|
|
23
|
+
"files": [
|
|
24
|
+
"asn1.js",
|
|
25
|
+
"base64.js",
|
|
26
|
+
"hex.js",
|
|
27
|
+
"int10.js",
|
|
28
|
+
"dom.js",
|
|
29
|
+
"defs.js",
|
|
30
|
+
"oids.js",
|
|
31
|
+
"rfcdef.js",
|
|
32
|
+
"dumpASN1.js"
|
|
33
|
+
],
|
|
17
34
|
"scripts": {
|
|
18
35
|
"lint": "npx eslint asn1.js base64.js hex.js int10.js dom.js defs.js oids.js rfcdef.js tags.js context.js index.js parseRFC.js dumpASN1.js test.js testDefs.js vite.config.js theme.js",
|
|
19
36
|
"lint-action": "npx @action-validator/cli .github/workflows/node.js.yml",
|
|
@@ -26,87 +43,28 @@
|
|
|
26
43
|
"dumpASN1": "./dumpASN1.js"
|
|
27
44
|
},
|
|
28
45
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
46
|
+
"node": ">=14.6.0"
|
|
30
47
|
},
|
|
48
|
+
"packageManager": "pnpm@7.33.7",
|
|
31
49
|
"devDependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"eslint": "^
|
|
50
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
51
|
+
"@eslint/js": "^9.38.0",
|
|
52
|
+
"@rollup/wasm-node": "^4.52.5",
|
|
53
|
+
"diff": "^8.0.2",
|
|
54
|
+
"eslint": "^9.38.0",
|
|
55
|
+
"globals": "^16.4.0",
|
|
34
56
|
"htmlparser2": "^9.1.0",
|
|
35
|
-
"vite": "^5.4.
|
|
36
|
-
"vite-plugin-dom": "^1.0.
|
|
37
|
-
"vite-plugin-singlefile": "^2.0
|
|
57
|
+
"vite": "^5.4.21",
|
|
58
|
+
"vite-plugin-dom": "^1.0.5",
|
|
59
|
+
"vite-plugin-singlefile": "^2.3.0"
|
|
38
60
|
},
|
|
39
61
|
"overrides": {
|
|
40
62
|
"rollup": "npm:@rollup/wasm-node"
|
|
41
63
|
},
|
|
42
64
|
"pnpm": {
|
|
43
65
|
"overrides": {
|
|
44
|
-
"rollup": "npm:@rollup/wasm-node"
|
|
66
|
+
"rollup": "npm:@rollup/wasm-node",
|
|
67
|
+
"esbuild@<=0.24.2": ">=0.25.0"
|
|
45
68
|
}
|
|
46
|
-
},
|
|
47
|
-
"eslintConfig": {
|
|
48
|
-
"env": {
|
|
49
|
-
"es6": true,
|
|
50
|
-
"browser": true,
|
|
51
|
-
"node": true
|
|
52
|
-
},
|
|
53
|
-
"parserOptions": {
|
|
54
|
-
"ecmaVersion": 2015,
|
|
55
|
-
"sourceType": "module"
|
|
56
|
-
},
|
|
57
|
-
"extends": [ "eslint:recommended" ],
|
|
58
|
-
"globals": {
|
|
59
|
-
"Uint8Array": "readonly"
|
|
60
|
-
},
|
|
61
|
-
"rules": {
|
|
62
|
-
"strict": [ "error", "function" ],
|
|
63
|
-
"indent": [ "error", 4 ],
|
|
64
|
-
"no-trailing-spaces": [ "error" ],
|
|
65
|
-
"linebreak-style": [ "error", "unix" ],
|
|
66
|
-
"eol-last": [ "error", "always" ],
|
|
67
|
-
"semi": [ "warn", "always" ],
|
|
68
|
-
"quotes": [ "error", "single", { "avoidEscape": true } ],
|
|
69
|
-
"no-var": [ "warn" ],
|
|
70
|
-
"comma-dangle": [ "error", "always-multiline" ]
|
|
71
|
-
},
|
|
72
|
-
"overrides": [
|
|
73
|
-
{
|
|
74
|
-
"files": [ "defs.js" ],
|
|
75
|
-
"parserOptions": {
|
|
76
|
-
"ecmaVersion": 2020
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
"files": [ "test.js", "parseRFC.js", "dumpASN1.js" ],
|
|
80
|
-
"parserOptions": {
|
|
81
|
-
"ecmaVersion": 2021
|
|
82
|
-
},
|
|
83
|
-
"rules": {
|
|
84
|
-
"strict": [ "error", "global" ]
|
|
85
|
-
}
|
|
86
|
-
}, {
|
|
87
|
-
"files": [ "oids.js" ],
|
|
88
|
-
"rules": {
|
|
89
|
-
"indent": "off",
|
|
90
|
-
"quotes": [ "warn", "double" ]
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
"files": [ "tags.js", "rfcdef.js" ],
|
|
94
|
-
"rules": {
|
|
95
|
-
"indent": [ "error", 2, { "ignoredNodes": [ "Program > ExpressionStatement > CallExpression > FunctionExpression > BlockStatement > ExpressionStatement[directive='use strict']:first-child" ] } ],
|
|
96
|
-
"comma-dangle": "off",
|
|
97
|
-
"quotes": [ "warn", "double" ]
|
|
98
|
-
}
|
|
99
|
-
}, {
|
|
100
|
-
"files": [ "defs.js" ],
|
|
101
|
-
"parserOptions": {
|
|
102
|
-
"ecmaVersion": 2021
|
|
103
|
-
}
|
|
104
|
-
}, {
|
|
105
|
-
"files": [ "testDefs.js" ],
|
|
106
|
-
"parserOptions": {
|
|
107
|
-
"ecmaVersion": 2022
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
69
|
}
|
|
112
70
|
}
|