@lapo/asn1js 2.0.5 → 2.1.0
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/asn1.js +24 -18
- package/base64.js +6 -5
- package/defs.js +8 -6
- package/dumpASN1.js +1 -1
- package/int10.js +13 -7
- package/package.json +32 -75
package/asn1.js
CHANGED
|
@@ -21,7 +21,8 @@ const
|
|
|
21
21
|
reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|(-(?:0\d|1[0-2])|[+](?:0\d|1[0-4]))([0-5]\d)?)?$/,
|
|
22
22
|
reTimeL = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|(-(?:0\d|1[0-2])|[+](?:0\d|1[0-4]))([0-5]\d)?)?$/,
|
|
23
23
|
hexDigits = '0123456789ABCDEF',
|
|
24
|
-
|
|
24
|
+
b64Std = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
|
25
|
+
b64URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
|
|
25
26
|
tableT61 = [
|
|
26
27
|
['', ''],
|
|
27
28
|
['AEIOUaeiou', 'ÀÈÌÒÙàèìòù'], // Grave
|
|
@@ -58,7 +59,7 @@ function checkPrintable(s) {
|
|
|
58
59
|
|
|
59
60
|
/** Class to manage a stream of bytes, with a zero-copy approach.
|
|
60
61
|
* It uses an existing array or binary string and advances a position index. */
|
|
61
|
-
class Stream {
|
|
62
|
+
export class Stream {
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* @param {Stream|array|string} enc data (will not be copied)
|
|
@@ -98,7 +99,7 @@ class Stream {
|
|
|
98
99
|
/** Hexadecimal dump of a specified region of the stream.
|
|
99
100
|
* @param {number} start starting position (included)
|
|
100
101
|
* @param {number} end ending position (excluded)
|
|
101
|
-
* @param {string} type 'raw', 'byte' or 'dump' */
|
|
102
|
+
* @param {string} type 'raw', 'byte' or 'dump' (default) */
|
|
102
103
|
hexDump(start, end, type = 'dump') {
|
|
103
104
|
let s = '';
|
|
104
105
|
for (let i = start; i < end; ++i) {
|
|
@@ -114,26 +115,29 @@ class Stream {
|
|
|
114
115
|
}
|
|
115
116
|
return s;
|
|
116
117
|
}
|
|
117
|
-
/**
|
|
118
|
+
/** Base64url dump of a specified region of the stream (according to RFC 4648 section 5).
|
|
118
119
|
* @param {number} start starting position (included)
|
|
119
|
-
* @param {number} end ending position (excluded)
|
|
120
|
-
|
|
120
|
+
* @param {number} end ending position (excluded)
|
|
121
|
+
* @param {string} type 'url' (default, section 5 without padding) or 'std' (section 4 with padding) */
|
|
122
|
+
b64Dump(start, end, type = 'url') {
|
|
123
|
+
const b64 = type === 'url' ? b64URL : b64Std;
|
|
121
124
|
let extra = (end - start) % 3,
|
|
122
125
|
s = '',
|
|
123
126
|
i, c;
|
|
124
127
|
for (i = start; i + 2 < end; i += 3) {
|
|
125
128
|
c = this.get(i) << 16 | this.get(i + 1) << 8 | this.get(i + 2);
|
|
126
|
-
s +=
|
|
127
|
-
s +=
|
|
128
|
-
s +=
|
|
129
|
-
s +=
|
|
129
|
+
s += b64.charAt(c >> 18 & 0x3F);
|
|
130
|
+
s += b64.charAt(c >> 12 & 0x3F);
|
|
131
|
+
s += b64.charAt(c >> 6 & 0x3F);
|
|
132
|
+
s += b64.charAt(c & 0x3F);
|
|
130
133
|
}
|
|
131
134
|
if (extra > 0) {
|
|
132
135
|
c = this.get(i) << 16;
|
|
133
136
|
if (extra > 1) c |= this.get(i + 1) << 8;
|
|
134
|
-
s +=
|
|
135
|
-
s +=
|
|
136
|
-
if (extra == 2) s +=
|
|
137
|
+
s += b64.charAt(c >> 18 & 0x3F);
|
|
138
|
+
s += b64.charAt(c >> 12 & 0x3F);
|
|
139
|
+
if (extra == 2) s += b64.charAt(c >> 6 & 0x3F);
|
|
140
|
+
if (b64 === b64Std) s += '==='.slice(0, 3 - extra);
|
|
137
141
|
}
|
|
138
142
|
return s;
|
|
139
143
|
}
|
|
@@ -291,7 +295,7 @@ class Stream {
|
|
|
291
295
|
s = this.parseStringUTF(start, end, maxLength);
|
|
292
296
|
checkPrintable(s.str);
|
|
293
297
|
return { size: end - start, str: s.str };
|
|
294
|
-
} catch (
|
|
298
|
+
} catch (ignore) {
|
|
295
299
|
// ignore
|
|
296
300
|
}
|
|
297
301
|
maxLength /= 2; // we work in bytes
|
|
@@ -557,9 +561,11 @@ export class ASN1 {
|
|
|
557
561
|
toHexString(type = 'raw') {
|
|
558
562
|
return this.stream.hexDump(this.posStart(), this.posEnd(), type);
|
|
559
563
|
}
|
|
560
|
-
/**
|
|
561
|
-
|
|
562
|
-
|
|
564
|
+
/** Base64url dump of the node (according to RFC 4648 section 5).
|
|
565
|
+
* @param {string} type 'url' (default, section 5 without padding) or 'std' (section 4 with padding)
|
|
566
|
+
*/
|
|
567
|
+
toB64String(type = 'url') {
|
|
568
|
+
return this.stream.b64Dump(this.posStart(), this.posEnd(), type);
|
|
563
569
|
}
|
|
564
570
|
static decodeLength(stream) {
|
|
565
571
|
let buf = stream.get(),
|
|
@@ -632,7 +638,7 @@ export class ASN1 {
|
|
|
632
638
|
throw new Error('Unable to parse content: ' + e);
|
|
633
639
|
}
|
|
634
640
|
}
|
|
635
|
-
} catch (
|
|
641
|
+
} catch (ignore) {
|
|
636
642
|
// but silently ignore when they don't
|
|
637
643
|
sub = null;
|
|
638
644
|
//DEBUG console.log('Could not decode structure at ' + start + ':', e);
|
package/base64.js
CHANGED
|
@@ -31,7 +31,7 @@ export class Base64 {
|
|
|
31
31
|
decoder[b64.charCodeAt(i)] = i;
|
|
32
32
|
for (i = 0; i < ignore.length; ++i)
|
|
33
33
|
decoder[ignore.charCodeAt(i)] = -1;
|
|
34
|
-
//
|
|
34
|
+
// also support decoding Base64url (RFC 4648 section 5)
|
|
35
35
|
decoder['-'.charCodeAt(0)] = decoder['+'.charCodeAt(0)];
|
|
36
36
|
decoder['_'.charCodeAt(0)] = decoder['/'.charCodeAt(0)];
|
|
37
37
|
}
|
|
@@ -75,12 +75,13 @@ export class Base64 {
|
|
|
75
75
|
|
|
76
76
|
static pretty(str) {
|
|
77
77
|
// fix padding
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
let pad = 4 - str.length % 4;
|
|
79
|
+
if (pad < 4)
|
|
80
|
+
str += '==='.slice(0, pad);
|
|
81
|
+
// convert Base64url (RFC 4648 section 5) to standard Base64 (RFC 4648 section 4)
|
|
81
82
|
str = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
82
83
|
// 80 column width
|
|
83
|
-
return str.replace(
|
|
84
|
+
return str.replace(/.{80}/g, '$&\n');
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
static unarmor(a) {
|
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
|
}
|
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.0
|
|
3
|
+
"version": "2.1.0",
|
|
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,17 +8,34 @@
|
|
|
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",
|
|
20
37
|
"build": "vite build",
|
|
21
|
-
"serve": "
|
|
38
|
+
"serve": "npx -p local-web-server ws",
|
|
22
39
|
"test": "node test",
|
|
23
40
|
"testdefs": "node testDefs"
|
|
24
41
|
},
|
|
@@ -26,15 +43,20 @@
|
|
|
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.32.0",
|
|
52
|
+
"@rollup/wasm-node": "^4.46.2",
|
|
53
|
+
"diff": "^8.0.2",
|
|
54
|
+
"eslint": "^9.32.0",
|
|
55
|
+
"globals": "^16.3.0",
|
|
34
56
|
"htmlparser2": "^9.1.0",
|
|
35
|
-
"vite": "^5.4.
|
|
57
|
+
"vite": "^5.4.19",
|
|
36
58
|
"vite-plugin-dom": "^1.0.4",
|
|
37
|
-
"vite-plugin-singlefile": "^2.0
|
|
59
|
+
"vite-plugin-singlefile": "^2.3.0"
|
|
38
60
|
},
|
|
39
61
|
"overrides": {
|
|
40
62
|
"rollup": "npm:@rollup/wasm-node"
|
|
@@ -43,70 +65,5 @@
|
|
|
43
65
|
"overrides": {
|
|
44
66
|
"rollup": "npm:@rollup/wasm-node"
|
|
45
67
|
}
|
|
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
68
|
}
|
|
112
69
|
}
|