@lapo/asn1js 1.2.4 → 1.3.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/LICENSE +1 -1
- package/README.md +4 -1
- package/asn1.js +544 -537
- package/base64.js +77 -81
- package/hex.js +50 -55
- package/int10.js +82 -89
- package/oids.js +241 -67
- package/package.json +35 -8
package/base64.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Base64 JavaScript decoder
|
|
2
|
-
// Copyright (c) 2008-
|
|
2
|
+
// Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
|
|
3
3
|
|
|
4
4
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
5
5
|
// purpose with or without fee is hereby granted, provided that the above
|
|
@@ -13,95 +13,91 @@
|
|
|
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
|
-
|
|
17
|
-
if (typeof module == 'object') module.exports = factory();
|
|
18
|
-
else window.base64 = factory();
|
|
19
|
-
})(function () {
|
|
20
|
-
"use strict";
|
|
21
|
-
|
|
22
|
-
var Base64 = {},
|
|
23
|
-
decoder, // populated on first usage
|
|
16
|
+
const
|
|
24
17
|
haveU8 = (typeof Uint8Array == 'function');
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
decoder
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
let decoder; // populated on first usage
|
|
20
|
+
|
|
21
|
+
export class Base64 {
|
|
22
|
+
|
|
23
|
+
static decode(a) {
|
|
24
|
+
let isString = (typeof a == 'string');
|
|
25
|
+
let i;
|
|
26
|
+
if (decoder === undefined) {
|
|
27
|
+
let b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
|
28
|
+
ignore = '= \f\n\r\t\u00A0\u2028\u2029';
|
|
29
|
+
decoder = [];
|
|
30
|
+
for (i = 0; i < 64; ++i)
|
|
31
|
+
decoder[b64.charCodeAt(i)] = i;
|
|
32
|
+
for (i = 0; i < ignore.length; ++i)
|
|
33
|
+
decoder[ignore.charCodeAt(i)] = -1;
|
|
34
|
+
// RFC 3548 URL & file safe encoding
|
|
35
|
+
decoder['-'.charCodeAt(0)] = decoder['+'.charCodeAt(0)];
|
|
36
|
+
decoder['_'.charCodeAt(0)] = decoder['/'.charCodeAt(0)];
|
|
37
|
+
}
|
|
38
|
+
let out = haveU8 ? new Uint8Array(a.length * 3 >> 2) : [];
|
|
39
|
+
let bits = 0, char_count = 0, len = 0;
|
|
40
|
+
for (i = 0; i < a.length; ++i) {
|
|
41
|
+
let c = isString ? a.charCodeAt(i) : a[i];
|
|
42
|
+
if (c == 61) // '='.charCodeAt(0)
|
|
43
|
+
break;
|
|
44
|
+
c = decoder[c];
|
|
45
|
+
if (c == -1)
|
|
46
|
+
continue;
|
|
47
|
+
if (c === undefined)
|
|
48
|
+
throw 'Illegal character at offset ' + i;
|
|
49
|
+
bits |= c;
|
|
50
|
+
if (++char_count >= 4) {
|
|
51
|
+
out[len++] = (bits >> 16);
|
|
52
|
+
out[len++] = (bits >> 8) & 0xFF;
|
|
53
|
+
out[len++] = bits & 0xFF;
|
|
54
|
+
bits = 0;
|
|
55
|
+
char_count = 0;
|
|
56
|
+
} else {
|
|
57
|
+
bits <<= 6;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
switch (char_count) {
|
|
61
|
+
case 1:
|
|
62
|
+
throw 'Base64 encoding incomplete: at least 2 bits missing';
|
|
63
|
+
case 2:
|
|
64
|
+
out[len++] = (bits >> 10);
|
|
46
65
|
break;
|
|
47
|
-
|
|
48
|
-
if (c == -1)
|
|
49
|
-
continue;
|
|
50
|
-
if (c === undefined)
|
|
51
|
-
throw 'Illegal character at offset ' + i;
|
|
52
|
-
bits |= c;
|
|
53
|
-
if (++char_count >= 4) {
|
|
66
|
+
case 3:
|
|
54
67
|
out[len++] = (bits >> 16);
|
|
55
68
|
out[len++] = (bits >> 8) & 0xFF;
|
|
56
|
-
|
|
57
|
-
bits = 0;
|
|
58
|
-
char_count = 0;
|
|
59
|
-
} else {
|
|
60
|
-
bits <<= 6;
|
|
69
|
+
break;
|
|
61
70
|
}
|
|
71
|
+
if (haveU8 && out.length > len) // in case it was originally longer because of ignored characters
|
|
72
|
+
out = out.subarray(0, len);
|
|
73
|
+
return out;
|
|
62
74
|
}
|
|
63
|
-
switch (char_count) {
|
|
64
|
-
case 1:
|
|
65
|
-
throw "Base64 encoding incomplete: at least 2 bits missing";
|
|
66
|
-
case 2:
|
|
67
|
-
out[len++] = (bits >> 10);
|
|
68
|
-
break;
|
|
69
|
-
case 3:
|
|
70
|
-
out[len++] = (bits >> 16);
|
|
71
|
-
out[len++] = (bits >> 8) & 0xFF;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
if (haveU8 && out.length > len) // in case it was originally longer because of ignored characters
|
|
75
|
-
out = out.subarray(0, len);
|
|
76
|
-
return out;
|
|
77
|
-
};
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
76
|
+
static pretty(str) {
|
|
77
|
+
// fix padding
|
|
78
|
+
if (str.length % 4 > 0)
|
|
79
|
+
str = (str + '===').slice(0, str.length + str.length % 4);
|
|
80
|
+
// convert RFC 3548 to standard Base64
|
|
81
|
+
str = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
82
|
+
// 80 column width
|
|
83
|
+
return str.replace(/(.{80})/g, '$1\n');
|
|
84
|
+
}
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
static unarmor(a) {
|
|
87
|
+
let m = Base64.re.exec(a);
|
|
88
|
+
if (m) {
|
|
89
|
+
if (m[1])
|
|
90
|
+
a = m[1];
|
|
91
|
+
else if (m[2])
|
|
92
|
+
a = m[2];
|
|
93
|
+
else if (m[3])
|
|
94
|
+
a = m[3];
|
|
95
|
+
else
|
|
96
|
+
throw 'RegExp out of sync';
|
|
97
|
+
}
|
|
98
|
+
return Base64.decode(a);
|
|
101
99
|
}
|
|
102
|
-
return Base64.decode(a);
|
|
103
|
-
};
|
|
104
100
|
|
|
105
|
-
|
|
101
|
+
}
|
|
106
102
|
|
|
107
|
-
|
|
103
|
+
Base64.re = /-----BEGIN [^-]+-----([A-Za-z0-9+/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+/=\s]+)====|^([A-Za-z0-9+/=\s]+)$/;
|
package/hex.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Hex JavaScript decoder
|
|
2
|
-
// Copyright (c) 2008-
|
|
2
|
+
// Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
|
|
3
3
|
|
|
4
4
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
5
5
|
// purpose with or without fee is hereby granted, provided that the above
|
|
@@ -13,62 +13,57 @@
|
|
|
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
|
-
|
|
17
|
-
if (typeof module == 'object') module.exports = factory();
|
|
18
|
-
else window.hex = factory();
|
|
19
|
-
})(function () {
|
|
20
|
-
"use strict";
|
|
21
|
-
|
|
22
|
-
var Hex = {},
|
|
23
|
-
decoder, // populated on first usage
|
|
16
|
+
const
|
|
24
17
|
haveU8 = (typeof Uint8Array == 'function');
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
19
|
+
let decoder; // populated on first usage
|
|
20
|
+
|
|
21
|
+
export class Hex {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decodes an hexadecimal value.
|
|
25
|
+
* @param {string|Array|Uint8Array} a - a string representing hexadecimal data, or an array representation of its charcodes
|
|
26
|
+
*/
|
|
27
|
+
static decode(a) {
|
|
28
|
+
let isString = (typeof a == 'string');
|
|
29
|
+
let i;
|
|
30
|
+
if (decoder === undefined) {
|
|
31
|
+
let hex = '0123456789ABCDEF',
|
|
32
|
+
ignore = ' \f\n\r\t\u00A0\u2028\u2029';
|
|
33
|
+
decoder = [];
|
|
34
|
+
for (i = 0; i < 16; ++i)
|
|
35
|
+
decoder[hex.charCodeAt(i)] = i;
|
|
36
|
+
hex = hex.toLowerCase();
|
|
37
|
+
for (i = 10; i < 16; ++i)
|
|
38
|
+
decoder[hex.charCodeAt(i)] = i;
|
|
39
|
+
for (i = 0; i < ignore.length; ++i)
|
|
40
|
+
decoder[ignore.charCodeAt(i)] = -1;
|
|
41
|
+
}
|
|
42
|
+
let out = haveU8 ? new Uint8Array(a.length >> 1) : [],
|
|
43
|
+
bits = 0,
|
|
44
|
+
char_count = 0,
|
|
45
|
+
len = 0;
|
|
46
|
+
for (i = 0; i < a.length; ++i) {
|
|
47
|
+
let c = isString ? a.charCodeAt(i) : a[i];
|
|
48
|
+
c = decoder[c];
|
|
49
|
+
if (c == -1)
|
|
50
|
+
continue;
|
|
51
|
+
if (c === undefined)
|
|
52
|
+
throw 'Illegal character at offset ' + i;
|
|
53
|
+
bits |= c;
|
|
54
|
+
if (++char_count >= 2) {
|
|
55
|
+
out[len++] = bits;
|
|
56
|
+
bits = 0;
|
|
57
|
+
char_count = 0;
|
|
58
|
+
} else {
|
|
59
|
+
bits <<= 4;
|
|
60
|
+
}
|
|
63
61
|
}
|
|
62
|
+
if (char_count)
|
|
63
|
+
throw 'Hex encoding incomplete: 4 bits missing';
|
|
64
|
+
if (haveU8 && out.length > len) // in case it was originally longer because of ignored characters
|
|
65
|
+
out = out.subarray(0, len);
|
|
66
|
+
return out;
|
|
64
67
|
}
|
|
65
|
-
if (char_count)
|
|
66
|
-
throw "Hex encoding incomplete: 4 bits missing";
|
|
67
|
-
if (haveU8 && out.length > len) // in case it was originally longer because of ignored characters
|
|
68
|
-
out = out.subarray(0, len);
|
|
69
|
-
return out;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return Hex;
|
|
73
68
|
|
|
74
|
-
}
|
|
69
|
+
}
|
package/int10.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Big integer base-10 printing library
|
|
2
|
-
// Copyright (c) 2008-
|
|
2
|
+
// Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
|
|
3
3
|
|
|
4
4
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
5
5
|
// purpose with or without fee is hereby granted, provided that the above
|
|
@@ -13,101 +13,94 @@
|
|
|
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
|
-
|
|
17
|
-
if (typeof module == 'object') module.exports = factory();
|
|
18
|
-
else window.int10 = factory();
|
|
19
|
-
})(function () {
|
|
20
|
-
"use strict";
|
|
16
|
+
let max = 10000000000000; // biggest 10^n integer that can still fit 2^53 when multiplied by 256
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
18
|
+
export class Int10 {
|
|
19
|
+
/**
|
|
20
|
+
* Arbitrary length base-10 value.
|
|
21
|
+
* @param {number} value - Optional initial value (will be 0 otherwise).
|
|
22
|
+
*/
|
|
23
|
+
constructor(value) {
|
|
24
|
+
this.buf = [+value || 0];
|
|
25
|
+
}
|
|
31
26
|
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Multiply value by m and add c.
|
|
29
|
+
* @param {number} m - multiplier, must be < =256
|
|
30
|
+
* @param {number} c - value to add
|
|
31
|
+
*/
|
|
32
|
+
mulAdd(m, c) {
|
|
33
|
+
// assert(m <= 256)
|
|
34
|
+
let b = this.buf,
|
|
35
|
+
l = b.length,
|
|
36
|
+
i, t;
|
|
37
|
+
for (i = 0; i < l; ++i) {
|
|
38
|
+
t = b[i] * m + c;
|
|
39
|
+
if (t < max)
|
|
40
|
+
c = 0;
|
|
41
|
+
else {
|
|
42
|
+
c = 0|(t / max);
|
|
43
|
+
t -= c * max;
|
|
44
|
+
}
|
|
45
|
+
b[i] = t;
|
|
49
46
|
}
|
|
50
|
-
|
|
47
|
+
if (c > 0)
|
|
48
|
+
b[i] = c;
|
|
51
49
|
}
|
|
52
|
-
if (c > 0)
|
|
53
|
-
b[i] = c;
|
|
54
|
-
};
|
|
55
50
|
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Subtract value.
|
|
53
|
+
* @param {number} c - value to subtract
|
|
54
|
+
*/
|
|
55
|
+
sub(c) {
|
|
56
|
+
let b = this.buf,
|
|
57
|
+
l = b.length,
|
|
58
|
+
i, t;
|
|
59
|
+
for (i = 0; i < l; ++i) {
|
|
60
|
+
t = b[i] - c;
|
|
61
|
+
if (t < 0) {
|
|
62
|
+
t += max;
|
|
63
|
+
c = 1;
|
|
64
|
+
} else
|
|
65
|
+
c = 0;
|
|
66
|
+
b[i] = t;
|
|
67
|
+
}
|
|
68
|
+
while (b[b.length - 1] === 0)
|
|
69
|
+
b.pop();
|
|
72
70
|
}
|
|
73
|
-
while (b[b.length - 1] === 0)
|
|
74
|
-
b.pop();
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Convert to decimal string representation.
|
|
79
|
-
* @param {*} base - optional value, only value accepted is 10
|
|
80
|
-
*/
|
|
81
|
-
Int10.prototype.toString = function (base) {
|
|
82
|
-
if ((base || 10) != 10)
|
|
83
|
-
throw 'only base 10 is supported';
|
|
84
|
-
var b = this.buf,
|
|
85
|
-
s = b[b.length - 1].toString();
|
|
86
|
-
for (var i = b.length - 2; i >= 0; --i)
|
|
87
|
-
s += (max + b[i]).toString().substring(1);
|
|
88
|
-
return s;
|
|
89
|
-
};
|
|
90
71
|
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Convert to decimal string representation.
|
|
74
|
+
* @param {*} base - optional value, only value accepted is 10
|
|
75
|
+
*/
|
|
76
|
+
toString(base) {
|
|
77
|
+
if ((base || 10) != 10)
|
|
78
|
+
throw 'only base 10 is supported';
|
|
79
|
+
let b = this.buf,
|
|
80
|
+
s = b[b.length - 1].toString();
|
|
81
|
+
for (let i = b.length - 2; i >= 0; --i)
|
|
82
|
+
s += (max + b[i]).toString().substring(1);
|
|
83
|
+
return s;
|
|
84
|
+
}
|
|
102
85
|
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Convert to Number value representation.
|
|
88
|
+
* Will probably overflow 2^53 and thus become approximate.
|
|
89
|
+
*/
|
|
90
|
+
valueOf() {
|
|
91
|
+
let b = this.buf,
|
|
92
|
+
v = 0;
|
|
93
|
+
for (let i = b.length - 1; i >= 0; --i)
|
|
94
|
+
v = v * max + b[i];
|
|
95
|
+
return v;
|
|
96
|
+
}
|
|
110
97
|
|
|
111
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Return value as a simple Number (if it is <= 10000000000000), or return this.
|
|
100
|
+
*/
|
|
101
|
+
simplify() {
|
|
102
|
+
let b = this.buf;
|
|
103
|
+
return (b.length == 1) ? b[0] : this;
|
|
104
|
+
}
|
|
112
105
|
|
|
113
|
-
}
|
|
106
|
+
}
|