@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/base64.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Base64 JavaScript decoder
2
- // Copyright (c) 2008-2022 Lapo Luchini <lapo@lapo.it>
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
- (typeof define != 'undefined' ? define : function (factory) { 'use strict';
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
- Base64.decode = function (a) {
27
- var isString = (typeof a == 'string');
28
- var i;
29
- if (decoder === undefined) {
30
- var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
31
- ignore = "= \f\n\r\t\u00A0\u2028\u2029";
32
- decoder = [];
33
- for (i = 0; i < 64; ++i)
34
- decoder[b64.charCodeAt(i)] = i;
35
- for (i = 0; i < ignore.length; ++i)
36
- decoder[ignore.charCodeAt(i)] = -1;
37
- // RFC 3548 URL & file safe encoding
38
- decoder['-'.charCodeAt(0)] = decoder['+'.charCodeAt(0)];
39
- decoder['_'.charCodeAt(0)] = decoder['/'.charCodeAt(0)];
40
- }
41
- var out = haveU8 ? new Uint8Array(a.length * 3 >> 2) : [];
42
- var bits = 0, char_count = 0, len = 0;
43
- for (i = 0; i < a.length; ++i) {
44
- var c = isString ? a.charCodeAt(i) : a[i];
45
- if (c == 61) // '='.charCodeAt(0)
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
- c = decoder[c];
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
- out[len++] = bits & 0xFF;
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
- Base64.pretty = function (str) {
80
- // fix padding
81
- if (str.length % 4 > 0)
82
- str = (str + '===').slice(0, str.length + str.length % 4);
83
- // convert RFC 3548 to standard Base64
84
- str = str.replace(/-/g, '+').replace(/_/g, '/');
85
- // 80 column width
86
- return str.replace(/(.{80})/g, '$1\n');
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
- Base64.re = /-----BEGIN [^-]+-----([A-Za-z0-9+/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+/=\s]+)====|^([A-Za-z0-9+/=\s]+)$/;
90
- Base64.unarmor = function (a) {
91
- var m = Base64.re.exec(a);
92
- if (m) {
93
- if (m[1])
94
- a = m[1];
95
- else if (m[2])
96
- a = m[2];
97
- else if (m[3])
98
- a = m[3];
99
- else
100
- throw "RegExp out of sync";
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
- return Base64;
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-2022 Lapo Luchini <lapo@lapo.it>
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
- (typeof define != 'undefined' ? define : function (factory) { 'use strict';
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
- * Decodes an hexadecimal value.
28
- * @param {string|Array|Uint8Array} a - a string representing hexadecimal data, or an array representation of its charcodes
29
- */
30
- Hex.decode = function(a) {
31
- var isString = (typeof a == 'string');
32
- var i;
33
- if (decoder === undefined) {
34
- var hex = "0123456789ABCDEF",
35
- ignore = " \f\n\r\t\u00A0\u2028\u2029";
36
- decoder = [];
37
- for (i = 0; i < 16; ++i)
38
- decoder[hex.charCodeAt(i)] = i;
39
- hex = hex.toLowerCase();
40
- for (i = 10; i < 16; ++i)
41
- decoder[hex.charCodeAt(i)] = i;
42
- for (i = 0; i < ignore.length; ++i)
43
- decoder[ignore.charCodeAt(i)] = -1;
44
- }
45
- var out = haveU8 ? new Uint8Array(a.length >> 1) : [],
46
- bits = 0,
47
- char_count = 0,
48
- len = 0;
49
- for (i = 0; i < a.length; ++i) {
50
- var c = isString ? a.charCodeAt(i) : a[i];
51
- c = decoder[c];
52
- if (c == -1)
53
- continue;
54
- if (c === undefined)
55
- throw 'Illegal character at offset ' + i;
56
- bits |= c;
57
- if (++char_count >= 2) {
58
- out[len++] = bits;
59
- bits = 0;
60
- char_count = 0;
61
- } else {
62
- bits <<= 4;
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-2022 Lapo Luchini <lapo@lapo.it>
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
- (typeof define != 'undefined' ? define : function (factory) { 'use strict';
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
- var max = 10000000000000; // biggest 10^n integer that can still fit 2^53 when multiplied by 256
23
-
24
- /**
25
- * Arbitrary length base-10 value.
26
- * @param {number} value - Optional initial value (will be 0 otherwise).
27
- */
28
- function Int10(value) {
29
- this.buf = [+value || 0];
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
- * Multiply value by m and add c.
34
- * @param {number} m - multiplier, must be < =256
35
- * @param {number} c - value to add
36
- */
37
- Int10.prototype.mulAdd = function (m, c) {
38
- // assert(m <= 256)
39
- var b = this.buf,
40
- l = b.length,
41
- i, t;
42
- for (i = 0; i < l; ++i) {
43
- t = b[i] * m + c;
44
- if (t < max)
45
- c = 0;
46
- else {
47
- c = 0|(t / max);
48
- t -= c * max;
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
- b[i] = t;
47
+ if (c > 0)
48
+ b[i] = c;
51
49
  }
52
- if (c > 0)
53
- b[i] = c;
54
- };
55
50
 
56
- /**
57
- * Subtract value.
58
- * @param {number} c - value to subtract
59
- */
60
- Int10.prototype.sub = function (c) {
61
- var b = this.buf,
62
- l = b.length,
63
- i, t;
64
- for (i = 0; i < l; ++i) {
65
- t = b[i] - c;
66
- if (t < 0) {
67
- t += max;
68
- c = 1;
69
- } else
70
- c = 0;
71
- b[i] = t;
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
- * Convert to Number value representation.
93
- * Will probably overflow 2^53 and thus become approximate.
94
- */
95
- Int10.prototype.valueOf = function () {
96
- var b = this.buf,
97
- v = 0;
98
- for (var i = b.length - 1; i >= 0; --i)
99
- v = v * max + b[i];
100
- return v;
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
- * Return value as a simple Number (if it is <= 10000000000000), or return this.
105
- */
106
- Int10.prototype.simplify = function () {
107
- var b = this.buf;
108
- return (b.length == 1) ? b[0] : this;
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
- return Int10;
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
+ }