qidian-shared 1.0.2 → 1.0.3

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.
@@ -398,7 +398,7 @@ function requireCore() {
398
398
  * var string = wordArray.toString(CryptoJS.enc.Utf8);
399
399
  */
400
400
  toString: function(encoder) {
401
- return (encoder || Hex).stringify(this);
401
+ return (encoder || Hex2).stringify(this);
402
402
  },
403
403
  /**
404
404
  * Concatenates a word array to this word array.
@@ -479,7 +479,7 @@ function requireCore() {
479
479
  }
480
480
  });
481
481
  var C_enc = C.enc = {};
482
- var Hex = C_enc.Hex = {
482
+ var Hex2 = C_enc.Hex = {
483
483
  /**
484
484
  * Converts a word array to a hex string.
485
485
  *
@@ -3216,7 +3216,7 @@ function requireCipherCore() {
3216
3216
  var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
3217
3217
  var C_enc = C.enc;
3218
3218
  C_enc.Utf8;
3219
- var Base64 = C_enc.Base64;
3219
+ var Base642 = C_enc.Base64;
3220
3220
  var C_algo = C.algo;
3221
3221
  var EvpKDF = C_algo.EvpKDF;
3222
3222
  var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
@@ -3626,7 +3626,7 @@ function requireCipherCore() {
3626
3626
  } else {
3627
3627
  wordArray = ciphertext;
3628
3628
  }
3629
- return wordArray.toString(Base64);
3629
+ return wordArray.toString(Base642);
3630
3630
  },
3631
3631
  /**
3632
3632
  * Converts an OpenSSL-compatible string to a cipher params object.
@@ -3643,7 +3643,7 @@ function requireCipherCore() {
3643
3643
  */
3644
3644
  parse: function(openSSLStr) {
3645
3645
  var salt;
3646
- var ciphertext = Base64.parse(openSSLStr);
3646
+ var ciphertext = Base642.parse(openSSLStr);
3647
3647
  var ciphertextWords = ciphertext.words;
3648
3648
  if (ciphertextWords[0] == 1398893684 && ciphertextWords[1] == 1701076831) {
3649
3649
  salt = WordArray.create(ciphertextWords.slice(2, 4));
@@ -4242,7 +4242,7 @@ function requireFormatHex() {
4242
4242
  var C_lib = C.lib;
4243
4243
  var CipherParams = C_lib.CipherParams;
4244
4244
  var C_enc = C.enc;
4245
- var Hex = C_enc.Hex;
4245
+ var Hex2 = C_enc.Hex;
4246
4246
  var C_format = C.format;
4247
4247
  C_format.Hex = {
4248
4248
  /**
@@ -4259,7 +4259,7 @@ function requireFormatHex() {
4259
4259
  * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
4260
4260
  */
4261
4261
  stringify: function(cipherParams) {
4262
- return cipherParams.ciphertext.toString(Hex);
4262
+ return cipherParams.ciphertext.toString(Hex2);
4263
4263
  },
4264
4264
  /**
4265
4265
  * Converts a hexadecimally encoded ciphertext string to a cipher params object.
@@ -4275,7 +4275,7 @@ function requireFormatHex() {
4275
4275
  * var cipherParams = CryptoJS.format.Hex.parse(hexString);
4276
4276
  */
4277
4277
  parse: function(input) {
4278
- var ciphertext = Hex.parse(input);
4278
+ var ciphertext = Hex2.parse(input);
4279
4279
  return CipherParams.create({ ciphertext });
4280
4280
  }
4281
4281
  };
@@ -6791,6 +6791,3918 @@ function encryptWithAes(message, aesKey, iv, mode = CryptoJS.mode.ECB, padding =
6791
6791
  });
6792
6792
  return encrypted.toString();
6793
6793
  }
6794
+ var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
6795
+ function int2char(n) {
6796
+ return BI_RM.charAt(n);
6797
+ }
6798
+ function op_and(x, y) {
6799
+ return x & y;
6800
+ }
6801
+ function op_or(x, y) {
6802
+ return x | y;
6803
+ }
6804
+ function op_xor(x, y) {
6805
+ return x ^ y;
6806
+ }
6807
+ function op_andnot(x, y) {
6808
+ return x & ~y;
6809
+ }
6810
+ function lbit(x) {
6811
+ if (x == 0) {
6812
+ return -1;
6813
+ }
6814
+ var r = 0;
6815
+ if ((x & 65535) == 0) {
6816
+ x >>= 16;
6817
+ r += 16;
6818
+ }
6819
+ if ((x & 255) == 0) {
6820
+ x >>= 8;
6821
+ r += 8;
6822
+ }
6823
+ if ((x & 15) == 0) {
6824
+ x >>= 4;
6825
+ r += 4;
6826
+ }
6827
+ if ((x & 3) == 0) {
6828
+ x >>= 2;
6829
+ r += 2;
6830
+ }
6831
+ if ((x & 1) == 0) {
6832
+ ++r;
6833
+ }
6834
+ return r;
6835
+ }
6836
+ function cbit(x) {
6837
+ var r = 0;
6838
+ while (x != 0) {
6839
+ x &= x - 1;
6840
+ ++r;
6841
+ }
6842
+ return r;
6843
+ }
6844
+ var b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
6845
+ var b64pad = "=";
6846
+ function hex2b64(h) {
6847
+ var i;
6848
+ var c;
6849
+ var ret = "";
6850
+ for (i = 0; i + 3 <= h.length; i += 3) {
6851
+ c = parseInt(h.substring(i, i + 3), 16);
6852
+ ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
6853
+ }
6854
+ if (i + 1 == h.length) {
6855
+ c = parseInt(h.substring(i, i + 1), 16);
6856
+ ret += b64map.charAt(c << 2);
6857
+ } else if (i + 2 == h.length) {
6858
+ c = parseInt(h.substring(i, i + 2), 16);
6859
+ ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
6860
+ }
6861
+ while ((ret.length & 3) > 0) {
6862
+ ret += b64pad;
6863
+ }
6864
+ return ret;
6865
+ }
6866
+ function b64tohex(s) {
6867
+ var ret = "";
6868
+ var i;
6869
+ var k = 0;
6870
+ var slop = 0;
6871
+ for (i = 0; i < s.length; ++i) {
6872
+ if (s.charAt(i) == b64pad) {
6873
+ break;
6874
+ }
6875
+ var v = b64map.indexOf(s.charAt(i));
6876
+ if (v < 0) {
6877
+ continue;
6878
+ }
6879
+ if (k == 0) {
6880
+ ret += int2char(v >> 2);
6881
+ slop = v & 3;
6882
+ k = 1;
6883
+ } else if (k == 1) {
6884
+ ret += int2char(slop << 2 | v >> 4);
6885
+ slop = v & 15;
6886
+ k = 2;
6887
+ } else if (k == 2) {
6888
+ ret += int2char(slop);
6889
+ ret += int2char(v >> 2);
6890
+ slop = v & 3;
6891
+ k = 3;
6892
+ } else {
6893
+ ret += int2char(slop << 2 | v >> 4);
6894
+ ret += int2char(v & 15);
6895
+ k = 0;
6896
+ }
6897
+ }
6898
+ if (k == 1) {
6899
+ ret += int2char(slop << 2);
6900
+ }
6901
+ return ret;
6902
+ }
6903
+ var decoder$1;
6904
+ var Hex = {
6905
+ decode: function(a) {
6906
+ var i;
6907
+ if (decoder$1 === void 0) {
6908
+ var hex = "0123456789ABCDEF";
6909
+ var ignore = " \f\n\r  \u2028\u2029";
6910
+ decoder$1 = {};
6911
+ for (i = 0; i < 16; ++i) {
6912
+ decoder$1[hex.charAt(i)] = i;
6913
+ }
6914
+ hex = hex.toLowerCase();
6915
+ for (i = 10; i < 16; ++i) {
6916
+ decoder$1[hex.charAt(i)] = i;
6917
+ }
6918
+ for (i = 0; i < ignore.length; ++i) {
6919
+ decoder$1[ignore.charAt(i)] = -1;
6920
+ }
6921
+ }
6922
+ var out = [];
6923
+ var bits = 0;
6924
+ var char_count = 0;
6925
+ for (i = 0; i < a.length; ++i) {
6926
+ var c = a.charAt(i);
6927
+ if (c == "=") {
6928
+ break;
6929
+ }
6930
+ c = decoder$1[c];
6931
+ if (c == -1) {
6932
+ continue;
6933
+ }
6934
+ if (c === void 0) {
6935
+ throw new Error("Illegal character at offset " + i);
6936
+ }
6937
+ bits |= c;
6938
+ if (++char_count >= 2) {
6939
+ out[out.length] = bits;
6940
+ bits = 0;
6941
+ char_count = 0;
6942
+ } else {
6943
+ bits <<= 4;
6944
+ }
6945
+ }
6946
+ if (char_count) {
6947
+ throw new Error("Hex encoding incomplete: 4 bits missing");
6948
+ }
6949
+ return out;
6950
+ }
6951
+ };
6952
+ var decoder;
6953
+ var Base64 = {
6954
+ decode: function(a) {
6955
+ var i;
6956
+ if (decoder === void 0) {
6957
+ var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
6958
+ var ignore = "= \f\n\r  \u2028\u2029";
6959
+ decoder = /* @__PURE__ */ Object.create(null);
6960
+ for (i = 0; i < 64; ++i) {
6961
+ decoder[b64.charAt(i)] = i;
6962
+ }
6963
+ decoder["-"] = 62;
6964
+ decoder["_"] = 63;
6965
+ for (i = 0; i < ignore.length; ++i) {
6966
+ decoder[ignore.charAt(i)] = -1;
6967
+ }
6968
+ }
6969
+ var out = [];
6970
+ var bits = 0;
6971
+ var char_count = 0;
6972
+ for (i = 0; i < a.length; ++i) {
6973
+ var c = a.charAt(i);
6974
+ if (c == "=") {
6975
+ break;
6976
+ }
6977
+ c = decoder[c];
6978
+ if (c == -1) {
6979
+ continue;
6980
+ }
6981
+ if (c === void 0) {
6982
+ throw new Error("Illegal character at offset " + i);
6983
+ }
6984
+ bits |= c;
6985
+ if (++char_count >= 4) {
6986
+ out[out.length] = bits >> 16;
6987
+ out[out.length] = bits >> 8 & 255;
6988
+ out[out.length] = bits & 255;
6989
+ bits = 0;
6990
+ char_count = 0;
6991
+ } else {
6992
+ bits <<= 6;
6993
+ }
6994
+ }
6995
+ switch (char_count) {
6996
+ case 1:
6997
+ throw new Error("Base64 encoding incomplete: at least 2 bits missing");
6998
+ case 2:
6999
+ out[out.length] = bits >> 10;
7000
+ break;
7001
+ case 3:
7002
+ out[out.length] = bits >> 16;
7003
+ out[out.length] = bits >> 8 & 255;
7004
+ break;
7005
+ }
7006
+ return out;
7007
+ },
7008
+ re: /-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,
7009
+ unarmor: function(a) {
7010
+ var m = Base64.re.exec(a);
7011
+ if (m) {
7012
+ if (m[1]) {
7013
+ a = m[1];
7014
+ } else if (m[2]) {
7015
+ a = m[2];
7016
+ } else {
7017
+ throw new Error("RegExp out of sync");
7018
+ }
7019
+ }
7020
+ return Base64.decode(a);
7021
+ }
7022
+ };
7023
+ var max = 1e13;
7024
+ var Int10 = (
7025
+ /** @class */
7026
+ (function() {
7027
+ function Int102(value) {
7028
+ this.buf = [+value || 0];
7029
+ }
7030
+ Int102.prototype.mulAdd = function(m, c) {
7031
+ var b = this.buf;
7032
+ var l = b.length;
7033
+ var i;
7034
+ var t;
7035
+ for (i = 0; i < l; ++i) {
7036
+ t = b[i] * m + c;
7037
+ if (t < max) {
7038
+ c = 0;
7039
+ } else {
7040
+ c = 0 | t / max;
7041
+ t -= c * max;
7042
+ }
7043
+ b[i] = t;
7044
+ }
7045
+ if (c > 0) {
7046
+ b[i] = c;
7047
+ }
7048
+ };
7049
+ Int102.prototype.sub = function(c) {
7050
+ var b = this.buf;
7051
+ var l = b.length;
7052
+ var i;
7053
+ var t;
7054
+ for (i = 0; i < l; ++i) {
7055
+ t = b[i] - c;
7056
+ if (t < 0) {
7057
+ t += max;
7058
+ c = 1;
7059
+ } else {
7060
+ c = 0;
7061
+ }
7062
+ b[i] = t;
7063
+ }
7064
+ while (b[b.length - 1] === 0) {
7065
+ b.pop();
7066
+ }
7067
+ };
7068
+ Int102.prototype.toString = function(base) {
7069
+ if ((base || 10) != 10) {
7070
+ throw new Error("only base 10 is supported");
7071
+ }
7072
+ var b = this.buf;
7073
+ var s = b[b.length - 1].toString();
7074
+ for (var i = b.length - 2; i >= 0; --i) {
7075
+ s += (max + b[i]).toString().substring(1);
7076
+ }
7077
+ return s;
7078
+ };
7079
+ Int102.prototype.valueOf = function() {
7080
+ var b = this.buf;
7081
+ var v = 0;
7082
+ for (var i = b.length - 1; i >= 0; --i) {
7083
+ v = v * max + b[i];
7084
+ }
7085
+ return v;
7086
+ };
7087
+ Int102.prototype.simplify = function() {
7088
+ var b = this.buf;
7089
+ return b.length == 1 ? b[0] : this;
7090
+ };
7091
+ return Int102;
7092
+ })()
7093
+ );
7094
+ var ellipsis = "…";
7095
+ var 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-5]\d)?)?$/;
7096
+ var 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-5]\d)?)?$/;
7097
+ function stringCut(str, len) {
7098
+ if (str.length > len) {
7099
+ str = str.substring(0, len) + ellipsis;
7100
+ }
7101
+ return str;
7102
+ }
7103
+ var Stream = (
7104
+ /** @class */
7105
+ (function() {
7106
+ function Stream2(enc, pos) {
7107
+ this.hexDigits = "0123456789ABCDEF";
7108
+ if (enc instanceof Stream2) {
7109
+ this.enc = enc.enc;
7110
+ this.pos = enc.pos;
7111
+ } else {
7112
+ this.enc = enc;
7113
+ this.pos = pos;
7114
+ }
7115
+ }
7116
+ Stream2.prototype.get = function(pos) {
7117
+ if (pos === void 0) {
7118
+ pos = this.pos++;
7119
+ }
7120
+ if (pos >= this.enc.length) {
7121
+ throw new Error("Requesting byte offset ".concat(pos, " on a stream of length ").concat(this.enc.length));
7122
+ }
7123
+ return "string" === typeof this.enc ? this.enc.charCodeAt(pos) : this.enc[pos];
7124
+ };
7125
+ Stream2.prototype.hexByte = function(b) {
7126
+ return this.hexDigits.charAt(b >> 4 & 15) + this.hexDigits.charAt(b & 15);
7127
+ };
7128
+ Stream2.prototype.hexDump = function(start, end, raw) {
7129
+ var s = "";
7130
+ for (var i = start; i < end; ++i) {
7131
+ s += this.hexByte(this.get(i));
7132
+ if (raw !== true) {
7133
+ switch (i & 15) {
7134
+ case 7:
7135
+ s += " ";
7136
+ break;
7137
+ case 15:
7138
+ s += "\n";
7139
+ break;
7140
+ default:
7141
+ s += " ";
7142
+ }
7143
+ }
7144
+ }
7145
+ return s;
7146
+ };
7147
+ Stream2.prototype.isASCII = function(start, end) {
7148
+ for (var i = start; i < end; ++i) {
7149
+ var c = this.get(i);
7150
+ if (c < 32 || c > 176) {
7151
+ return false;
7152
+ }
7153
+ }
7154
+ return true;
7155
+ };
7156
+ Stream2.prototype.parseStringISO = function(start, end) {
7157
+ var s = "";
7158
+ for (var i = start; i < end; ++i) {
7159
+ s += String.fromCharCode(this.get(i));
7160
+ }
7161
+ return s;
7162
+ };
7163
+ Stream2.prototype.parseStringUTF = function(start, end) {
7164
+ var s = "";
7165
+ for (var i = start; i < end; ) {
7166
+ var c = this.get(i++);
7167
+ if (c < 128) {
7168
+ s += String.fromCharCode(c);
7169
+ } else if (c > 191 && c < 224) {
7170
+ s += String.fromCharCode((c & 31) << 6 | this.get(i++) & 63);
7171
+ } else {
7172
+ s += String.fromCharCode((c & 15) << 12 | (this.get(i++) & 63) << 6 | this.get(i++) & 63);
7173
+ }
7174
+ }
7175
+ return s;
7176
+ };
7177
+ Stream2.prototype.parseStringBMP = function(start, end) {
7178
+ var str = "";
7179
+ var hi;
7180
+ var lo;
7181
+ for (var i = start; i < end; ) {
7182
+ hi = this.get(i++);
7183
+ lo = this.get(i++);
7184
+ str += String.fromCharCode(hi << 8 | lo);
7185
+ }
7186
+ return str;
7187
+ };
7188
+ Stream2.prototype.parseTime = function(start, end, shortYear) {
7189
+ var s = this.parseStringISO(start, end);
7190
+ var m = (shortYear ? reTimeS : reTimeL).exec(s);
7191
+ if (!m) {
7192
+ return "Unrecognized time: " + s;
7193
+ }
7194
+ if (shortYear) {
7195
+ m[1] = +m[1];
7196
+ m[1] += +m[1] < 70 ? 2e3 : 1900;
7197
+ }
7198
+ s = m[1] + "-" + m[2] + "-" + m[3] + " " + m[4];
7199
+ if (m[5]) {
7200
+ s += ":" + m[5];
7201
+ if (m[6]) {
7202
+ s += ":" + m[6];
7203
+ if (m[7]) {
7204
+ s += "." + m[7];
7205
+ }
7206
+ }
7207
+ }
7208
+ if (m[8]) {
7209
+ s += " UTC";
7210
+ if (m[8] != "Z") {
7211
+ s += m[8];
7212
+ if (m[9]) {
7213
+ s += ":" + m[9];
7214
+ }
7215
+ }
7216
+ }
7217
+ return s;
7218
+ };
7219
+ Stream2.prototype.parseInteger = function(start, end) {
7220
+ var v = this.get(start);
7221
+ var neg = v > 127;
7222
+ var pad = neg ? 255 : 0;
7223
+ var len;
7224
+ var s = "";
7225
+ while (v == pad && ++start < end) {
7226
+ v = this.get(start);
7227
+ }
7228
+ len = end - start;
7229
+ if (len === 0) {
7230
+ return neg ? -1 : 0;
7231
+ }
7232
+ if (len > 4) {
7233
+ s = v;
7234
+ len <<= 3;
7235
+ while (((+s ^ pad) & 128) == 0) {
7236
+ s = +s << 1;
7237
+ --len;
7238
+ }
7239
+ s = "(" + len + " bit)\n";
7240
+ }
7241
+ if (neg) {
7242
+ v = v - 256;
7243
+ }
7244
+ var n = new Int10(v);
7245
+ for (var i = start + 1; i < end; ++i) {
7246
+ n.mulAdd(256, this.get(i));
7247
+ }
7248
+ return s + n.toString();
7249
+ };
7250
+ Stream2.prototype.parseBitString = function(start, end, maxLength) {
7251
+ var unusedBit = this.get(start);
7252
+ var lenBit = (end - start - 1 << 3) - unusedBit;
7253
+ var intro = "(" + lenBit + " bit)\n";
7254
+ var s = "";
7255
+ for (var i = start + 1; i < end; ++i) {
7256
+ var b = this.get(i);
7257
+ var skip = i == end - 1 ? unusedBit : 0;
7258
+ for (var j = 7; j >= skip; --j) {
7259
+ s += b >> j & 1 ? "1" : "0";
7260
+ }
7261
+ if (s.length > maxLength) {
7262
+ return intro + stringCut(s, maxLength);
7263
+ }
7264
+ }
7265
+ return intro + s;
7266
+ };
7267
+ Stream2.prototype.parseOctetString = function(start, end, maxLength) {
7268
+ if (this.isASCII(start, end)) {
7269
+ return stringCut(this.parseStringISO(start, end), maxLength);
7270
+ }
7271
+ var len = end - start;
7272
+ var s = "(" + len + " byte)\n";
7273
+ maxLength /= 2;
7274
+ if (len > maxLength) {
7275
+ end = start + maxLength;
7276
+ }
7277
+ for (var i = start; i < end; ++i) {
7278
+ s += this.hexByte(this.get(i));
7279
+ }
7280
+ if (len > maxLength) {
7281
+ s += ellipsis;
7282
+ }
7283
+ return s;
7284
+ };
7285
+ Stream2.prototype.parseOID = function(start, end, maxLength) {
7286
+ var s = "";
7287
+ var n = new Int10();
7288
+ var bits = 0;
7289
+ for (var i = start; i < end; ++i) {
7290
+ var v = this.get(i);
7291
+ n.mulAdd(128, v & 127);
7292
+ bits += 7;
7293
+ if (!(v & 128)) {
7294
+ if (s === "") {
7295
+ n = n.simplify();
7296
+ if (n instanceof Int10) {
7297
+ n.sub(80);
7298
+ s = "2." + n.toString();
7299
+ } else {
7300
+ var m = n < 80 ? n < 40 ? 0 : 1 : 2;
7301
+ s = m + "." + (n - m * 40);
7302
+ }
7303
+ } else {
7304
+ s += "." + n.toString();
7305
+ }
7306
+ if (s.length > maxLength) {
7307
+ return stringCut(s, maxLength);
7308
+ }
7309
+ n = new Int10();
7310
+ bits = 0;
7311
+ }
7312
+ }
7313
+ if (bits > 0) {
7314
+ s += ".incomplete";
7315
+ }
7316
+ return s;
7317
+ };
7318
+ return Stream2;
7319
+ })()
7320
+ );
7321
+ var ASN1 = (
7322
+ /** @class */
7323
+ (function() {
7324
+ function ASN12(stream, header, length, tag, sub) {
7325
+ if (!(tag instanceof ASN1Tag)) {
7326
+ throw new Error("Invalid tag value.");
7327
+ }
7328
+ this.stream = stream;
7329
+ this.header = header;
7330
+ this.length = length;
7331
+ this.tag = tag;
7332
+ this.sub = sub;
7333
+ }
7334
+ ASN12.prototype.typeName = function() {
7335
+ switch (this.tag.tagClass) {
7336
+ case 0:
7337
+ switch (this.tag.tagNumber) {
7338
+ case 0:
7339
+ return "EOC";
7340
+ case 1:
7341
+ return "BOOLEAN";
7342
+ case 2:
7343
+ return "INTEGER";
7344
+ case 3:
7345
+ return "BIT_STRING";
7346
+ case 4:
7347
+ return "OCTET_STRING";
7348
+ case 5:
7349
+ return "NULL";
7350
+ case 6:
7351
+ return "OBJECT_IDENTIFIER";
7352
+ case 7:
7353
+ return "ObjectDescriptor";
7354
+ case 8:
7355
+ return "EXTERNAL";
7356
+ case 9:
7357
+ return "REAL";
7358
+ case 10:
7359
+ return "ENUMERATED";
7360
+ case 11:
7361
+ return "EMBEDDED_PDV";
7362
+ case 12:
7363
+ return "UTF8String";
7364
+ case 16:
7365
+ return "SEQUENCE";
7366
+ case 17:
7367
+ return "SET";
7368
+ case 18:
7369
+ return "NumericString";
7370
+ case 19:
7371
+ return "PrintableString";
7372
+ // ASCII subset
7373
+ case 20:
7374
+ return "TeletexString";
7375
+ // aka T61String
7376
+ case 21:
7377
+ return "VideotexString";
7378
+ case 22:
7379
+ return "IA5String";
7380
+ // ASCII
7381
+ case 23:
7382
+ return "UTCTime";
7383
+ case 24:
7384
+ return "GeneralizedTime";
7385
+ case 25:
7386
+ return "GraphicString";
7387
+ case 26:
7388
+ return "VisibleString";
7389
+ // ASCII subset
7390
+ case 27:
7391
+ return "GeneralString";
7392
+ case 28:
7393
+ return "UniversalString";
7394
+ case 30:
7395
+ return "BMPString";
7396
+ }
7397
+ return "Universal_" + this.tag.tagNumber.toString();
7398
+ case 1:
7399
+ return "Application_" + this.tag.tagNumber.toString();
7400
+ case 2:
7401
+ return "[" + this.tag.tagNumber.toString() + "]";
7402
+ // Context
7403
+ case 3:
7404
+ return "Private_" + this.tag.tagNumber.toString();
7405
+ }
7406
+ };
7407
+ ASN12.prototype.content = function(maxLength) {
7408
+ if (this.tag === void 0) {
7409
+ return null;
7410
+ }
7411
+ if (maxLength === void 0) {
7412
+ maxLength = Infinity;
7413
+ }
7414
+ var content = this.posContent();
7415
+ var len = Math.abs(this.length);
7416
+ if (!this.tag.isUniversal()) {
7417
+ if (this.sub !== null) {
7418
+ return "(" + this.sub.length + " elem)";
7419
+ }
7420
+ return this.stream.parseOctetString(content, content + len, maxLength);
7421
+ }
7422
+ switch (this.tag.tagNumber) {
7423
+ case 1:
7424
+ return this.stream.get(content) === 0 ? "false" : "true";
7425
+ case 2:
7426
+ return this.stream.parseInteger(content, content + len);
7427
+ case 3:
7428
+ return this.sub ? "(" + this.sub.length + " elem)" : this.stream.parseBitString(content, content + len, maxLength);
7429
+ case 4:
7430
+ return this.sub ? "(" + this.sub.length + " elem)" : this.stream.parseOctetString(content, content + len, maxLength);
7431
+ // case 0x05: // NULL
7432
+ case 6:
7433
+ return this.stream.parseOID(content, content + len, maxLength);
7434
+ // case 0x07: // ObjectDescriptor
7435
+ // case 0x08: // EXTERNAL
7436
+ // case 0x09: // REAL
7437
+ // case 0x0A: // ENUMERATED
7438
+ // case 0x0B: // EMBEDDED_PDV
7439
+ case 16:
7440
+ // SEQUENCE
7441
+ case 17:
7442
+ if (this.sub !== null) {
7443
+ return "(" + this.sub.length + " elem)";
7444
+ } else {
7445
+ return "(no elem)";
7446
+ }
7447
+ case 12:
7448
+ return stringCut(this.stream.parseStringUTF(content, content + len), maxLength);
7449
+ case 18:
7450
+ // NumericString
7451
+ case 19:
7452
+ // PrintableString
7453
+ case 20:
7454
+ // TeletexString
7455
+ case 21:
7456
+ // VideotexString
7457
+ case 22:
7458
+ // IA5String
7459
+ // case 0x19: // GraphicString
7460
+ case 26:
7461
+ return stringCut(this.stream.parseStringISO(content, content + len), maxLength);
7462
+ case 30:
7463
+ return stringCut(this.stream.parseStringBMP(content, content + len), maxLength);
7464
+ case 23:
7465
+ // UTCTime
7466
+ case 24:
7467
+ return this.stream.parseTime(content, content + len, this.tag.tagNumber == 23);
7468
+ }
7469
+ return null;
7470
+ };
7471
+ ASN12.prototype.toString = function() {
7472
+ return this.typeName() + "@" + this.stream.pos + "[header:" + this.header + ",length:" + this.length + ",sub:" + (this.sub === null ? "null" : this.sub.length) + "]";
7473
+ };
7474
+ ASN12.prototype.toPrettyString = function(indent) {
7475
+ if (indent === void 0) {
7476
+ indent = "";
7477
+ }
7478
+ var s = indent + this.typeName() + " @" + this.stream.pos;
7479
+ if (this.length >= 0) {
7480
+ s += "+";
7481
+ }
7482
+ s += this.length;
7483
+ if (this.tag.tagConstructed) {
7484
+ s += " (constructed)";
7485
+ } else if (this.tag.isUniversal() && (this.tag.tagNumber == 3 || this.tag.tagNumber == 4) && this.sub !== null) {
7486
+ s += " (encapsulates)";
7487
+ }
7488
+ s += "\n";
7489
+ if (this.sub !== null) {
7490
+ indent += " ";
7491
+ for (var i = 0, max2 = this.sub.length; i < max2; ++i) {
7492
+ s += this.sub[i].toPrettyString(indent);
7493
+ }
7494
+ }
7495
+ return s;
7496
+ };
7497
+ ASN12.prototype.posStart = function() {
7498
+ return this.stream.pos;
7499
+ };
7500
+ ASN12.prototype.posContent = function() {
7501
+ return this.stream.pos + this.header;
7502
+ };
7503
+ ASN12.prototype.posEnd = function() {
7504
+ return this.stream.pos + this.header + Math.abs(this.length);
7505
+ };
7506
+ ASN12.prototype.toHexString = function() {
7507
+ return this.stream.hexDump(this.posStart(), this.posEnd(), true);
7508
+ };
7509
+ ASN12.decodeLength = function(stream) {
7510
+ var buf = stream.get();
7511
+ var len = buf & 127;
7512
+ if (len == buf) {
7513
+ return len;
7514
+ }
7515
+ if (len > 6) {
7516
+ throw new Error("Length over 48 bits not supported at position " + (stream.pos - 1));
7517
+ }
7518
+ if (len === 0) {
7519
+ return null;
7520
+ }
7521
+ buf = 0;
7522
+ for (var i = 0; i < len; ++i) {
7523
+ buf = buf * 256 + stream.get();
7524
+ }
7525
+ return buf;
7526
+ };
7527
+ ASN12.prototype.getHexStringValue = function() {
7528
+ var hexString = this.toHexString();
7529
+ var offset = this.header * 2;
7530
+ var length = this.length * 2;
7531
+ return hexString.substring(offset, offset + length);
7532
+ };
7533
+ ASN12.decode = function(str) {
7534
+ var stream;
7535
+ if (!(str instanceof Stream)) {
7536
+ stream = new Stream(str, 0);
7537
+ } else {
7538
+ stream = str;
7539
+ }
7540
+ var streamStart = new Stream(stream);
7541
+ var tag = new ASN1Tag(stream);
7542
+ var len = ASN12.decodeLength(stream);
7543
+ var start = stream.pos;
7544
+ var header = start - streamStart.pos;
7545
+ var sub = null;
7546
+ var getSub = function() {
7547
+ var ret = [];
7548
+ if (len !== null) {
7549
+ var end = start + len;
7550
+ while (stream.pos < end) {
7551
+ ret[ret.length] = ASN12.decode(stream);
7552
+ }
7553
+ if (stream.pos != end) {
7554
+ throw new Error("Content size is not correct for container starting at offset " + start);
7555
+ }
7556
+ } else {
7557
+ try {
7558
+ for (; ; ) {
7559
+ var s = ASN12.decode(stream);
7560
+ if (s.tag.isEOC()) {
7561
+ break;
7562
+ }
7563
+ ret[ret.length] = s;
7564
+ }
7565
+ len = start - stream.pos;
7566
+ } catch (e) {
7567
+ throw new Error("Exception while decoding undefined length content: " + e);
7568
+ }
7569
+ }
7570
+ return ret;
7571
+ };
7572
+ if (tag.tagConstructed) {
7573
+ sub = getSub();
7574
+ } else if (tag.isUniversal() && (tag.tagNumber == 3 || tag.tagNumber == 4)) {
7575
+ try {
7576
+ if (tag.tagNumber == 3) {
7577
+ if (stream.get() != 0) {
7578
+ throw new Error("BIT STRINGs with unused bits cannot encapsulate.");
7579
+ }
7580
+ }
7581
+ sub = getSub();
7582
+ for (var i = 0; i < sub.length; ++i) {
7583
+ if (sub[i].tag.isEOC()) {
7584
+ throw new Error("EOC is not supposed to be actual content.");
7585
+ }
7586
+ }
7587
+ } catch (e) {
7588
+ sub = null;
7589
+ }
7590
+ }
7591
+ if (sub === null) {
7592
+ if (len === null) {
7593
+ throw new Error("We can't skip over an invalid tag with undefined length at offset " + start);
7594
+ }
7595
+ stream.pos = start + Math.abs(len);
7596
+ }
7597
+ return new ASN12(streamStart, header, len, tag, sub);
7598
+ };
7599
+ return ASN12;
7600
+ })()
7601
+ );
7602
+ var ASN1Tag = (
7603
+ /** @class */
7604
+ (function() {
7605
+ function ASN1Tag2(stream) {
7606
+ var buf = stream.get();
7607
+ this.tagClass = buf >> 6;
7608
+ this.tagConstructed = (buf & 32) !== 0;
7609
+ this.tagNumber = buf & 31;
7610
+ if (this.tagNumber == 31) {
7611
+ var n = new Int10();
7612
+ do {
7613
+ buf = stream.get();
7614
+ n.mulAdd(128, buf & 127);
7615
+ } while (buf & 128);
7616
+ this.tagNumber = n.simplify();
7617
+ }
7618
+ }
7619
+ ASN1Tag2.prototype.isUniversal = function() {
7620
+ return this.tagClass === 0;
7621
+ };
7622
+ ASN1Tag2.prototype.isEOC = function() {
7623
+ return this.tagClass === 0 && this.tagNumber === 0;
7624
+ };
7625
+ return ASN1Tag2;
7626
+ })()
7627
+ );
7628
+ var dbits;
7629
+ var canary = 244837814094590;
7630
+ var j_lm = (canary & 16777215) == 15715070;
7631
+ var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
7632
+ var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
7633
+ var BigInteger = (
7634
+ /** @class */
7635
+ (function() {
7636
+ function BigInteger2(a, b, c) {
7637
+ if (a != null) {
7638
+ if ("number" == typeof a) {
7639
+ this.fromNumber(a, b, c);
7640
+ } else if (b == null && "string" != typeof a) {
7641
+ this.fromString(a, 256);
7642
+ } else {
7643
+ this.fromString(a, b);
7644
+ }
7645
+ }
7646
+ }
7647
+ BigInteger2.prototype.toString = function(b) {
7648
+ if (this.s < 0) {
7649
+ return "-" + this.negate().toString(b);
7650
+ }
7651
+ var k;
7652
+ if (b == 16) {
7653
+ k = 4;
7654
+ } else if (b == 8) {
7655
+ k = 3;
7656
+ } else if (b == 2) {
7657
+ k = 1;
7658
+ } else if (b == 32) {
7659
+ k = 5;
7660
+ } else if (b == 4) {
7661
+ k = 2;
7662
+ } else {
7663
+ return this.toRadix(b);
7664
+ }
7665
+ var km = (1 << k) - 1;
7666
+ var d;
7667
+ var m = false;
7668
+ var r = "";
7669
+ var i = this.t;
7670
+ var p = this.DB - i * this.DB % k;
7671
+ if (i-- > 0) {
7672
+ if (p < this.DB && (d = this[i] >> p) > 0) {
7673
+ m = true;
7674
+ r = int2char(d);
7675
+ }
7676
+ while (i >= 0) {
7677
+ if (p < k) {
7678
+ d = (this[i] & (1 << p) - 1) << k - p;
7679
+ d |= this[--i] >> (p += this.DB - k);
7680
+ } else {
7681
+ d = this[i] >> (p -= k) & km;
7682
+ if (p <= 0) {
7683
+ p += this.DB;
7684
+ --i;
7685
+ }
7686
+ }
7687
+ if (d > 0) {
7688
+ m = true;
7689
+ }
7690
+ if (m) {
7691
+ r += int2char(d);
7692
+ }
7693
+ }
7694
+ }
7695
+ return m ? r : "0";
7696
+ };
7697
+ BigInteger2.prototype.negate = function() {
7698
+ var r = nbi();
7699
+ BigInteger2.ZERO.subTo(this, r);
7700
+ return r;
7701
+ };
7702
+ BigInteger2.prototype.abs = function() {
7703
+ return this.s < 0 ? this.negate() : this;
7704
+ };
7705
+ BigInteger2.prototype.compareTo = function(a) {
7706
+ var r = this.s - a.s;
7707
+ if (r != 0) {
7708
+ return r;
7709
+ }
7710
+ var i = this.t;
7711
+ r = i - a.t;
7712
+ if (r != 0) {
7713
+ return this.s < 0 ? -r : r;
7714
+ }
7715
+ while (--i >= 0) {
7716
+ if ((r = this[i] - a[i]) != 0) {
7717
+ return r;
7718
+ }
7719
+ }
7720
+ return 0;
7721
+ };
7722
+ BigInteger2.prototype.bitLength = function() {
7723
+ if (this.t <= 0) {
7724
+ return 0;
7725
+ }
7726
+ return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM);
7727
+ };
7728
+ BigInteger2.prototype.mod = function(a) {
7729
+ var r = nbi();
7730
+ this.abs().divRemTo(a, null, r);
7731
+ if (this.s < 0 && r.compareTo(BigInteger2.ZERO) > 0) {
7732
+ a.subTo(r, r);
7733
+ }
7734
+ return r;
7735
+ };
7736
+ BigInteger2.prototype.modPowInt = function(e, m) {
7737
+ var z;
7738
+ if (e < 256 || m.isEven()) {
7739
+ z = new Classic(m);
7740
+ } else {
7741
+ z = new Montgomery(m);
7742
+ }
7743
+ return this.exp(e, z);
7744
+ };
7745
+ BigInteger2.prototype.clone = function() {
7746
+ var r = nbi();
7747
+ this.copyTo(r);
7748
+ return r;
7749
+ };
7750
+ BigInteger2.prototype.intValue = function() {
7751
+ if (this.s < 0) {
7752
+ if (this.t == 1) {
7753
+ return this[0] - this.DV;
7754
+ } else if (this.t == 0) {
7755
+ return -1;
7756
+ }
7757
+ } else if (this.t == 1) {
7758
+ return this[0];
7759
+ } else if (this.t == 0) {
7760
+ return 0;
7761
+ }
7762
+ return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0];
7763
+ };
7764
+ BigInteger2.prototype.byteValue = function() {
7765
+ return this.t == 0 ? this.s : this[0] << 24 >> 24;
7766
+ };
7767
+ BigInteger2.prototype.shortValue = function() {
7768
+ return this.t == 0 ? this.s : this[0] << 16 >> 16;
7769
+ };
7770
+ BigInteger2.prototype.signum = function() {
7771
+ if (this.s < 0) {
7772
+ return -1;
7773
+ } else if (this.t <= 0 || this.t == 1 && this[0] <= 0) {
7774
+ return 0;
7775
+ } else {
7776
+ return 1;
7777
+ }
7778
+ };
7779
+ BigInteger2.prototype.toByteArray = function() {
7780
+ var i = this.t;
7781
+ var r = [];
7782
+ r[0] = this.s;
7783
+ var p = this.DB - i * this.DB % 8;
7784
+ var d;
7785
+ var k = 0;
7786
+ if (i-- > 0) {
7787
+ if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) {
7788
+ r[k++] = d | this.s << this.DB - p;
7789
+ }
7790
+ while (i >= 0) {
7791
+ if (p < 8) {
7792
+ d = (this[i] & (1 << p) - 1) << 8 - p;
7793
+ d |= this[--i] >> (p += this.DB - 8);
7794
+ } else {
7795
+ d = this[i] >> (p -= 8) & 255;
7796
+ if (p <= 0) {
7797
+ p += this.DB;
7798
+ --i;
7799
+ }
7800
+ }
7801
+ if ((d & 128) != 0) {
7802
+ d |= -256;
7803
+ }
7804
+ if (k == 0 && (this.s & 128) != (d & 128)) {
7805
+ ++k;
7806
+ }
7807
+ if (k > 0 || d != this.s) {
7808
+ r[k++] = d;
7809
+ }
7810
+ }
7811
+ }
7812
+ return r;
7813
+ };
7814
+ BigInteger2.prototype.equals = function(a) {
7815
+ return this.compareTo(a) == 0;
7816
+ };
7817
+ BigInteger2.prototype.min = function(a) {
7818
+ return this.compareTo(a) < 0 ? this : a;
7819
+ };
7820
+ BigInteger2.prototype.max = function(a) {
7821
+ return this.compareTo(a) > 0 ? this : a;
7822
+ };
7823
+ BigInteger2.prototype.and = function(a) {
7824
+ var r = nbi();
7825
+ this.bitwiseTo(a, op_and, r);
7826
+ return r;
7827
+ };
7828
+ BigInteger2.prototype.or = function(a) {
7829
+ var r = nbi();
7830
+ this.bitwiseTo(a, op_or, r);
7831
+ return r;
7832
+ };
7833
+ BigInteger2.prototype.xor = function(a) {
7834
+ var r = nbi();
7835
+ this.bitwiseTo(a, op_xor, r);
7836
+ return r;
7837
+ };
7838
+ BigInteger2.prototype.andNot = function(a) {
7839
+ var r = nbi();
7840
+ this.bitwiseTo(a, op_andnot, r);
7841
+ return r;
7842
+ };
7843
+ BigInteger2.prototype.not = function() {
7844
+ var r = nbi();
7845
+ for (var i = 0; i < this.t; ++i) {
7846
+ r[i] = this.DM & ~this[i];
7847
+ }
7848
+ r.t = this.t;
7849
+ r.s = ~this.s;
7850
+ return r;
7851
+ };
7852
+ BigInteger2.prototype.shiftLeft = function(n) {
7853
+ var r = nbi();
7854
+ if (n < 0) {
7855
+ this.rShiftTo(-n, r);
7856
+ } else {
7857
+ this.lShiftTo(n, r);
7858
+ }
7859
+ return r;
7860
+ };
7861
+ BigInteger2.prototype.shiftRight = function(n) {
7862
+ var r = nbi();
7863
+ if (n < 0) {
7864
+ this.lShiftTo(-n, r);
7865
+ } else {
7866
+ this.rShiftTo(n, r);
7867
+ }
7868
+ return r;
7869
+ };
7870
+ BigInteger2.prototype.getLowestSetBit = function() {
7871
+ for (var i = 0; i < this.t; ++i) {
7872
+ if (this[i] != 0) {
7873
+ return i * this.DB + lbit(this[i]);
7874
+ }
7875
+ }
7876
+ if (this.s < 0) {
7877
+ return this.t * this.DB;
7878
+ }
7879
+ return -1;
7880
+ };
7881
+ BigInteger2.prototype.bitCount = function() {
7882
+ var r = 0;
7883
+ var x = this.s & this.DM;
7884
+ for (var i = 0; i < this.t; ++i) {
7885
+ r += cbit(this[i] ^ x);
7886
+ }
7887
+ return r;
7888
+ };
7889
+ BigInteger2.prototype.testBit = function(n) {
7890
+ var j = Math.floor(n / this.DB);
7891
+ if (j >= this.t) {
7892
+ return this.s != 0;
7893
+ }
7894
+ return (this[j] & 1 << n % this.DB) != 0;
7895
+ };
7896
+ BigInteger2.prototype.setBit = function(n) {
7897
+ return this.changeBit(n, op_or);
7898
+ };
7899
+ BigInteger2.prototype.clearBit = function(n) {
7900
+ return this.changeBit(n, op_andnot);
7901
+ };
7902
+ BigInteger2.prototype.flipBit = function(n) {
7903
+ return this.changeBit(n, op_xor);
7904
+ };
7905
+ BigInteger2.prototype.add = function(a) {
7906
+ var r = nbi();
7907
+ this.addTo(a, r);
7908
+ return r;
7909
+ };
7910
+ BigInteger2.prototype.subtract = function(a) {
7911
+ var r = nbi();
7912
+ this.subTo(a, r);
7913
+ return r;
7914
+ };
7915
+ BigInteger2.prototype.multiply = function(a) {
7916
+ var r = nbi();
7917
+ this.multiplyTo(a, r);
7918
+ return r;
7919
+ };
7920
+ BigInteger2.prototype.divide = function(a) {
7921
+ var r = nbi();
7922
+ this.divRemTo(a, r, null);
7923
+ return r;
7924
+ };
7925
+ BigInteger2.prototype.remainder = function(a) {
7926
+ var r = nbi();
7927
+ this.divRemTo(a, null, r);
7928
+ return r;
7929
+ };
7930
+ BigInteger2.prototype.divideAndRemainder = function(a) {
7931
+ var q = nbi();
7932
+ var r = nbi();
7933
+ this.divRemTo(a, q, r);
7934
+ return [q, r];
7935
+ };
7936
+ BigInteger2.prototype.modPow = function(e, m) {
7937
+ var i = e.bitLength();
7938
+ var k;
7939
+ var r = nbv(1);
7940
+ var z;
7941
+ if (i <= 0) {
7942
+ return r;
7943
+ } else if (i < 18) {
7944
+ k = 1;
7945
+ } else if (i < 48) {
7946
+ k = 3;
7947
+ } else if (i < 144) {
7948
+ k = 4;
7949
+ } else if (i < 768) {
7950
+ k = 5;
7951
+ } else {
7952
+ k = 6;
7953
+ }
7954
+ if (i < 8) {
7955
+ z = new Classic(m);
7956
+ } else if (m.isEven()) {
7957
+ z = new Barrett(m);
7958
+ } else {
7959
+ z = new Montgomery(m);
7960
+ }
7961
+ var g = [];
7962
+ var n = 3;
7963
+ var k1 = k - 1;
7964
+ var km = (1 << k) - 1;
7965
+ g[1] = z.convert(this);
7966
+ if (k > 1) {
7967
+ var g2 = nbi();
7968
+ z.sqrTo(g[1], g2);
7969
+ while (n <= km) {
7970
+ g[n] = nbi();
7971
+ z.mulTo(g2, g[n - 2], g[n]);
7972
+ n += 2;
7973
+ }
7974
+ }
7975
+ var j = e.t - 1;
7976
+ var w;
7977
+ var is1 = true;
7978
+ var r2 = nbi();
7979
+ var t;
7980
+ i = nbits(e[j]) - 1;
7981
+ while (j >= 0) {
7982
+ if (i >= k1) {
7983
+ w = e[j] >> i - k1 & km;
7984
+ } else {
7985
+ w = (e[j] & (1 << i + 1) - 1) << k1 - i;
7986
+ if (j > 0) {
7987
+ w |= e[j - 1] >> this.DB + i - k1;
7988
+ }
7989
+ }
7990
+ n = k;
7991
+ while ((w & 1) == 0) {
7992
+ w >>= 1;
7993
+ --n;
7994
+ }
7995
+ if ((i -= n) < 0) {
7996
+ i += this.DB;
7997
+ --j;
7998
+ }
7999
+ if (is1) {
8000
+ g[w].copyTo(r);
8001
+ is1 = false;
8002
+ } else {
8003
+ while (n > 1) {
8004
+ z.sqrTo(r, r2);
8005
+ z.sqrTo(r2, r);
8006
+ n -= 2;
8007
+ }
8008
+ if (n > 0) {
8009
+ z.sqrTo(r, r2);
8010
+ } else {
8011
+ t = r;
8012
+ r = r2;
8013
+ r2 = t;
8014
+ }
8015
+ z.mulTo(r2, g[w], r);
8016
+ }
8017
+ while (j >= 0 && (e[j] & 1 << i) == 0) {
8018
+ z.sqrTo(r, r2);
8019
+ t = r;
8020
+ r = r2;
8021
+ r2 = t;
8022
+ if (--i < 0) {
8023
+ i = this.DB - 1;
8024
+ --j;
8025
+ }
8026
+ }
8027
+ }
8028
+ return z.revert(r);
8029
+ };
8030
+ BigInteger2.prototype.modInverse = function(m) {
8031
+ var ac = m.isEven();
8032
+ if (this.isEven() && ac || m.signum() == 0) {
8033
+ return BigInteger2.ZERO;
8034
+ }
8035
+ var u = m.clone();
8036
+ var v = this.clone();
8037
+ var a = nbv(1);
8038
+ var b = nbv(0);
8039
+ var c = nbv(0);
8040
+ var d = nbv(1);
8041
+ while (u.signum() != 0) {
8042
+ while (u.isEven()) {
8043
+ u.rShiftTo(1, u);
8044
+ if (ac) {
8045
+ if (!a.isEven() || !b.isEven()) {
8046
+ a.addTo(this, a);
8047
+ b.subTo(m, b);
8048
+ }
8049
+ a.rShiftTo(1, a);
8050
+ } else if (!b.isEven()) {
8051
+ b.subTo(m, b);
8052
+ }
8053
+ b.rShiftTo(1, b);
8054
+ }
8055
+ while (v.isEven()) {
8056
+ v.rShiftTo(1, v);
8057
+ if (ac) {
8058
+ if (!c.isEven() || !d.isEven()) {
8059
+ c.addTo(this, c);
8060
+ d.subTo(m, d);
8061
+ }
8062
+ c.rShiftTo(1, c);
8063
+ } else if (!d.isEven()) {
8064
+ d.subTo(m, d);
8065
+ }
8066
+ d.rShiftTo(1, d);
8067
+ }
8068
+ if (u.compareTo(v) >= 0) {
8069
+ u.subTo(v, u);
8070
+ if (ac) {
8071
+ a.subTo(c, a);
8072
+ }
8073
+ b.subTo(d, b);
8074
+ } else {
8075
+ v.subTo(u, v);
8076
+ if (ac) {
8077
+ c.subTo(a, c);
8078
+ }
8079
+ d.subTo(b, d);
8080
+ }
8081
+ }
8082
+ if (v.compareTo(BigInteger2.ONE) != 0) {
8083
+ return BigInteger2.ZERO;
8084
+ }
8085
+ if (d.compareTo(m) >= 0) {
8086
+ return d.subtract(m);
8087
+ }
8088
+ if (d.signum() < 0) {
8089
+ d.addTo(m, d);
8090
+ } else {
8091
+ return d;
8092
+ }
8093
+ if (d.signum() < 0) {
8094
+ return d.add(m);
8095
+ } else {
8096
+ return d;
8097
+ }
8098
+ };
8099
+ BigInteger2.prototype.pow = function(e) {
8100
+ return this.exp(e, new NullExp());
8101
+ };
8102
+ BigInteger2.prototype.gcd = function(a) {
8103
+ var x = this.s < 0 ? this.negate() : this.clone();
8104
+ var y = a.s < 0 ? a.negate() : a.clone();
8105
+ if (x.compareTo(y) < 0) {
8106
+ var t = x;
8107
+ x = y;
8108
+ y = t;
8109
+ }
8110
+ var i = x.getLowestSetBit();
8111
+ var g = y.getLowestSetBit();
8112
+ if (g < 0) {
8113
+ return x;
8114
+ }
8115
+ if (i < g) {
8116
+ g = i;
8117
+ }
8118
+ if (g > 0) {
8119
+ x.rShiftTo(g, x);
8120
+ y.rShiftTo(g, y);
8121
+ }
8122
+ while (x.signum() > 0) {
8123
+ if ((i = x.getLowestSetBit()) > 0) {
8124
+ x.rShiftTo(i, x);
8125
+ }
8126
+ if ((i = y.getLowestSetBit()) > 0) {
8127
+ y.rShiftTo(i, y);
8128
+ }
8129
+ if (x.compareTo(y) >= 0) {
8130
+ x.subTo(y, x);
8131
+ x.rShiftTo(1, x);
8132
+ } else {
8133
+ y.subTo(x, y);
8134
+ y.rShiftTo(1, y);
8135
+ }
8136
+ }
8137
+ if (g > 0) {
8138
+ y.lShiftTo(g, y);
8139
+ }
8140
+ return y;
8141
+ };
8142
+ BigInteger2.prototype.isProbablePrime = function(t) {
8143
+ var i;
8144
+ var x = this.abs();
8145
+ if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
8146
+ for (i = 0; i < lowprimes.length; ++i) {
8147
+ if (x[0] == lowprimes[i]) {
8148
+ return true;
8149
+ }
8150
+ }
8151
+ return false;
8152
+ }
8153
+ if (x.isEven()) {
8154
+ return false;
8155
+ }
8156
+ i = 1;
8157
+ while (i < lowprimes.length) {
8158
+ var m = lowprimes[i];
8159
+ var j = i + 1;
8160
+ while (j < lowprimes.length && m < lplim) {
8161
+ m *= lowprimes[j++];
8162
+ }
8163
+ m = x.modInt(m);
8164
+ while (i < j) {
8165
+ if (m % lowprimes[i++] == 0) {
8166
+ return false;
8167
+ }
8168
+ }
8169
+ }
8170
+ return x.millerRabin(t);
8171
+ };
8172
+ BigInteger2.prototype.copyTo = function(r) {
8173
+ for (var i = this.t - 1; i >= 0; --i) {
8174
+ r[i] = this[i];
8175
+ }
8176
+ r.t = this.t;
8177
+ r.s = this.s;
8178
+ };
8179
+ BigInteger2.prototype.fromInt = function(x) {
8180
+ this.t = 1;
8181
+ this.s = x < 0 ? -1 : 0;
8182
+ if (x > 0) {
8183
+ this[0] = x;
8184
+ } else if (x < -1) {
8185
+ this[0] = x + this.DV;
8186
+ } else {
8187
+ this.t = 0;
8188
+ }
8189
+ };
8190
+ BigInteger2.prototype.fromString = function(s, b) {
8191
+ var k;
8192
+ if (b == 16) {
8193
+ k = 4;
8194
+ } else if (b == 8) {
8195
+ k = 3;
8196
+ } else if (b == 256) {
8197
+ k = 8;
8198
+ } else if (b == 2) {
8199
+ k = 1;
8200
+ } else if (b == 32) {
8201
+ k = 5;
8202
+ } else if (b == 4) {
8203
+ k = 2;
8204
+ } else {
8205
+ this.fromRadix(s, b);
8206
+ return;
8207
+ }
8208
+ this.t = 0;
8209
+ this.s = 0;
8210
+ var i = s.length;
8211
+ var mi = false;
8212
+ var sh = 0;
8213
+ while (--i >= 0) {
8214
+ var x = k == 8 ? +s[i] & 255 : intAt(s, i);
8215
+ if (x < 0) {
8216
+ if (s.charAt(i) == "-") {
8217
+ mi = true;
8218
+ }
8219
+ continue;
8220
+ }
8221
+ mi = false;
8222
+ if (sh == 0) {
8223
+ this[this.t++] = x;
8224
+ } else if (sh + k > this.DB) {
8225
+ this[this.t - 1] |= (x & (1 << this.DB - sh) - 1) << sh;
8226
+ this[this.t++] = x >> this.DB - sh;
8227
+ } else {
8228
+ this[this.t - 1] |= x << sh;
8229
+ }
8230
+ sh += k;
8231
+ if (sh >= this.DB) {
8232
+ sh -= this.DB;
8233
+ }
8234
+ }
8235
+ if (k == 8 && (+s[0] & 128) != 0) {
8236
+ this.s = -1;
8237
+ if (sh > 0) {
8238
+ this[this.t - 1] |= (1 << this.DB - sh) - 1 << sh;
8239
+ }
8240
+ }
8241
+ this.clamp();
8242
+ if (mi) {
8243
+ BigInteger2.ZERO.subTo(this, this);
8244
+ }
8245
+ };
8246
+ BigInteger2.prototype.clamp = function() {
8247
+ var c = this.s & this.DM;
8248
+ while (this.t > 0 && this[this.t - 1] == c) {
8249
+ --this.t;
8250
+ }
8251
+ };
8252
+ BigInteger2.prototype.dlShiftTo = function(n, r) {
8253
+ var i;
8254
+ for (i = this.t - 1; i >= 0; --i) {
8255
+ r[i + n] = this[i];
8256
+ }
8257
+ for (i = n - 1; i >= 0; --i) {
8258
+ r[i] = 0;
8259
+ }
8260
+ r.t = this.t + n;
8261
+ r.s = this.s;
8262
+ };
8263
+ BigInteger2.prototype.drShiftTo = function(n, r) {
8264
+ for (var i = n; i < this.t; ++i) {
8265
+ r[i - n] = this[i];
8266
+ }
8267
+ r.t = Math.max(this.t - n, 0);
8268
+ r.s = this.s;
8269
+ };
8270
+ BigInteger2.prototype.lShiftTo = function(n, r) {
8271
+ var bs = n % this.DB;
8272
+ var cbs = this.DB - bs;
8273
+ var bm = (1 << cbs) - 1;
8274
+ var ds = Math.floor(n / this.DB);
8275
+ var c = this.s << bs & this.DM;
8276
+ for (var i = this.t - 1; i >= 0; --i) {
8277
+ r[i + ds + 1] = this[i] >> cbs | c;
8278
+ c = (this[i] & bm) << bs;
8279
+ }
8280
+ for (var i = ds - 1; i >= 0; --i) {
8281
+ r[i] = 0;
8282
+ }
8283
+ r[ds] = c;
8284
+ r.t = this.t + ds + 1;
8285
+ r.s = this.s;
8286
+ r.clamp();
8287
+ };
8288
+ BigInteger2.prototype.rShiftTo = function(n, r) {
8289
+ r.s = this.s;
8290
+ var ds = Math.floor(n / this.DB);
8291
+ if (ds >= this.t) {
8292
+ r.t = 0;
8293
+ return;
8294
+ }
8295
+ var bs = n % this.DB;
8296
+ var cbs = this.DB - bs;
8297
+ var bm = (1 << bs) - 1;
8298
+ r[0] = this[ds] >> bs;
8299
+ for (var i = ds + 1; i < this.t; ++i) {
8300
+ r[i - ds - 1] |= (this[i] & bm) << cbs;
8301
+ r[i - ds] = this[i] >> bs;
8302
+ }
8303
+ if (bs > 0) {
8304
+ r[this.t - ds - 1] |= (this.s & bm) << cbs;
8305
+ }
8306
+ r.t = this.t - ds;
8307
+ r.clamp();
8308
+ };
8309
+ BigInteger2.prototype.subTo = function(a, r) {
8310
+ var i = 0;
8311
+ var c = 0;
8312
+ var m = Math.min(a.t, this.t);
8313
+ while (i < m) {
8314
+ c += this[i] - a[i];
8315
+ r[i++] = c & this.DM;
8316
+ c >>= this.DB;
8317
+ }
8318
+ if (a.t < this.t) {
8319
+ c -= a.s;
8320
+ while (i < this.t) {
8321
+ c += this[i];
8322
+ r[i++] = c & this.DM;
8323
+ c >>= this.DB;
8324
+ }
8325
+ c += this.s;
8326
+ } else {
8327
+ c += this.s;
8328
+ while (i < a.t) {
8329
+ c -= a[i];
8330
+ r[i++] = c & this.DM;
8331
+ c >>= this.DB;
8332
+ }
8333
+ c -= a.s;
8334
+ }
8335
+ r.s = c < 0 ? -1 : 0;
8336
+ if (c < -1) {
8337
+ r[i++] = this.DV + c;
8338
+ } else if (c > 0) {
8339
+ r[i++] = c;
8340
+ }
8341
+ r.t = i;
8342
+ r.clamp();
8343
+ };
8344
+ BigInteger2.prototype.multiplyTo = function(a, r) {
8345
+ var x = this.abs();
8346
+ var y = a.abs();
8347
+ var i = x.t;
8348
+ r.t = i + y.t;
8349
+ while (--i >= 0) {
8350
+ r[i] = 0;
8351
+ }
8352
+ for (i = 0; i < y.t; ++i) {
8353
+ r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
8354
+ }
8355
+ r.s = 0;
8356
+ r.clamp();
8357
+ if (this.s != a.s) {
8358
+ BigInteger2.ZERO.subTo(r, r);
8359
+ }
8360
+ };
8361
+ BigInteger2.prototype.squareTo = function(r) {
8362
+ var x = this.abs();
8363
+ var i = r.t = 2 * x.t;
8364
+ while (--i >= 0) {
8365
+ r[i] = 0;
8366
+ }
8367
+ for (i = 0; i < x.t - 1; ++i) {
8368
+ var c = x.am(i, x[i], r, 2 * i, 0, 1);
8369
+ if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
8370
+ r[i + x.t] -= x.DV;
8371
+ r[i + x.t + 1] = 1;
8372
+ }
8373
+ }
8374
+ if (r.t > 0) {
8375
+ r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
8376
+ }
8377
+ r.s = 0;
8378
+ r.clamp();
8379
+ };
8380
+ BigInteger2.prototype.divRemTo = function(m, q, r) {
8381
+ var pm = m.abs();
8382
+ if (pm.t <= 0) {
8383
+ return;
8384
+ }
8385
+ var pt = this.abs();
8386
+ if (pt.t < pm.t) {
8387
+ if (q != null) {
8388
+ q.fromInt(0);
8389
+ }
8390
+ if (r != null) {
8391
+ this.copyTo(r);
8392
+ }
8393
+ return;
8394
+ }
8395
+ if (r == null) {
8396
+ r = nbi();
8397
+ }
8398
+ var y = nbi();
8399
+ var ts = this.s;
8400
+ var ms = m.s;
8401
+ var nsh = this.DB - nbits(pm[pm.t - 1]);
8402
+ if (nsh > 0) {
8403
+ pm.lShiftTo(nsh, y);
8404
+ pt.lShiftTo(nsh, r);
8405
+ } else {
8406
+ pm.copyTo(y);
8407
+ pt.copyTo(r);
8408
+ }
8409
+ var ys = y.t;
8410
+ var y0 = y[ys - 1];
8411
+ if (y0 == 0) {
8412
+ return;
8413
+ }
8414
+ var yt = y0 * (1 << this.F1) + (ys > 1 ? y[ys - 2] >> this.F2 : 0);
8415
+ var d1 = this.FV / yt;
8416
+ var d2 = (1 << this.F1) / yt;
8417
+ var e = 1 << this.F2;
8418
+ var i = r.t;
8419
+ var j = i - ys;
8420
+ var t = q == null ? nbi() : q;
8421
+ y.dlShiftTo(j, t);
8422
+ if (r.compareTo(t) >= 0) {
8423
+ r[r.t++] = 1;
8424
+ r.subTo(t, r);
8425
+ }
8426
+ BigInteger2.ONE.dlShiftTo(ys, t);
8427
+ t.subTo(y, y);
8428
+ while (y.t < ys) {
8429
+ y[y.t++] = 0;
8430
+ }
8431
+ while (--j >= 0) {
8432
+ var qd = r[--i] == y0 ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
8433
+ if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) {
8434
+ y.dlShiftTo(j, t);
8435
+ r.subTo(t, r);
8436
+ while (r[i] < --qd) {
8437
+ r.subTo(t, r);
8438
+ }
8439
+ }
8440
+ }
8441
+ if (q != null) {
8442
+ r.drShiftTo(ys, q);
8443
+ if (ts != ms) {
8444
+ BigInteger2.ZERO.subTo(q, q);
8445
+ }
8446
+ }
8447
+ r.t = ys;
8448
+ r.clamp();
8449
+ if (nsh > 0) {
8450
+ r.rShiftTo(nsh, r);
8451
+ }
8452
+ if (ts < 0) {
8453
+ BigInteger2.ZERO.subTo(r, r);
8454
+ }
8455
+ };
8456
+ BigInteger2.prototype.invDigit = function() {
8457
+ if (this.t < 1) {
8458
+ return 0;
8459
+ }
8460
+ var x = this[0];
8461
+ if ((x & 1) == 0) {
8462
+ return 0;
8463
+ }
8464
+ var y = x & 3;
8465
+ y = y * (2 - (x & 15) * y) & 15;
8466
+ y = y * (2 - (x & 255) * y) & 255;
8467
+ y = y * (2 - ((x & 65535) * y & 65535)) & 65535;
8468
+ y = y * (2 - x * y % this.DV) % this.DV;
8469
+ return y > 0 ? this.DV - y : -y;
8470
+ };
8471
+ BigInteger2.prototype.isEven = function() {
8472
+ return (this.t > 0 ? this[0] & 1 : this.s) == 0;
8473
+ };
8474
+ BigInteger2.prototype.exp = function(e, z) {
8475
+ if (e > 4294967295 || e < 1) {
8476
+ return BigInteger2.ONE;
8477
+ }
8478
+ var r = nbi();
8479
+ var r2 = nbi();
8480
+ var g = z.convert(this);
8481
+ var i = nbits(e) - 1;
8482
+ g.copyTo(r);
8483
+ while (--i >= 0) {
8484
+ z.sqrTo(r, r2);
8485
+ if ((e & 1 << i) > 0) {
8486
+ z.mulTo(r2, g, r);
8487
+ } else {
8488
+ var t = r;
8489
+ r = r2;
8490
+ r2 = t;
8491
+ }
8492
+ }
8493
+ return z.revert(r);
8494
+ };
8495
+ BigInteger2.prototype.chunkSize = function(r) {
8496
+ return Math.floor(Math.LN2 * this.DB / Math.log(r));
8497
+ };
8498
+ BigInteger2.prototype.toRadix = function(b) {
8499
+ if (b == null) {
8500
+ b = 10;
8501
+ }
8502
+ if (this.signum() == 0 || b < 2 || b > 36) {
8503
+ return "0";
8504
+ }
8505
+ var cs = this.chunkSize(b);
8506
+ var a = Math.pow(b, cs);
8507
+ var d = nbv(a);
8508
+ var y = nbi();
8509
+ var z = nbi();
8510
+ var r = "";
8511
+ this.divRemTo(d, y, z);
8512
+ while (y.signum() > 0) {
8513
+ r = (a + z.intValue()).toString(b).substring(1) + r;
8514
+ y.divRemTo(d, y, z);
8515
+ }
8516
+ return z.intValue().toString(b) + r;
8517
+ };
8518
+ BigInteger2.prototype.fromRadix = function(s, b) {
8519
+ this.fromInt(0);
8520
+ if (b == null) {
8521
+ b = 10;
8522
+ }
8523
+ var cs = this.chunkSize(b);
8524
+ var d = Math.pow(b, cs);
8525
+ var mi = false;
8526
+ var j = 0;
8527
+ var w = 0;
8528
+ for (var i = 0; i < s.length; ++i) {
8529
+ var x = intAt(s, i);
8530
+ if (x < 0) {
8531
+ if (s.charAt(i) == "-" && this.signum() == 0) {
8532
+ mi = true;
8533
+ }
8534
+ continue;
8535
+ }
8536
+ w = b * w + x;
8537
+ if (++j >= cs) {
8538
+ this.dMultiply(d);
8539
+ this.dAddOffset(w, 0);
8540
+ j = 0;
8541
+ w = 0;
8542
+ }
8543
+ }
8544
+ if (j > 0) {
8545
+ this.dMultiply(Math.pow(b, j));
8546
+ this.dAddOffset(w, 0);
8547
+ }
8548
+ if (mi) {
8549
+ BigInteger2.ZERO.subTo(this, this);
8550
+ }
8551
+ };
8552
+ BigInteger2.prototype.fromNumber = function(a, b, c) {
8553
+ if ("number" == typeof b) {
8554
+ if (a < 2) {
8555
+ this.fromInt(1);
8556
+ } else {
8557
+ this.fromNumber(a, c);
8558
+ if (!this.testBit(a - 1)) {
8559
+ this.bitwiseTo(BigInteger2.ONE.shiftLeft(a - 1), op_or, this);
8560
+ }
8561
+ if (this.isEven()) {
8562
+ this.dAddOffset(1, 0);
8563
+ }
8564
+ while (!this.isProbablePrime(b)) {
8565
+ this.dAddOffset(2, 0);
8566
+ if (this.bitLength() > a) {
8567
+ this.subTo(BigInteger2.ONE.shiftLeft(a - 1), this);
8568
+ }
8569
+ }
8570
+ }
8571
+ } else {
8572
+ var x = [];
8573
+ var t = a & 7;
8574
+ x.length = (a >> 3) + 1;
8575
+ b.nextBytes(x);
8576
+ if (t > 0) {
8577
+ x[0] &= (1 << t) - 1;
8578
+ } else {
8579
+ x[0] = 0;
8580
+ }
8581
+ this.fromString(x, 256);
8582
+ }
8583
+ };
8584
+ BigInteger2.prototype.bitwiseTo = function(a, op, r) {
8585
+ var i;
8586
+ var f;
8587
+ var m = Math.min(a.t, this.t);
8588
+ for (i = 0; i < m; ++i) {
8589
+ r[i] = op(this[i], a[i]);
8590
+ }
8591
+ if (a.t < this.t) {
8592
+ f = a.s & this.DM;
8593
+ for (i = m; i < this.t; ++i) {
8594
+ r[i] = op(this[i], f);
8595
+ }
8596
+ r.t = this.t;
8597
+ } else {
8598
+ f = this.s & this.DM;
8599
+ for (i = m; i < a.t; ++i) {
8600
+ r[i] = op(f, a[i]);
8601
+ }
8602
+ r.t = a.t;
8603
+ }
8604
+ r.s = op(this.s, a.s);
8605
+ r.clamp();
8606
+ };
8607
+ BigInteger2.prototype.changeBit = function(n, op) {
8608
+ var r = BigInteger2.ONE.shiftLeft(n);
8609
+ this.bitwiseTo(r, op, r);
8610
+ return r;
8611
+ };
8612
+ BigInteger2.prototype.addTo = function(a, r) {
8613
+ var i = 0;
8614
+ var c = 0;
8615
+ var m = Math.min(a.t, this.t);
8616
+ while (i < m) {
8617
+ c += this[i] + a[i];
8618
+ r[i++] = c & this.DM;
8619
+ c >>= this.DB;
8620
+ }
8621
+ if (a.t < this.t) {
8622
+ c += a.s;
8623
+ while (i < this.t) {
8624
+ c += this[i];
8625
+ r[i++] = c & this.DM;
8626
+ c >>= this.DB;
8627
+ }
8628
+ c += this.s;
8629
+ } else {
8630
+ c += this.s;
8631
+ while (i < a.t) {
8632
+ c += a[i];
8633
+ r[i++] = c & this.DM;
8634
+ c >>= this.DB;
8635
+ }
8636
+ c += a.s;
8637
+ }
8638
+ r.s = c < 0 ? -1 : 0;
8639
+ if (c > 0) {
8640
+ r[i++] = c;
8641
+ } else if (c < -1) {
8642
+ r[i++] = this.DV + c;
8643
+ }
8644
+ r.t = i;
8645
+ r.clamp();
8646
+ };
8647
+ BigInteger2.prototype.dMultiply = function(n) {
8648
+ this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
8649
+ ++this.t;
8650
+ this.clamp();
8651
+ };
8652
+ BigInteger2.prototype.dAddOffset = function(n, w) {
8653
+ if (n == 0) {
8654
+ return;
8655
+ }
8656
+ while (this.t <= w) {
8657
+ this[this.t++] = 0;
8658
+ }
8659
+ this[w] += n;
8660
+ while (this[w] >= this.DV) {
8661
+ this[w] -= this.DV;
8662
+ if (++w >= this.t) {
8663
+ this[this.t++] = 0;
8664
+ }
8665
+ ++this[w];
8666
+ }
8667
+ };
8668
+ BigInteger2.prototype.multiplyLowerTo = function(a, n, r) {
8669
+ var i = Math.min(this.t + a.t, n);
8670
+ r.s = 0;
8671
+ r.t = i;
8672
+ while (i > 0) {
8673
+ r[--i] = 0;
8674
+ }
8675
+ for (var j = r.t - this.t; i < j; ++i) {
8676
+ r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
8677
+ }
8678
+ for (var j = Math.min(a.t, n); i < j; ++i) {
8679
+ this.am(0, a[i], r, i, 0, n - i);
8680
+ }
8681
+ r.clamp();
8682
+ };
8683
+ BigInteger2.prototype.multiplyUpperTo = function(a, n, r) {
8684
+ --n;
8685
+ var i = r.t = this.t + a.t - n;
8686
+ r.s = 0;
8687
+ while (--i >= 0) {
8688
+ r[i] = 0;
8689
+ }
8690
+ for (i = Math.max(n - this.t, 0); i < a.t; ++i) {
8691
+ r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
8692
+ }
8693
+ r.clamp();
8694
+ r.drShiftTo(1, r);
8695
+ };
8696
+ BigInteger2.prototype.modInt = function(n) {
8697
+ if (n <= 0) {
8698
+ return 0;
8699
+ }
8700
+ var d = this.DV % n;
8701
+ var r = this.s < 0 ? n - 1 : 0;
8702
+ if (this.t > 0) {
8703
+ if (d == 0) {
8704
+ r = this[0] % n;
8705
+ } else {
8706
+ for (var i = this.t - 1; i >= 0; --i) {
8707
+ r = (d * r + this[i]) % n;
8708
+ }
8709
+ }
8710
+ }
8711
+ return r;
8712
+ };
8713
+ BigInteger2.prototype.millerRabin = function(t) {
8714
+ var n1 = this.subtract(BigInteger2.ONE);
8715
+ var k = n1.getLowestSetBit();
8716
+ if (k <= 0) {
8717
+ return false;
8718
+ }
8719
+ var r = n1.shiftRight(k);
8720
+ t = t + 1 >> 1;
8721
+ if (t > lowprimes.length) {
8722
+ t = lowprimes.length;
8723
+ }
8724
+ var a = nbi();
8725
+ for (var i = 0; i < t; ++i) {
8726
+ a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
8727
+ var y = a.modPow(r, this);
8728
+ if (y.compareTo(BigInteger2.ONE) != 0 && y.compareTo(n1) != 0) {
8729
+ var j = 1;
8730
+ while (j++ < k && y.compareTo(n1) != 0) {
8731
+ y = y.modPowInt(2, this);
8732
+ if (y.compareTo(BigInteger2.ONE) == 0) {
8733
+ return false;
8734
+ }
8735
+ }
8736
+ if (y.compareTo(n1) != 0) {
8737
+ return false;
8738
+ }
8739
+ }
8740
+ }
8741
+ return true;
8742
+ };
8743
+ BigInteger2.prototype.square = function() {
8744
+ var r = nbi();
8745
+ this.squareTo(r);
8746
+ return r;
8747
+ };
8748
+ BigInteger2.prototype.gcda = function(a, callback) {
8749
+ var x = this.s < 0 ? this.negate() : this.clone();
8750
+ var y = a.s < 0 ? a.negate() : a.clone();
8751
+ if (x.compareTo(y) < 0) {
8752
+ var t = x;
8753
+ x = y;
8754
+ y = t;
8755
+ }
8756
+ var i = x.getLowestSetBit();
8757
+ var g = y.getLowestSetBit();
8758
+ if (g < 0) {
8759
+ callback(x);
8760
+ return;
8761
+ }
8762
+ if (i < g) {
8763
+ g = i;
8764
+ }
8765
+ if (g > 0) {
8766
+ x.rShiftTo(g, x);
8767
+ y.rShiftTo(g, y);
8768
+ }
8769
+ var gcda1 = function() {
8770
+ if ((i = x.getLowestSetBit()) > 0) {
8771
+ x.rShiftTo(i, x);
8772
+ }
8773
+ if ((i = y.getLowestSetBit()) > 0) {
8774
+ y.rShiftTo(i, y);
8775
+ }
8776
+ if (x.compareTo(y) >= 0) {
8777
+ x.subTo(y, x);
8778
+ x.rShiftTo(1, x);
8779
+ } else {
8780
+ y.subTo(x, y);
8781
+ y.rShiftTo(1, y);
8782
+ }
8783
+ if (!(x.signum() > 0)) {
8784
+ if (g > 0) {
8785
+ y.lShiftTo(g, y);
8786
+ }
8787
+ setTimeout(function() {
8788
+ callback(y);
8789
+ }, 0);
8790
+ } else {
8791
+ setTimeout(gcda1, 0);
8792
+ }
8793
+ };
8794
+ setTimeout(gcda1, 10);
8795
+ };
8796
+ BigInteger2.prototype.fromNumberAsync = function(a, b, c, callback) {
8797
+ if ("number" == typeof b) {
8798
+ if (a < 2) {
8799
+ this.fromInt(1);
8800
+ } else {
8801
+ this.fromNumber(a, c);
8802
+ if (!this.testBit(a - 1)) {
8803
+ this.bitwiseTo(BigInteger2.ONE.shiftLeft(a - 1), op_or, this);
8804
+ }
8805
+ if (this.isEven()) {
8806
+ this.dAddOffset(1, 0);
8807
+ }
8808
+ var bnp_1 = this;
8809
+ var bnpfn1_1 = function() {
8810
+ bnp_1.dAddOffset(2, 0);
8811
+ if (bnp_1.bitLength() > a) {
8812
+ bnp_1.subTo(BigInteger2.ONE.shiftLeft(a - 1), bnp_1);
8813
+ }
8814
+ if (bnp_1.isProbablePrime(b)) {
8815
+ setTimeout(function() {
8816
+ callback();
8817
+ }, 0);
8818
+ } else {
8819
+ setTimeout(bnpfn1_1, 0);
8820
+ }
8821
+ };
8822
+ setTimeout(bnpfn1_1, 0);
8823
+ }
8824
+ } else {
8825
+ var x = [];
8826
+ var t = a & 7;
8827
+ x.length = (a >> 3) + 1;
8828
+ b.nextBytes(x);
8829
+ if (t > 0) {
8830
+ x[0] &= (1 << t) - 1;
8831
+ } else {
8832
+ x[0] = 0;
8833
+ }
8834
+ this.fromString(x, 256);
8835
+ }
8836
+ };
8837
+ return BigInteger2;
8838
+ })()
8839
+ );
8840
+ var NullExp = (
8841
+ /** @class */
8842
+ (function() {
8843
+ function NullExp2() {
8844
+ }
8845
+ NullExp2.prototype.convert = function(x) {
8846
+ return x;
8847
+ };
8848
+ NullExp2.prototype.revert = function(x) {
8849
+ return x;
8850
+ };
8851
+ NullExp2.prototype.mulTo = function(x, y, r) {
8852
+ x.multiplyTo(y, r);
8853
+ };
8854
+ NullExp2.prototype.sqrTo = function(x, r) {
8855
+ x.squareTo(r);
8856
+ };
8857
+ return NullExp2;
8858
+ })()
8859
+ );
8860
+ var Classic = (
8861
+ /** @class */
8862
+ (function() {
8863
+ function Classic2(m) {
8864
+ this.m = m;
8865
+ }
8866
+ Classic2.prototype.convert = function(x) {
8867
+ if (x.s < 0 || x.compareTo(this.m) >= 0) {
8868
+ return x.mod(this.m);
8869
+ } else {
8870
+ return x;
8871
+ }
8872
+ };
8873
+ Classic2.prototype.revert = function(x) {
8874
+ return x;
8875
+ };
8876
+ Classic2.prototype.reduce = function(x) {
8877
+ x.divRemTo(this.m, null, x);
8878
+ };
8879
+ Classic2.prototype.mulTo = function(x, y, r) {
8880
+ x.multiplyTo(y, r);
8881
+ this.reduce(r);
8882
+ };
8883
+ Classic2.prototype.sqrTo = function(x, r) {
8884
+ x.squareTo(r);
8885
+ this.reduce(r);
8886
+ };
8887
+ return Classic2;
8888
+ })()
8889
+ );
8890
+ var Montgomery = (
8891
+ /** @class */
8892
+ (function() {
8893
+ function Montgomery2(m) {
8894
+ this.m = m;
8895
+ this.mp = m.invDigit();
8896
+ this.mpl = this.mp & 32767;
8897
+ this.mph = this.mp >> 15;
8898
+ this.um = (1 << m.DB - 15) - 1;
8899
+ this.mt2 = 2 * m.t;
8900
+ }
8901
+ Montgomery2.prototype.convert = function(x) {
8902
+ var r = nbi();
8903
+ x.abs().dlShiftTo(this.m.t, r);
8904
+ r.divRemTo(this.m, null, r);
8905
+ if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
8906
+ this.m.subTo(r, r);
8907
+ }
8908
+ return r;
8909
+ };
8910
+ Montgomery2.prototype.revert = function(x) {
8911
+ var r = nbi();
8912
+ x.copyTo(r);
8913
+ this.reduce(r);
8914
+ return r;
8915
+ };
8916
+ Montgomery2.prototype.reduce = function(x) {
8917
+ while (x.t <= this.mt2) {
8918
+ x[x.t++] = 0;
8919
+ }
8920
+ for (var i = 0; i < this.m.t; ++i) {
8921
+ var j = x[i] & 32767;
8922
+ var u0 = j * this.mpl + ((j * this.mph + (x[i] >> 15) * this.mpl & this.um) << 15) & x.DM;
8923
+ j = i + this.m.t;
8924
+ x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
8925
+ while (x[j] >= x.DV) {
8926
+ x[j] -= x.DV;
8927
+ x[++j]++;
8928
+ }
8929
+ }
8930
+ x.clamp();
8931
+ x.drShiftTo(this.m.t, x);
8932
+ if (x.compareTo(this.m) >= 0) {
8933
+ x.subTo(this.m, x);
8934
+ }
8935
+ };
8936
+ Montgomery2.prototype.mulTo = function(x, y, r) {
8937
+ x.multiplyTo(y, r);
8938
+ this.reduce(r);
8939
+ };
8940
+ Montgomery2.prototype.sqrTo = function(x, r) {
8941
+ x.squareTo(r);
8942
+ this.reduce(r);
8943
+ };
8944
+ return Montgomery2;
8945
+ })()
8946
+ );
8947
+ var Barrett = (
8948
+ /** @class */
8949
+ (function() {
8950
+ function Barrett2(m) {
8951
+ this.m = m;
8952
+ this.r2 = nbi();
8953
+ this.q3 = nbi();
8954
+ BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
8955
+ this.mu = this.r2.divide(m);
8956
+ }
8957
+ Barrett2.prototype.convert = function(x) {
8958
+ if (x.s < 0 || x.t > 2 * this.m.t) {
8959
+ return x.mod(this.m);
8960
+ } else if (x.compareTo(this.m) < 0) {
8961
+ return x;
8962
+ } else {
8963
+ var r = nbi();
8964
+ x.copyTo(r);
8965
+ this.reduce(r);
8966
+ return r;
8967
+ }
8968
+ };
8969
+ Barrett2.prototype.revert = function(x) {
8970
+ return x;
8971
+ };
8972
+ Barrett2.prototype.reduce = function(x) {
8973
+ x.drShiftTo(this.m.t - 1, this.r2);
8974
+ if (x.t > this.m.t + 1) {
8975
+ x.t = this.m.t + 1;
8976
+ x.clamp();
8977
+ }
8978
+ this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
8979
+ this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
8980
+ while (x.compareTo(this.r2) < 0) {
8981
+ x.dAddOffset(1, this.m.t + 1);
8982
+ }
8983
+ x.subTo(this.r2, x);
8984
+ while (x.compareTo(this.m) >= 0) {
8985
+ x.subTo(this.m, x);
8986
+ }
8987
+ };
8988
+ Barrett2.prototype.mulTo = function(x, y, r) {
8989
+ x.multiplyTo(y, r);
8990
+ this.reduce(r);
8991
+ };
8992
+ Barrett2.prototype.sqrTo = function(x, r) {
8993
+ x.squareTo(r);
8994
+ this.reduce(r);
8995
+ };
8996
+ return Barrett2;
8997
+ })()
8998
+ );
8999
+ function nbi() {
9000
+ return new BigInteger(null);
9001
+ }
9002
+ function parseBigInt(str, r) {
9003
+ return new BigInteger(str, r);
9004
+ }
9005
+ var inBrowser = typeof navigator !== "undefined";
9006
+ if (inBrowser && j_lm && navigator.appName == "Microsoft Internet Explorer") {
9007
+ BigInteger.prototype.am = function am2(i, x, w, j, c, n) {
9008
+ var xl = x & 32767;
9009
+ var xh = x >> 15;
9010
+ while (--n >= 0) {
9011
+ var l = this[i] & 32767;
9012
+ var h = this[i++] >> 15;
9013
+ var m = xh * l + h * xl;
9014
+ l = xl * l + ((m & 32767) << 15) + w[j] + (c & 1073741823);
9015
+ c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
9016
+ w[j++] = l & 1073741823;
9017
+ }
9018
+ return c;
9019
+ };
9020
+ dbits = 30;
9021
+ } else if (inBrowser && j_lm && navigator.appName != "Netscape") {
9022
+ BigInteger.prototype.am = function am1(i, x, w, j, c, n) {
9023
+ while (--n >= 0) {
9024
+ var v = x * this[i++] + w[j] + c;
9025
+ c = Math.floor(v / 67108864);
9026
+ w[j++] = v & 67108863;
9027
+ }
9028
+ return c;
9029
+ };
9030
+ dbits = 26;
9031
+ } else {
9032
+ BigInteger.prototype.am = function am3(i, x, w, j, c, n) {
9033
+ var xl = x & 16383;
9034
+ var xh = x >> 14;
9035
+ while (--n >= 0) {
9036
+ var l = this[i] & 16383;
9037
+ var h = this[i++] >> 14;
9038
+ var m = xh * l + h * xl;
9039
+ l = xl * l + ((m & 16383) << 14) + w[j] + c;
9040
+ c = (l >> 28) + (m >> 14) + xh * h;
9041
+ w[j++] = l & 268435455;
9042
+ }
9043
+ return c;
9044
+ };
9045
+ dbits = 28;
9046
+ }
9047
+ BigInteger.prototype.DB = dbits;
9048
+ BigInteger.prototype.DM = (1 << dbits) - 1;
9049
+ BigInteger.prototype.DV = 1 << dbits;
9050
+ var BI_FP = 52;
9051
+ BigInteger.prototype.FV = Math.pow(2, BI_FP);
9052
+ BigInteger.prototype.F1 = BI_FP - dbits;
9053
+ BigInteger.prototype.F2 = 2 * dbits - BI_FP;
9054
+ var BI_RC = [];
9055
+ var rr;
9056
+ var vv;
9057
+ rr = "0".charCodeAt(0);
9058
+ for (vv = 0; vv <= 9; ++vv) {
9059
+ BI_RC[rr++] = vv;
9060
+ }
9061
+ rr = "a".charCodeAt(0);
9062
+ for (vv = 10; vv < 36; ++vv) {
9063
+ BI_RC[rr++] = vv;
9064
+ }
9065
+ rr = "A".charCodeAt(0);
9066
+ for (vv = 10; vv < 36; ++vv) {
9067
+ BI_RC[rr++] = vv;
9068
+ }
9069
+ function intAt(s, i) {
9070
+ var c = BI_RC[s.charCodeAt(i)];
9071
+ return c == null ? -1 : c;
9072
+ }
9073
+ function nbv(i) {
9074
+ var r = nbi();
9075
+ r.fromInt(i);
9076
+ return r;
9077
+ }
9078
+ function nbits(x) {
9079
+ var r = 1;
9080
+ var t;
9081
+ if ((t = x >>> 16) != 0) {
9082
+ x = t;
9083
+ r += 16;
9084
+ }
9085
+ if ((t = x >> 8) != 0) {
9086
+ x = t;
9087
+ r += 8;
9088
+ }
9089
+ if ((t = x >> 4) != 0) {
9090
+ x = t;
9091
+ r += 4;
9092
+ }
9093
+ if ((t = x >> 2) != 0) {
9094
+ x = t;
9095
+ r += 2;
9096
+ }
9097
+ if ((t = x >> 1) != 0) {
9098
+ x = t;
9099
+ r += 1;
9100
+ }
9101
+ return r;
9102
+ }
9103
+ BigInteger.ZERO = nbv(0);
9104
+ BigInteger.ONE = nbv(1);
9105
+ var Arcfour = (
9106
+ /** @class */
9107
+ (function() {
9108
+ function Arcfour2() {
9109
+ this.i = 0;
9110
+ this.j = 0;
9111
+ this.S = [];
9112
+ }
9113
+ Arcfour2.prototype.init = function(key) {
9114
+ var i;
9115
+ var j;
9116
+ var t;
9117
+ for (i = 0; i < 256; ++i) {
9118
+ this.S[i] = i;
9119
+ }
9120
+ j = 0;
9121
+ for (i = 0; i < 256; ++i) {
9122
+ j = j + this.S[i] + key[i % key.length] & 255;
9123
+ t = this.S[i];
9124
+ this.S[i] = this.S[j];
9125
+ this.S[j] = t;
9126
+ }
9127
+ this.i = 0;
9128
+ this.j = 0;
9129
+ };
9130
+ Arcfour2.prototype.next = function() {
9131
+ var t;
9132
+ this.i = this.i + 1 & 255;
9133
+ this.j = this.j + this.S[this.i] & 255;
9134
+ t = this.S[this.i];
9135
+ this.S[this.i] = this.S[this.j];
9136
+ this.S[this.j] = t;
9137
+ return this.S[t + this.S[this.i] & 255];
9138
+ };
9139
+ return Arcfour2;
9140
+ })()
9141
+ );
9142
+ function prng_newstate() {
9143
+ return new Arcfour();
9144
+ }
9145
+ var rng_psize = 256;
9146
+ var rng_state;
9147
+ var rng_pool = null;
9148
+ var rng_pptr;
9149
+ if (rng_pool == null) {
9150
+ rng_pool = [];
9151
+ rng_pptr = 0;
9152
+ var t = void 0;
9153
+ if (typeof window !== "undefined" && self.crypto && self.crypto.getRandomValues) {
9154
+ var z = new Uint32Array(256);
9155
+ self.crypto.getRandomValues(z);
9156
+ for (t = 0; t < z.length; ++t) {
9157
+ rng_pool[rng_pptr++] = z[t] & 255;
9158
+ }
9159
+ }
9160
+ var count = 0;
9161
+ var onMouseMoveListener_1 = function(ev) {
9162
+ count = count || 0;
9163
+ if (count >= 256 || rng_pptr >= rng_psize) {
9164
+ if (self.removeEventListener) {
9165
+ self.removeEventListener("mousemove", onMouseMoveListener_1, false);
9166
+ } else if (self.detachEvent) {
9167
+ self.detachEvent("onmousemove", onMouseMoveListener_1);
9168
+ }
9169
+ return;
9170
+ }
9171
+ try {
9172
+ var mouseCoordinates = ev.x + ev.y;
9173
+ rng_pool[rng_pptr++] = mouseCoordinates & 255;
9174
+ count += 1;
9175
+ } catch (e) {
9176
+ }
9177
+ };
9178
+ if (typeof window !== "undefined") {
9179
+ if (self.addEventListener) {
9180
+ self.addEventListener("mousemove", onMouseMoveListener_1, false);
9181
+ } else if (self.attachEvent) {
9182
+ self.attachEvent("onmousemove", onMouseMoveListener_1);
9183
+ }
9184
+ }
9185
+ }
9186
+ function rng_get_byte() {
9187
+ if (rng_state == null) {
9188
+ rng_state = prng_newstate();
9189
+ while (rng_pptr < rng_psize) {
9190
+ var random = Math.floor(65536 * Math.random());
9191
+ rng_pool[rng_pptr++] = random & 255;
9192
+ }
9193
+ rng_state.init(rng_pool);
9194
+ for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) {
9195
+ rng_pool[rng_pptr] = 0;
9196
+ }
9197
+ rng_pptr = 0;
9198
+ }
9199
+ return rng_state.next();
9200
+ }
9201
+ var SecureRandom = (
9202
+ /** @class */
9203
+ (function() {
9204
+ function SecureRandom2() {
9205
+ }
9206
+ SecureRandom2.prototype.nextBytes = function(ba) {
9207
+ for (var i = 0; i < ba.length; ++i) {
9208
+ ba[i] = rng_get_byte();
9209
+ }
9210
+ };
9211
+ return SecureRandom2;
9212
+ })()
9213
+ );
9214
+ function rstr_sha256(s) {
9215
+ return binb2rstr(binb_sha256(rstr2binb(s), s.length * 8));
9216
+ }
9217
+ function rstr2hex(input) {
9218
+ var hex_tab = "0123456789abcdef";
9219
+ var output = "";
9220
+ for (var i = 0; i < input.length; i++) {
9221
+ var x = input.charCodeAt(i);
9222
+ output += hex_tab.charAt(x >>> 4 & 15) + hex_tab.charAt(x & 15);
9223
+ }
9224
+ return output;
9225
+ }
9226
+ function rstr2binb(input) {
9227
+ var output = Array(input.length >> 2);
9228
+ for (var i = 0; i < output.length; i++)
9229
+ output[i] = 0;
9230
+ for (var i = 0; i < input.length * 8; i += 8)
9231
+ output[i >> 5] |= (input.charCodeAt(i / 8) & 255) << 24 - i % 32;
9232
+ return output;
9233
+ }
9234
+ function binb2rstr(input) {
9235
+ var output = "";
9236
+ for (var i = 0; i < input.length * 32; i += 8)
9237
+ output += String.fromCharCode(input[i >> 5] >>> 24 - i % 32 & 255);
9238
+ return output;
9239
+ }
9240
+ function sha256_S(X, n) {
9241
+ return X >>> n | X << 32 - n;
9242
+ }
9243
+ function sha256_R(X, n) {
9244
+ return X >>> n;
9245
+ }
9246
+ function sha256_Ch(x, y, z) {
9247
+ return x & y ^ ~x & z;
9248
+ }
9249
+ function sha256_Maj(x, y, z) {
9250
+ return x & y ^ x & z ^ y & z;
9251
+ }
9252
+ function sha256_Sigma0256(x) {
9253
+ return sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22);
9254
+ }
9255
+ function sha256_Sigma1256(x) {
9256
+ return sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25);
9257
+ }
9258
+ function sha256_Gamma0256(x) {
9259
+ return sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3);
9260
+ }
9261
+ function sha256_Gamma1256(x) {
9262
+ return sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10);
9263
+ }
9264
+ var sha256_K = new Array(1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998);
9265
+ function binb_sha256(m, l) {
9266
+ var HASH = new Array(1779033703, -1150833019, 1013904242, -1521486534, 1359893119, -1694144372, 528734635, 1541459225);
9267
+ var W = new Array(64);
9268
+ var a, b, c, d, e, f, g, h;
9269
+ var i, j, T1, T2;
9270
+ m[l >> 5] |= 128 << 24 - l % 32;
9271
+ m[(l + 64 >> 9 << 4) + 15] = l;
9272
+ for (i = 0; i < m.length; i += 16) {
9273
+ a = HASH[0];
9274
+ b = HASH[1];
9275
+ c = HASH[2];
9276
+ d = HASH[3];
9277
+ e = HASH[4];
9278
+ f = HASH[5];
9279
+ g = HASH[6];
9280
+ h = HASH[7];
9281
+ for (j = 0; j < 64; j++) {
9282
+ if (j < 16)
9283
+ W[j] = m[j + i];
9284
+ else
9285
+ W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]), sha256_Gamma0256(W[j - 15])), W[j - 16]);
9286
+ T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)), sha256_K[j]), W[j]);
9287
+ T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
9288
+ h = g;
9289
+ g = f;
9290
+ f = e;
9291
+ e = safe_add(d, T1);
9292
+ d = c;
9293
+ c = b;
9294
+ b = a;
9295
+ a = safe_add(T1, T2);
9296
+ }
9297
+ HASH[0] = safe_add(a, HASH[0]);
9298
+ HASH[1] = safe_add(b, HASH[1]);
9299
+ HASH[2] = safe_add(c, HASH[2]);
9300
+ HASH[3] = safe_add(d, HASH[3]);
9301
+ HASH[4] = safe_add(e, HASH[4]);
9302
+ HASH[5] = safe_add(f, HASH[5]);
9303
+ HASH[6] = safe_add(g, HASH[6]);
9304
+ HASH[7] = safe_add(h, HASH[7]);
9305
+ }
9306
+ return HASH;
9307
+ }
9308
+ function safe_add(x, y) {
9309
+ var lsw = (x & 65535) + (y & 65535);
9310
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
9311
+ return msw << 16 | lsw & 65535;
9312
+ }
9313
+ function pkcs1pad1(s, n) {
9314
+ if (n < s.length + 22) {
9315
+ console.error("Message too long for RSA");
9316
+ return null;
9317
+ }
9318
+ var len = n - s.length - 6;
9319
+ var filler = "";
9320
+ for (var f = 0; f < len; f += 2) {
9321
+ filler += "ff";
9322
+ }
9323
+ var m = "0001" + filler + "00" + s;
9324
+ return parseBigInt(m, 16);
9325
+ }
9326
+ function pkcs1pad2(s, n) {
9327
+ if (n < s.length + 11) {
9328
+ console.error("Message too long for RSA");
9329
+ return null;
9330
+ }
9331
+ var ba = [];
9332
+ var i = s.length - 1;
9333
+ while (i >= 0 && n > 0) {
9334
+ var c = s.charCodeAt(i--);
9335
+ if (c < 128) {
9336
+ ba[--n] = c;
9337
+ } else if (c > 127 && c < 2048) {
9338
+ ba[--n] = c & 63 | 128;
9339
+ ba[--n] = c >> 6 | 192;
9340
+ } else {
9341
+ ba[--n] = c & 63 | 128;
9342
+ ba[--n] = c >> 6 & 63 | 128;
9343
+ ba[--n] = c >> 12 | 224;
9344
+ }
9345
+ }
9346
+ ba[--n] = 0;
9347
+ var rng = new SecureRandom();
9348
+ var x = [];
9349
+ while (n > 2) {
9350
+ x[0] = 0;
9351
+ while (x[0] == 0) {
9352
+ rng.nextBytes(x);
9353
+ }
9354
+ ba[--n] = x[0];
9355
+ }
9356
+ ba[--n] = 2;
9357
+ ba[--n] = 0;
9358
+ return new BigInteger(ba);
9359
+ }
9360
+ function oaep_mgf1_arr(seed, len, hashFunc) {
9361
+ var mask = "", i = 0;
9362
+ while (mask.length < len) {
9363
+ mask += hashFunc(String.fromCharCode.apply(String, seed.concat([
9364
+ (i & 4278190080) >> 24,
9365
+ (i & 16711680) >> 16,
9366
+ (i & 65280) >> 8,
9367
+ i & 255
9368
+ ])));
9369
+ i += 1;
9370
+ }
9371
+ return mask;
9372
+ }
9373
+ var SHA256_SIZE = 32;
9374
+ function oaep_pad(s, n) {
9375
+ var hashLen = SHA256_SIZE;
9376
+ var hashFunc = rstr_sha256;
9377
+ if (s.length + 2 * hashLen + 2 > n) {
9378
+ throw "Message too long for RSA";
9379
+ }
9380
+ var PS = "", i;
9381
+ for (i = 0; i < n - s.length - 2 * hashLen - 2; i += 1) {
9382
+ PS += "\0";
9383
+ }
9384
+ var DB = hashFunc("") + PS + "" + s, seed = new Array(hashLen);
9385
+ new SecureRandom().nextBytes(seed);
9386
+ var dbMask = oaep_mgf1_arr(seed, DB.length, hashFunc), maskedDB = [];
9387
+ for (i = 0; i < DB.length; i += 1) {
9388
+ maskedDB[i] = DB.charCodeAt(i) ^ dbMask.charCodeAt(i);
9389
+ }
9390
+ var seedMask = oaep_mgf1_arr(maskedDB, seed.length, hashFunc), maskedSeed = [0];
9391
+ for (i = 0; i < seed.length; i += 1) {
9392
+ maskedSeed[i + 1] = seed[i] ^ seedMask.charCodeAt(i);
9393
+ }
9394
+ return new BigInteger(maskedSeed.concat(maskedDB));
9395
+ }
9396
+ var RSAKey = (
9397
+ /** @class */
9398
+ (function() {
9399
+ function RSAKey2() {
9400
+ this.n = null;
9401
+ this.e = 0;
9402
+ this.d = null;
9403
+ this.p = null;
9404
+ this.q = null;
9405
+ this.dmp1 = null;
9406
+ this.dmq1 = null;
9407
+ this.coeff = null;
9408
+ }
9409
+ RSAKey2.prototype.doPublic = function(x) {
9410
+ return x.modPowInt(this.e, this.n);
9411
+ };
9412
+ RSAKey2.prototype.doPrivate = function(x) {
9413
+ if (this.p == null || this.q == null) {
9414
+ return x.modPow(this.d, this.n);
9415
+ }
9416
+ var xp = x.mod(this.p).modPow(this.dmp1, this.p);
9417
+ var xq = x.mod(this.q).modPow(this.dmq1, this.q);
9418
+ while (xp.compareTo(xq) < 0) {
9419
+ xp = xp.add(this.p);
9420
+ }
9421
+ return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
9422
+ };
9423
+ RSAKey2.prototype.setPublic = function(N, E) {
9424
+ if (N != null && E != null && N.length > 0 && E.length > 0) {
9425
+ this.n = parseBigInt(N, 16);
9426
+ this.e = parseInt(E, 16);
9427
+ } else {
9428
+ console.error("Invalid RSA public key");
9429
+ }
9430
+ };
9431
+ RSAKey2.prototype.encrypt = function(text, paddingFunction) {
9432
+ if (typeof paddingFunction === "undefined") {
9433
+ paddingFunction = pkcs1pad2;
9434
+ }
9435
+ var maxLength = this.n.bitLength() + 7 >> 3;
9436
+ var m = paddingFunction(text, maxLength);
9437
+ if (m == null) {
9438
+ return null;
9439
+ }
9440
+ var c = this.doPublic(m);
9441
+ if (c == null) {
9442
+ return null;
9443
+ }
9444
+ var h = c.toString(16);
9445
+ var length = h.length;
9446
+ for (var i = 0; i < maxLength * 2 - length; i++) {
9447
+ h = "0" + h;
9448
+ }
9449
+ return h;
9450
+ };
9451
+ RSAKey2.prototype.setPrivate = function(N, E, D) {
9452
+ if (N != null && E != null && N.length > 0 && E.length > 0) {
9453
+ this.n = parseBigInt(N, 16);
9454
+ this.e = parseInt(E, 16);
9455
+ this.d = parseBigInt(D, 16);
9456
+ } else {
9457
+ console.error("Invalid RSA private key");
9458
+ }
9459
+ };
9460
+ RSAKey2.prototype.setPrivateEx = function(N, E, D, P, Q, DP, DQ, C) {
9461
+ if (N != null && E != null && N.length > 0 && E.length > 0) {
9462
+ this.n = parseBigInt(N, 16);
9463
+ this.e = parseInt(E, 16);
9464
+ this.d = parseBigInt(D, 16);
9465
+ this.p = parseBigInt(P, 16);
9466
+ this.q = parseBigInt(Q, 16);
9467
+ this.dmp1 = parseBigInt(DP, 16);
9468
+ this.dmq1 = parseBigInt(DQ, 16);
9469
+ this.coeff = parseBigInt(C, 16);
9470
+ } else {
9471
+ console.error("Invalid RSA private key");
9472
+ }
9473
+ };
9474
+ RSAKey2.prototype.generate = function(B, E) {
9475
+ var rng = new SecureRandom();
9476
+ var qs = B >> 1;
9477
+ this.e = parseInt(E, 16);
9478
+ var ee = new BigInteger(E, 16);
9479
+ for (; ; ) {
9480
+ for (; ; ) {
9481
+ this.p = new BigInteger(B - qs, 1, rng);
9482
+ if (this.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.p.isProbablePrime(10)) {
9483
+ break;
9484
+ }
9485
+ }
9486
+ for (; ; ) {
9487
+ this.q = new BigInteger(qs, 1, rng);
9488
+ if (this.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.q.isProbablePrime(10)) {
9489
+ break;
9490
+ }
9491
+ }
9492
+ if (this.p.compareTo(this.q) <= 0) {
9493
+ var t = this.p;
9494
+ this.p = this.q;
9495
+ this.q = t;
9496
+ }
9497
+ var p1 = this.p.subtract(BigInteger.ONE);
9498
+ var q1 = this.q.subtract(BigInteger.ONE);
9499
+ var phi = p1.multiply(q1);
9500
+ if (phi.gcd(ee).compareTo(BigInteger.ONE) == 0) {
9501
+ this.n = this.p.multiply(this.q);
9502
+ this.d = ee.modInverse(phi);
9503
+ this.dmp1 = this.d.mod(p1);
9504
+ this.dmq1 = this.d.mod(q1);
9505
+ this.coeff = this.q.modInverse(this.p);
9506
+ break;
9507
+ }
9508
+ }
9509
+ };
9510
+ RSAKey2.prototype.decrypt = function(ctext) {
9511
+ var c = parseBigInt(ctext, 16);
9512
+ var m = this.doPrivate(c);
9513
+ if (m == null) {
9514
+ return null;
9515
+ }
9516
+ return pkcs1unpad2(m, this.n.bitLength() + 7 >> 3);
9517
+ };
9518
+ RSAKey2.prototype.generateAsync = function(B, E, callback) {
9519
+ var rng = new SecureRandom();
9520
+ var qs = B >> 1;
9521
+ this.e = parseInt(E, 16);
9522
+ var ee = new BigInteger(E, 16);
9523
+ var rsa = this;
9524
+ var loop1 = function() {
9525
+ var loop4 = function() {
9526
+ if (rsa.p.compareTo(rsa.q) <= 0) {
9527
+ var t = rsa.p;
9528
+ rsa.p = rsa.q;
9529
+ rsa.q = t;
9530
+ }
9531
+ var p1 = rsa.p.subtract(BigInteger.ONE);
9532
+ var q1 = rsa.q.subtract(BigInteger.ONE);
9533
+ var phi = p1.multiply(q1);
9534
+ if (phi.gcd(ee).compareTo(BigInteger.ONE) == 0) {
9535
+ rsa.n = rsa.p.multiply(rsa.q);
9536
+ rsa.d = ee.modInverse(phi);
9537
+ rsa.dmp1 = rsa.d.mod(p1);
9538
+ rsa.dmq1 = rsa.d.mod(q1);
9539
+ rsa.coeff = rsa.q.modInverse(rsa.p);
9540
+ setTimeout(function() {
9541
+ callback();
9542
+ }, 0);
9543
+ } else {
9544
+ setTimeout(loop1, 0);
9545
+ }
9546
+ };
9547
+ var loop3 = function() {
9548
+ rsa.q = nbi();
9549
+ rsa.q.fromNumberAsync(qs, 1, rng, function() {
9550
+ rsa.q.subtract(BigInteger.ONE).gcda(ee, function(r) {
9551
+ if (r.compareTo(BigInteger.ONE) == 0 && rsa.q.isProbablePrime(10)) {
9552
+ setTimeout(loop4, 0);
9553
+ } else {
9554
+ setTimeout(loop3, 0);
9555
+ }
9556
+ });
9557
+ });
9558
+ };
9559
+ var loop2 = function() {
9560
+ rsa.p = nbi();
9561
+ rsa.p.fromNumberAsync(B - qs, 1, rng, function() {
9562
+ rsa.p.subtract(BigInteger.ONE).gcda(ee, function(r) {
9563
+ if (r.compareTo(BigInteger.ONE) == 0 && rsa.p.isProbablePrime(10)) {
9564
+ setTimeout(loop3, 0);
9565
+ } else {
9566
+ setTimeout(loop2, 0);
9567
+ }
9568
+ });
9569
+ });
9570
+ };
9571
+ setTimeout(loop2, 0);
9572
+ };
9573
+ setTimeout(loop1, 0);
9574
+ };
9575
+ RSAKey2.prototype.sign = function(text, digestMethod, digestName) {
9576
+ var header = getDigestHeader(digestName);
9577
+ var digest = header + digestMethod(text).toString();
9578
+ var maxLength = this.n.bitLength() / 4;
9579
+ var m = pkcs1pad1(digest, maxLength);
9580
+ if (m == null) {
9581
+ return null;
9582
+ }
9583
+ var c = this.doPrivate(m);
9584
+ if (c == null) {
9585
+ return null;
9586
+ }
9587
+ var h = c.toString(16);
9588
+ var length = h.length;
9589
+ for (var i = 0; i < maxLength - length; i++) {
9590
+ h = "0" + h;
9591
+ }
9592
+ return h;
9593
+ };
9594
+ RSAKey2.prototype.verify = function(text, signature, digestMethod) {
9595
+ var c = parseBigInt(signature, 16);
9596
+ var m = this.doPublic(c);
9597
+ if (m == null) {
9598
+ return null;
9599
+ }
9600
+ var unpadded = m.toString(16).replace(/^1f+00/, "");
9601
+ var digest = removeDigestHeader(unpadded);
9602
+ return digest == digestMethod(text).toString();
9603
+ };
9604
+ return RSAKey2;
9605
+ })()
9606
+ );
9607
+ function pkcs1unpad2(d, n) {
9608
+ var b = d.toByteArray();
9609
+ var i = 0;
9610
+ while (i < b.length && b[i] == 0) {
9611
+ ++i;
9612
+ }
9613
+ if (b.length - i != n - 1 || b[i] != 2) {
9614
+ return null;
9615
+ }
9616
+ ++i;
9617
+ while (b[i] != 0) {
9618
+ if (++i >= b.length) {
9619
+ return null;
9620
+ }
9621
+ }
9622
+ var ret = "";
9623
+ while (++i < b.length) {
9624
+ var c = b[i] & 255;
9625
+ if (c < 128) {
9626
+ ret += String.fromCharCode(c);
9627
+ } else if (c > 191 && c < 224) {
9628
+ ret += String.fromCharCode((c & 31) << 6 | b[i + 1] & 63);
9629
+ ++i;
9630
+ } else {
9631
+ ret += String.fromCharCode((c & 15) << 12 | (b[i + 1] & 63) << 6 | b[i + 2] & 63);
9632
+ i += 2;
9633
+ }
9634
+ }
9635
+ return ret;
9636
+ }
9637
+ var DIGEST_HEADERS = {
9638
+ md2: "3020300c06082a864886f70d020205000410",
9639
+ md5: "3020300c06082a864886f70d020505000410",
9640
+ sha1: "3021300906052b0e03021a05000414",
9641
+ sha224: "302d300d06096086480165030402040500041c",
9642
+ sha256: "3031300d060960864801650304020105000420",
9643
+ sha384: "3041300d060960864801650304020205000430",
9644
+ sha512: "3051300d060960864801650304020305000440",
9645
+ ripemd160: "3021300906052b2403020105000414"
9646
+ };
9647
+ function getDigestHeader(name) {
9648
+ return DIGEST_HEADERS[name] || "";
9649
+ }
9650
+ function removeDigestHeader(str) {
9651
+ for (var name_1 in DIGEST_HEADERS) {
9652
+ if (DIGEST_HEADERS.hasOwnProperty(name_1)) {
9653
+ var header = DIGEST_HEADERS[name_1];
9654
+ var len = header.length;
9655
+ if (str.substring(0, len) == header) {
9656
+ return str.substring(len);
9657
+ }
9658
+ }
9659
+ }
9660
+ return str;
9661
+ }
9662
+ function extendClass(subc, superc, overrides) {
9663
+ if (!superc || !subc) {
9664
+ throw new Error("extend failed, please check that all dependencies are included.");
9665
+ }
9666
+ var F = function() {
9667
+ };
9668
+ F.prototype = superc.prototype;
9669
+ subc.prototype = new F();
9670
+ subc.prototype.constructor = subc;
9671
+ subc.superclass = superc.prototype;
9672
+ if (superc.prototype.constructor == Object.prototype.constructor) {
9673
+ superc.prototype.constructor = superc;
9674
+ }
9675
+ }
9676
+ /**
9677
+ * @fileOverview
9678
+ * @name asn1-1.0.js
9679
+ * @author Kenji Urushima kenji.urushima@gmail.com
9680
+ * @version asn1 1.0.13 (2017-Jun-02)
9681
+ * @since jsrsasign 2.1
9682
+ * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
9683
+ */
9684
+ var KJUR = {};
9685
+ if (typeof KJUR.asn1 == "undefined" || !KJUR.asn1)
9686
+ KJUR.asn1 = {};
9687
+ KJUR.asn1.ASN1Util = new function() {
9688
+ this.integerToByteHex = function(i) {
9689
+ var h = i.toString(16);
9690
+ if (h.length % 2 == 1)
9691
+ h = "0" + h;
9692
+ return h;
9693
+ };
9694
+ this.bigIntToMinTwosComplementsHex = function(bigIntegerValue) {
9695
+ var h = bigIntegerValue.toString(16);
9696
+ if (h.substring(0, 1) != "-") {
9697
+ if (h.length % 2 == 1) {
9698
+ h = "0" + h;
9699
+ } else {
9700
+ if (!h.match(/^[0-7]/)) {
9701
+ h = "00" + h;
9702
+ }
9703
+ }
9704
+ } else {
9705
+ var hPos = h.substring(1);
9706
+ var xorLen = hPos.length;
9707
+ if (xorLen % 2 == 1) {
9708
+ xorLen += 1;
9709
+ } else {
9710
+ if (!h.match(/^[0-7]/)) {
9711
+ xorLen += 2;
9712
+ }
9713
+ }
9714
+ var hMask = "";
9715
+ for (var i = 0; i < xorLen; i++) {
9716
+ hMask += "f";
9717
+ }
9718
+ var biMask = new BigInteger(hMask, 16);
9719
+ var biNeg = biMask.xor(bigIntegerValue).add(BigInteger.ONE);
9720
+ h = biNeg.toString(16).replace(/^-/, "");
9721
+ }
9722
+ return h;
9723
+ };
9724
+ this.getPEMStringFromHex = function(dataHex, pemHeader) {
9725
+ return hextopem(dataHex, pemHeader);
9726
+ };
9727
+ this.newObject = function(param) {
9728
+ var _KJUR = KJUR, _KJUR_asn1 = _KJUR.asn1, _DERBoolean = _KJUR_asn1.DERBoolean, _DERInteger = _KJUR_asn1.DERInteger, _DERBitString = _KJUR_asn1.DERBitString, _DEROctetString = _KJUR_asn1.DEROctetString, _DERNull = _KJUR_asn1.DERNull, _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, _DEREnumerated = _KJUR_asn1.DEREnumerated, _DERUTF8String = _KJUR_asn1.DERUTF8String, _DERNumericString = _KJUR_asn1.DERNumericString, _DERPrintableString = _KJUR_asn1.DERPrintableString, _DERTeletexString = _KJUR_asn1.DERTeletexString, _DERIA5String = _KJUR_asn1.DERIA5String, _DERUTCTime = _KJUR_asn1.DERUTCTime, _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime, _DERSequence = _KJUR_asn1.DERSequence, _DERSet = _KJUR_asn1.DERSet, _DERTaggedObject = _KJUR_asn1.DERTaggedObject, _newObject = _KJUR_asn1.ASN1Util.newObject;
9729
+ var keys = Object.keys(param);
9730
+ if (keys.length != 1)
9731
+ throw "key of param shall be only one.";
9732
+ var key = keys[0];
9733
+ if (":bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:seq:set:tag:".indexOf(":" + key + ":") == -1)
9734
+ throw "undefined key: " + key;
9735
+ if (key == "bool")
9736
+ return new _DERBoolean(param[key]);
9737
+ if (key == "int")
9738
+ return new _DERInteger(param[key]);
9739
+ if (key == "bitstr")
9740
+ return new _DERBitString(param[key]);
9741
+ if (key == "octstr")
9742
+ return new _DEROctetString(param[key]);
9743
+ if (key == "null")
9744
+ return new _DERNull(param[key]);
9745
+ if (key == "oid")
9746
+ return new _DERObjectIdentifier(param[key]);
9747
+ if (key == "enum")
9748
+ return new _DEREnumerated(param[key]);
9749
+ if (key == "utf8str")
9750
+ return new _DERUTF8String(param[key]);
9751
+ if (key == "numstr")
9752
+ return new _DERNumericString(param[key]);
9753
+ if (key == "prnstr")
9754
+ return new _DERPrintableString(param[key]);
9755
+ if (key == "telstr")
9756
+ return new _DERTeletexString(param[key]);
9757
+ if (key == "ia5str")
9758
+ return new _DERIA5String(param[key]);
9759
+ if (key == "utctime")
9760
+ return new _DERUTCTime(param[key]);
9761
+ if (key == "gentime")
9762
+ return new _DERGeneralizedTime(param[key]);
9763
+ if (key == "seq") {
9764
+ var paramList = param[key];
9765
+ var a = [];
9766
+ for (var i = 0; i < paramList.length; i++) {
9767
+ var asn1Obj = _newObject(paramList[i]);
9768
+ a.push(asn1Obj);
9769
+ }
9770
+ return new _DERSequence({ "array": a });
9771
+ }
9772
+ if (key == "set") {
9773
+ var paramList = param[key];
9774
+ var a = [];
9775
+ for (var i = 0; i < paramList.length; i++) {
9776
+ var asn1Obj = _newObject(paramList[i]);
9777
+ a.push(asn1Obj);
9778
+ }
9779
+ return new _DERSet({ "array": a });
9780
+ }
9781
+ if (key == "tag") {
9782
+ var tagParam = param[key];
9783
+ if (Object.prototype.toString.call(tagParam) === "[object Array]" && tagParam.length == 3) {
9784
+ var obj = _newObject(tagParam[2]);
9785
+ return new _DERTaggedObject({
9786
+ tag: tagParam[0],
9787
+ explicit: tagParam[1],
9788
+ obj
9789
+ });
9790
+ } else {
9791
+ var newParam = {};
9792
+ if (tagParam.explicit !== void 0)
9793
+ newParam.explicit = tagParam.explicit;
9794
+ if (tagParam.tag !== void 0)
9795
+ newParam.tag = tagParam.tag;
9796
+ if (tagParam.obj === void 0)
9797
+ throw "obj shall be specified for 'tag'.";
9798
+ newParam.obj = _newObject(tagParam.obj);
9799
+ return new _DERTaggedObject(newParam);
9800
+ }
9801
+ }
9802
+ };
9803
+ this.jsonToASN1HEX = function(param) {
9804
+ var asn1Obj = this.newObject(param);
9805
+ return asn1Obj.getEncodedHex();
9806
+ };
9807
+ }();
9808
+ KJUR.asn1.ASN1Util.oidHexToInt = function(hex) {
9809
+ var s = "";
9810
+ var i01 = parseInt(hex.substring(0, 2), 16);
9811
+ var i0 = Math.floor(i01 / 40);
9812
+ var i1 = i01 % 40;
9813
+ var s = i0 + "." + i1;
9814
+ var binbuf = "";
9815
+ for (var i = 2; i < hex.length; i += 2) {
9816
+ var value = parseInt(hex.substring(i, i + 2), 16);
9817
+ var bin = ("00000000" + value.toString(2)).slice(-8);
9818
+ binbuf = binbuf + bin.substring(1, 8);
9819
+ if (bin.substring(0, 1) == "0") {
9820
+ var bi = new BigInteger(binbuf, 2);
9821
+ s = s + "." + bi.toString(10);
9822
+ binbuf = "";
9823
+ }
9824
+ }
9825
+ return s;
9826
+ };
9827
+ KJUR.asn1.ASN1Util.oidIntToHex = function(oidString) {
9828
+ var itox = function(i2) {
9829
+ var h2 = i2.toString(16);
9830
+ if (h2.length == 1)
9831
+ h2 = "0" + h2;
9832
+ return h2;
9833
+ };
9834
+ var roidtox = function(roid) {
9835
+ var h2 = "";
9836
+ var bi = new BigInteger(roid, 10);
9837
+ var b = bi.toString(2);
9838
+ var padLen = 7 - b.length % 7;
9839
+ if (padLen == 7)
9840
+ padLen = 0;
9841
+ var bPad = "";
9842
+ for (var i2 = 0; i2 < padLen; i2++)
9843
+ bPad += "0";
9844
+ b = bPad + b;
9845
+ for (var i2 = 0; i2 < b.length - 1; i2 += 7) {
9846
+ var b8 = b.substring(i2, i2 + 7);
9847
+ if (i2 != b.length - 7)
9848
+ b8 = "1" + b8;
9849
+ h2 += itox(parseInt(b8, 2));
9850
+ }
9851
+ return h2;
9852
+ };
9853
+ if (!oidString.match(/^[0-9.]+$/)) {
9854
+ throw "malformed oid string: " + oidString;
9855
+ }
9856
+ var h = "";
9857
+ var a = oidString.split(".");
9858
+ var i0 = parseInt(a[0]) * 40 + parseInt(a[1]);
9859
+ h += itox(i0);
9860
+ a.splice(0, 2);
9861
+ for (var i = 0; i < a.length; i++) {
9862
+ h += roidtox(a[i]);
9863
+ }
9864
+ return h;
9865
+ };
9866
+ KJUR.asn1.ASN1Object = function() {
9867
+ var hV = "";
9868
+ this.getLengthHexFromValue = function() {
9869
+ if (typeof this.hV == "undefined" || this.hV == null) {
9870
+ throw "this.hV is null or undefined.";
9871
+ }
9872
+ if (this.hV.length % 2 == 1) {
9873
+ throw "value hex must be even length: n=" + hV.length + ",v=" + this.hV;
9874
+ }
9875
+ var n = this.hV.length / 2;
9876
+ var hN = n.toString(16);
9877
+ if (hN.length % 2 == 1) {
9878
+ hN = "0" + hN;
9879
+ }
9880
+ if (n < 128) {
9881
+ return hN;
9882
+ } else {
9883
+ var hNlen = hN.length / 2;
9884
+ if (hNlen > 15) {
9885
+ throw "ASN.1 length too long to represent by 8x: n = " + n.toString(16);
9886
+ }
9887
+ var head = 128 + hNlen;
9888
+ return head.toString(16) + hN;
9889
+ }
9890
+ };
9891
+ this.getEncodedHex = function() {
9892
+ if (this.hTLV == null || this.isModified) {
9893
+ this.hV = this.getFreshValueHex();
9894
+ this.hL = this.getLengthHexFromValue();
9895
+ this.hTLV = this.hT + this.hL + this.hV;
9896
+ this.isModified = false;
9897
+ }
9898
+ return this.hTLV;
9899
+ };
9900
+ this.getValueHex = function() {
9901
+ this.getEncodedHex();
9902
+ return this.hV;
9903
+ };
9904
+ this.getFreshValueHex = function() {
9905
+ return "";
9906
+ };
9907
+ };
9908
+ KJUR.asn1.DERAbstractString = function(params) {
9909
+ KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
9910
+ this.getString = function() {
9911
+ return this.s;
9912
+ };
9913
+ this.setString = function(newS) {
9914
+ this.hTLV = null;
9915
+ this.isModified = true;
9916
+ this.s = newS;
9917
+ this.hV = stohex(this.s);
9918
+ };
9919
+ this.setStringHex = function(newHexString) {
9920
+ this.hTLV = null;
9921
+ this.isModified = true;
9922
+ this.s = null;
9923
+ this.hV = newHexString;
9924
+ };
9925
+ this.getFreshValueHex = function() {
9926
+ return this.hV;
9927
+ };
9928
+ if (typeof params != "undefined") {
9929
+ if (typeof params == "string") {
9930
+ this.setString(params);
9931
+ } else if (typeof params["str"] != "undefined") {
9932
+ this.setString(params["str"]);
9933
+ } else if (typeof params["hex"] != "undefined") {
9934
+ this.setStringHex(params["hex"]);
9935
+ }
9936
+ }
9937
+ };
9938
+ extendClass(KJUR.asn1.DERAbstractString, KJUR.asn1.ASN1Object);
9939
+ KJUR.asn1.DERAbstractTime = function(params) {
9940
+ KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);
9941
+ this.localDateToUTC = function(d) {
9942
+ utc = d.getTime() + d.getTimezoneOffset() * 6e4;
9943
+ var utcDate = new Date(utc);
9944
+ return utcDate;
9945
+ };
9946
+ this.formatDate = function(dateObject, type, withMillis) {
9947
+ var pad = this.zeroPadding;
9948
+ var d = this.localDateToUTC(dateObject);
9949
+ var year = String(d.getFullYear());
9950
+ if (type == "utc")
9951
+ year = year.substring(2, 4);
9952
+ var month = pad(String(d.getMonth() + 1), 2);
9953
+ var day = pad(String(d.getDate()), 2);
9954
+ var hour = pad(String(d.getHours()), 2);
9955
+ var min = pad(String(d.getMinutes()), 2);
9956
+ var sec = pad(String(d.getSeconds()), 2);
9957
+ var s = year + month + day + hour + min + sec;
9958
+ if (withMillis === true) {
9959
+ var millis = d.getMilliseconds();
9960
+ if (millis != 0) {
9961
+ var sMillis = pad(String(millis), 3);
9962
+ sMillis = sMillis.replace(/[0]+$/, "");
9963
+ s = s + "." + sMillis;
9964
+ }
9965
+ }
9966
+ return s + "Z";
9967
+ };
9968
+ this.zeroPadding = function(s, len) {
9969
+ if (s.length >= len)
9970
+ return s;
9971
+ return new Array(len - s.length + 1).join("0") + s;
9972
+ };
9973
+ this.getString = function() {
9974
+ return this.s;
9975
+ };
9976
+ this.setString = function(newS) {
9977
+ this.hTLV = null;
9978
+ this.isModified = true;
9979
+ this.s = newS;
9980
+ this.hV = stohex(newS);
9981
+ };
9982
+ this.setByDateValue = function(year, month, day, hour, min, sec) {
9983
+ var dateObject = new Date(Date.UTC(year, month - 1, day, hour, min, sec, 0));
9984
+ this.setByDate(dateObject);
9985
+ };
9986
+ this.getFreshValueHex = function() {
9987
+ return this.hV;
9988
+ };
9989
+ };
9990
+ extendClass(KJUR.asn1.DERAbstractTime, KJUR.asn1.ASN1Object);
9991
+ KJUR.asn1.DERAbstractStructured = function(params) {
9992
+ KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
9993
+ this.setByASN1ObjectArray = function(asn1ObjectArray) {
9994
+ this.hTLV = null;
9995
+ this.isModified = true;
9996
+ this.asn1Array = asn1ObjectArray;
9997
+ };
9998
+ this.appendASN1Object = function(asn1Object) {
9999
+ this.hTLV = null;
10000
+ this.isModified = true;
10001
+ this.asn1Array.push(asn1Object);
10002
+ };
10003
+ this.asn1Array = new Array();
10004
+ if (typeof params != "undefined") {
10005
+ if (typeof params["array"] != "undefined") {
10006
+ this.asn1Array = params["array"];
10007
+ }
10008
+ }
10009
+ };
10010
+ extendClass(KJUR.asn1.DERAbstractStructured, KJUR.asn1.ASN1Object);
10011
+ KJUR.asn1.DERBoolean = function() {
10012
+ KJUR.asn1.DERBoolean.superclass.constructor.call(this);
10013
+ this.hT = "01";
10014
+ this.hTLV = "0101ff";
10015
+ };
10016
+ extendClass(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object);
10017
+ KJUR.asn1.DERInteger = function(params) {
10018
+ KJUR.asn1.DERInteger.superclass.constructor.call(this);
10019
+ this.hT = "02";
10020
+ this.setByBigInteger = function(bigIntegerValue) {
10021
+ this.hTLV = null;
10022
+ this.isModified = true;
10023
+ this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
10024
+ };
10025
+ this.setByInteger = function(intValue) {
10026
+ var bi = new BigInteger(String(intValue), 10);
10027
+ this.setByBigInteger(bi);
10028
+ };
10029
+ this.setValueHex = function(newHexString) {
10030
+ this.hV = newHexString;
10031
+ };
10032
+ this.getFreshValueHex = function() {
10033
+ return this.hV;
10034
+ };
10035
+ if (typeof params != "undefined") {
10036
+ if (typeof params["bigint"] != "undefined") {
10037
+ this.setByBigInteger(params["bigint"]);
10038
+ } else if (typeof params["int"] != "undefined") {
10039
+ this.setByInteger(params["int"]);
10040
+ } else if (typeof params == "number") {
10041
+ this.setByInteger(params);
10042
+ } else if (typeof params["hex"] != "undefined") {
10043
+ this.setValueHex(params["hex"]);
10044
+ }
10045
+ }
10046
+ };
10047
+ extendClass(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object);
10048
+ KJUR.asn1.DERBitString = function(params) {
10049
+ if (params !== void 0 && typeof params.obj !== "undefined") {
10050
+ var o = KJUR.asn1.ASN1Util.newObject(params.obj);
10051
+ params.hex = "00" + o.getEncodedHex();
10052
+ }
10053
+ KJUR.asn1.DERBitString.superclass.constructor.call(this);
10054
+ this.hT = "03";
10055
+ this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) {
10056
+ this.hTLV = null;
10057
+ this.isModified = true;
10058
+ this.hV = newHexStringIncludingUnusedBits;
10059
+ };
10060
+ this.setUnusedBitsAndHexValue = function(unusedBits, hValue) {
10061
+ if (unusedBits < 0 || 7 < unusedBits) {
10062
+ throw "unused bits shall be from 0 to 7: u = " + unusedBits;
10063
+ }
10064
+ var hUnusedBits = "0" + unusedBits;
10065
+ this.hTLV = null;
10066
+ this.isModified = true;
10067
+ this.hV = hUnusedBits + hValue;
10068
+ };
10069
+ this.setByBinaryString = function(binaryString) {
10070
+ binaryString = binaryString.replace(/0+$/, "");
10071
+ var unusedBits = 8 - binaryString.length % 8;
10072
+ if (unusedBits == 8)
10073
+ unusedBits = 0;
10074
+ for (var i = 0; i <= unusedBits; i++) {
10075
+ binaryString += "0";
10076
+ }
10077
+ var h = "";
10078
+ for (var i = 0; i < binaryString.length - 1; i += 8) {
10079
+ var b = binaryString.substring(i, i + 8);
10080
+ var x = parseInt(b, 2).toString(16);
10081
+ if (x.length == 1)
10082
+ x = "0" + x;
10083
+ h += x;
10084
+ }
10085
+ this.hTLV = null;
10086
+ this.isModified = true;
10087
+ this.hV = "0" + unusedBits + h;
10088
+ };
10089
+ this.setByBooleanArray = function(booleanArray) {
10090
+ var s = "";
10091
+ for (var i = 0; i < booleanArray.length; i++) {
10092
+ if (booleanArray[i] == true) {
10093
+ s += "1";
10094
+ } else {
10095
+ s += "0";
10096
+ }
10097
+ }
10098
+ this.setByBinaryString(s);
10099
+ };
10100
+ this.newFalseArray = function(nLength) {
10101
+ var a = new Array(nLength);
10102
+ for (var i = 0; i < nLength; i++) {
10103
+ a[i] = false;
10104
+ }
10105
+ return a;
10106
+ };
10107
+ this.getFreshValueHex = function() {
10108
+ return this.hV;
10109
+ };
10110
+ if (typeof params != "undefined") {
10111
+ if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) {
10112
+ this.setHexValueIncludingUnusedBits(params);
10113
+ } else if (typeof params["hex"] != "undefined") {
10114
+ this.setHexValueIncludingUnusedBits(params["hex"]);
10115
+ } else if (typeof params["bin"] != "undefined") {
10116
+ this.setByBinaryString(params["bin"]);
10117
+ } else if (typeof params["array"] != "undefined") {
10118
+ this.setByBooleanArray(params["array"]);
10119
+ }
10120
+ }
10121
+ };
10122
+ extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object);
10123
+ KJUR.asn1.DEROctetString = function(params) {
10124
+ if (params !== void 0 && typeof params.obj !== "undefined") {
10125
+ var o = KJUR.asn1.ASN1Util.newObject(params.obj);
10126
+ params.hex = o.getEncodedHex();
10127
+ }
10128
+ KJUR.asn1.DEROctetString.superclass.constructor.call(this, params);
10129
+ this.hT = "04";
10130
+ };
10131
+ extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString);
10132
+ KJUR.asn1.DERNull = function() {
10133
+ KJUR.asn1.DERNull.superclass.constructor.call(this);
10134
+ this.hT = "05";
10135
+ this.hTLV = "0500";
10136
+ };
10137
+ extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object);
10138
+ KJUR.asn1.DERObjectIdentifier = function(params) {
10139
+ var itox = function(i) {
10140
+ var h = i.toString(16);
10141
+ if (h.length == 1)
10142
+ h = "0" + h;
10143
+ return h;
10144
+ };
10145
+ var roidtox = function(roid) {
10146
+ var h = "";
10147
+ var bi = new BigInteger(roid, 10);
10148
+ var b = bi.toString(2);
10149
+ var padLen = 7 - b.length % 7;
10150
+ if (padLen == 7)
10151
+ padLen = 0;
10152
+ var bPad = "";
10153
+ for (var i = 0; i < padLen; i++)
10154
+ bPad += "0";
10155
+ b = bPad + b;
10156
+ for (var i = 0; i < b.length - 1; i += 7) {
10157
+ var b8 = b.substring(i, i + 7);
10158
+ if (i != b.length - 7)
10159
+ b8 = "1" + b8;
10160
+ h += itox(parseInt(b8, 2));
10161
+ }
10162
+ return h;
10163
+ };
10164
+ KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this);
10165
+ this.hT = "06";
10166
+ this.setValueHex = function(newHexString) {
10167
+ this.hTLV = null;
10168
+ this.isModified = true;
10169
+ this.s = null;
10170
+ this.hV = newHexString;
10171
+ };
10172
+ this.setValueOidString = function(oidString) {
10173
+ if (!oidString.match(/^[0-9.]+$/)) {
10174
+ throw "malformed oid string: " + oidString;
10175
+ }
10176
+ var h = "";
10177
+ var a = oidString.split(".");
10178
+ var i0 = parseInt(a[0]) * 40 + parseInt(a[1]);
10179
+ h += itox(i0);
10180
+ a.splice(0, 2);
10181
+ for (var i = 0; i < a.length; i++) {
10182
+ h += roidtox(a[i]);
10183
+ }
10184
+ this.hTLV = null;
10185
+ this.isModified = true;
10186
+ this.s = null;
10187
+ this.hV = h;
10188
+ };
10189
+ this.setValueName = function(oidName) {
10190
+ var oid = KJUR.asn1.x509.OID.name2oid(oidName);
10191
+ if (oid !== "") {
10192
+ this.setValueOidString(oid);
10193
+ } else {
10194
+ throw "DERObjectIdentifier oidName undefined: " + oidName;
10195
+ }
10196
+ };
10197
+ this.getFreshValueHex = function() {
10198
+ return this.hV;
10199
+ };
10200
+ if (params !== void 0) {
10201
+ if (typeof params === "string") {
10202
+ if (params.match(/^[0-2].[0-9.]+$/)) {
10203
+ this.setValueOidString(params);
10204
+ } else {
10205
+ this.setValueName(params);
10206
+ }
10207
+ } else if (params.oid !== void 0) {
10208
+ this.setValueOidString(params.oid);
10209
+ } else if (params.hex !== void 0) {
10210
+ this.setValueHex(params.hex);
10211
+ } else if (params.name !== void 0) {
10212
+ this.setValueName(params.name);
10213
+ }
10214
+ }
10215
+ };
10216
+ extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object);
10217
+ KJUR.asn1.DEREnumerated = function(params) {
10218
+ KJUR.asn1.DEREnumerated.superclass.constructor.call(this);
10219
+ this.hT = "0a";
10220
+ this.setByBigInteger = function(bigIntegerValue) {
10221
+ this.hTLV = null;
10222
+ this.isModified = true;
10223
+ this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
10224
+ };
10225
+ this.setByInteger = function(intValue) {
10226
+ var bi = new BigInteger(String(intValue), 10);
10227
+ this.setByBigInteger(bi);
10228
+ };
10229
+ this.setValueHex = function(newHexString) {
10230
+ this.hV = newHexString;
10231
+ };
10232
+ this.getFreshValueHex = function() {
10233
+ return this.hV;
10234
+ };
10235
+ if (typeof params != "undefined") {
10236
+ if (typeof params["int"] != "undefined") {
10237
+ this.setByInteger(params["int"]);
10238
+ } else if (typeof params == "number") {
10239
+ this.setByInteger(params);
10240
+ } else if (typeof params["hex"] != "undefined") {
10241
+ this.setValueHex(params["hex"]);
10242
+ }
10243
+ }
10244
+ };
10245
+ extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object);
10246
+ KJUR.asn1.DERUTF8String = function(params) {
10247
+ KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params);
10248
+ this.hT = "0c";
10249
+ };
10250
+ extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString);
10251
+ KJUR.asn1.DERNumericString = function(params) {
10252
+ KJUR.asn1.DERNumericString.superclass.constructor.call(this, params);
10253
+ this.hT = "12";
10254
+ };
10255
+ extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString);
10256
+ KJUR.asn1.DERPrintableString = function(params) {
10257
+ KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params);
10258
+ this.hT = "13";
10259
+ };
10260
+ extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString);
10261
+ KJUR.asn1.DERTeletexString = function(params) {
10262
+ KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params);
10263
+ this.hT = "14";
10264
+ };
10265
+ extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString);
10266
+ KJUR.asn1.DERIA5String = function(params) {
10267
+ KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
10268
+ this.hT = "16";
10269
+ };
10270
+ extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString);
10271
+ KJUR.asn1.DERUTCTime = function(params) {
10272
+ KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params);
10273
+ this.hT = "17";
10274
+ this.setByDate = function(dateObject) {
10275
+ this.hTLV = null;
10276
+ this.isModified = true;
10277
+ this.date = dateObject;
10278
+ this.s = this.formatDate(this.date, "utc");
10279
+ this.hV = stohex(this.s);
10280
+ };
10281
+ this.getFreshValueHex = function() {
10282
+ if (typeof this.date == "undefined" && typeof this.s == "undefined") {
10283
+ this.date = /* @__PURE__ */ new Date();
10284
+ this.s = this.formatDate(this.date, "utc");
10285
+ this.hV = stohex(this.s);
10286
+ }
10287
+ return this.hV;
10288
+ };
10289
+ if (params !== void 0) {
10290
+ if (params.str !== void 0) {
10291
+ this.setString(params.str);
10292
+ } else if (typeof params == "string" && params.match(/^[0-9]{12}Z$/)) {
10293
+ this.setString(params);
10294
+ } else if (params.hex !== void 0) {
10295
+ this.setStringHex(params.hex);
10296
+ } else if (params.date !== void 0) {
10297
+ this.setByDate(params.date);
10298
+ }
10299
+ }
10300
+ };
10301
+ extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime);
10302
+ KJUR.asn1.DERGeneralizedTime = function(params) {
10303
+ KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params);
10304
+ this.hT = "18";
10305
+ this.withMillis = false;
10306
+ this.setByDate = function(dateObject) {
10307
+ this.hTLV = null;
10308
+ this.isModified = true;
10309
+ this.date = dateObject;
10310
+ this.s = this.formatDate(this.date, "gen", this.withMillis);
10311
+ this.hV = stohex(this.s);
10312
+ };
10313
+ this.getFreshValueHex = function() {
10314
+ if (this.date === void 0 && this.s === void 0) {
10315
+ this.date = /* @__PURE__ */ new Date();
10316
+ this.s = this.formatDate(this.date, "gen", this.withMillis);
10317
+ this.hV = stohex(this.s);
10318
+ }
10319
+ return this.hV;
10320
+ };
10321
+ if (params !== void 0) {
10322
+ if (params.str !== void 0) {
10323
+ this.setString(params.str);
10324
+ } else if (typeof params == "string" && params.match(/^[0-9]{14}Z$/)) {
10325
+ this.setString(params);
10326
+ } else if (params.hex !== void 0) {
10327
+ this.setStringHex(params.hex);
10328
+ } else if (params.date !== void 0) {
10329
+ this.setByDate(params.date);
10330
+ }
10331
+ if (params.millis === true) {
10332
+ this.withMillis = true;
10333
+ }
10334
+ }
10335
+ };
10336
+ extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime);
10337
+ KJUR.asn1.DERSequence = function(params) {
10338
+ KJUR.asn1.DERSequence.superclass.constructor.call(this, params);
10339
+ this.hT = "30";
10340
+ this.getFreshValueHex = function() {
10341
+ var h = "";
10342
+ for (var i = 0; i < this.asn1Array.length; i++) {
10343
+ var asn1Obj = this.asn1Array[i];
10344
+ h += asn1Obj.getEncodedHex();
10345
+ }
10346
+ this.hV = h;
10347
+ return this.hV;
10348
+ };
10349
+ };
10350
+ extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured);
10351
+ KJUR.asn1.DERSet = function(params) {
10352
+ KJUR.asn1.DERSet.superclass.constructor.call(this, params);
10353
+ this.hT = "31";
10354
+ this.sortFlag = true;
10355
+ this.getFreshValueHex = function() {
10356
+ var a = new Array();
10357
+ for (var i = 0; i < this.asn1Array.length; i++) {
10358
+ var asn1Obj = this.asn1Array[i];
10359
+ a.push(asn1Obj.getEncodedHex());
10360
+ }
10361
+ if (this.sortFlag == true)
10362
+ a.sort();
10363
+ this.hV = a.join("");
10364
+ return this.hV;
10365
+ };
10366
+ if (typeof params != "undefined") {
10367
+ if (typeof params.sortflag != "undefined" && params.sortflag == false)
10368
+ this.sortFlag = false;
10369
+ }
10370
+ };
10371
+ extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured);
10372
+ KJUR.asn1.DERTaggedObject = function(params) {
10373
+ KJUR.asn1.DERTaggedObject.superclass.constructor.call(this);
10374
+ this.hT = "a0";
10375
+ this.hV = "";
10376
+ this.isExplicit = true;
10377
+ this.asn1Object = null;
10378
+ this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) {
10379
+ this.hT = tagNoHex;
10380
+ this.isExplicit = isExplicitFlag;
10381
+ this.asn1Object = asn1Object;
10382
+ if (this.isExplicit) {
10383
+ this.hV = this.asn1Object.getEncodedHex();
10384
+ this.hTLV = null;
10385
+ this.isModified = true;
10386
+ } else {
10387
+ this.hV = null;
10388
+ this.hTLV = asn1Object.getEncodedHex();
10389
+ this.hTLV = this.hTLV.replace(/^../, tagNoHex);
10390
+ this.isModified = false;
10391
+ }
10392
+ };
10393
+ this.getFreshValueHex = function() {
10394
+ return this.hV;
10395
+ };
10396
+ if (typeof params != "undefined") {
10397
+ if (typeof params["tag"] != "undefined") {
10398
+ this.hT = params["tag"];
10399
+ }
10400
+ if (typeof params["explicit"] != "undefined") {
10401
+ this.isExplicit = params["explicit"];
10402
+ }
10403
+ if (typeof params["obj"] != "undefined") {
10404
+ this.asn1Object = params["obj"];
10405
+ this.setASN1Object(this.isExplicit, this.hT, this.asn1Object);
10406
+ }
10407
+ }
10408
+ };
10409
+ extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object);
10410
+ var __extends = /* @__PURE__ */ (function() {
10411
+ var extendStatics = function(d, b) {
10412
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
10413
+ d2.__proto__ = b2;
10414
+ } || function(d2, b2) {
10415
+ for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
10416
+ };
10417
+ return extendStatics(d, b);
10418
+ };
10419
+ return function(d, b) {
10420
+ if (typeof b !== "function" && b !== null)
10421
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10422
+ extendStatics(d, b);
10423
+ function __() {
10424
+ this.constructor = d;
10425
+ }
10426
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10427
+ };
10428
+ })();
10429
+ var JSEncryptRSAKey = (
10430
+ /** @class */
10431
+ (function(_super) {
10432
+ __extends(JSEncryptRSAKey2, _super);
10433
+ function JSEncryptRSAKey2(key) {
10434
+ var _this = _super.call(this) || this;
10435
+ if (key) {
10436
+ if (typeof key === "string") {
10437
+ _this.parseKey(key);
10438
+ } else if (JSEncryptRSAKey2.hasPrivateKeyProperty(key) || JSEncryptRSAKey2.hasPublicKeyProperty(key)) {
10439
+ _this.parsePropertiesFrom(key);
10440
+ }
10441
+ }
10442
+ return _this;
10443
+ }
10444
+ JSEncryptRSAKey2.prototype.parseKey = function(pem) {
10445
+ try {
10446
+ var modulus = 0;
10447
+ var public_exponent = 0;
10448
+ var reHex = /^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/;
10449
+ var der = reHex.test(pem) ? Hex.decode(pem) : Base64.unarmor(pem);
10450
+ var asn1 = ASN1.decode(der);
10451
+ if (asn1.sub.length === 3) {
10452
+ asn1 = asn1.sub[2].sub[0];
10453
+ }
10454
+ if (asn1.sub.length === 9) {
10455
+ modulus = asn1.sub[1].getHexStringValue();
10456
+ this.n = parseBigInt(modulus, 16);
10457
+ public_exponent = asn1.sub[2].getHexStringValue();
10458
+ this.e = parseInt(public_exponent, 16);
10459
+ var private_exponent = asn1.sub[3].getHexStringValue();
10460
+ this.d = parseBigInt(private_exponent, 16);
10461
+ var prime1 = asn1.sub[4].getHexStringValue();
10462
+ this.p = parseBigInt(prime1, 16);
10463
+ var prime2 = asn1.sub[5].getHexStringValue();
10464
+ this.q = parseBigInt(prime2, 16);
10465
+ var exponent1 = asn1.sub[6].getHexStringValue();
10466
+ this.dmp1 = parseBigInt(exponent1, 16);
10467
+ var exponent2 = asn1.sub[7].getHexStringValue();
10468
+ this.dmq1 = parseBigInt(exponent2, 16);
10469
+ var coefficient = asn1.sub[8].getHexStringValue();
10470
+ this.coeff = parseBigInt(coefficient, 16);
10471
+ } else if (asn1.sub.length === 2) {
10472
+ if (asn1.sub[0].sub) {
10473
+ var bit_string = asn1.sub[1];
10474
+ var sequence = bit_string.sub[0];
10475
+ modulus = sequence.sub[0].getHexStringValue();
10476
+ this.n = parseBigInt(modulus, 16);
10477
+ public_exponent = sequence.sub[1].getHexStringValue();
10478
+ this.e = parseInt(public_exponent, 16);
10479
+ } else {
10480
+ modulus = asn1.sub[0].getHexStringValue();
10481
+ this.n = parseBigInt(modulus, 16);
10482
+ public_exponent = asn1.sub[1].getHexStringValue();
10483
+ this.e = parseInt(public_exponent, 16);
10484
+ }
10485
+ } else {
10486
+ return false;
10487
+ }
10488
+ return true;
10489
+ } catch (ex) {
10490
+ return false;
10491
+ }
10492
+ };
10493
+ JSEncryptRSAKey2.prototype.getPrivateBaseKey = function() {
10494
+ var options = {
10495
+ array: [
10496
+ new KJUR.asn1.DERInteger({ int: 0 }),
10497
+ new KJUR.asn1.DERInteger({ bigint: this.n }),
10498
+ new KJUR.asn1.DERInteger({ int: this.e }),
10499
+ new KJUR.asn1.DERInteger({ bigint: this.d }),
10500
+ new KJUR.asn1.DERInteger({ bigint: this.p }),
10501
+ new KJUR.asn1.DERInteger({ bigint: this.q }),
10502
+ new KJUR.asn1.DERInteger({ bigint: this.dmp1 }),
10503
+ new KJUR.asn1.DERInteger({ bigint: this.dmq1 }),
10504
+ new KJUR.asn1.DERInteger({ bigint: this.coeff })
10505
+ ]
10506
+ };
10507
+ var seq = new KJUR.asn1.DERSequence(options);
10508
+ return seq.getEncodedHex();
10509
+ };
10510
+ JSEncryptRSAKey2.prototype.getPrivateBaseKeyB64 = function() {
10511
+ return hex2b64(this.getPrivateBaseKey());
10512
+ };
10513
+ JSEncryptRSAKey2.prototype.getPublicBaseKey = function() {
10514
+ var first_sequence = new KJUR.asn1.DERSequence({
10515
+ array: [
10516
+ new KJUR.asn1.DERObjectIdentifier({ oid: "1.2.840.113549.1.1.1" }),
10517
+ // RSA Encryption pkcs #1 oid
10518
+ new KJUR.asn1.DERNull()
10519
+ ]
10520
+ });
10521
+ var second_sequence = new KJUR.asn1.DERSequence({
10522
+ array: [
10523
+ new KJUR.asn1.DERInteger({ bigint: this.n }),
10524
+ new KJUR.asn1.DERInteger({ int: this.e })
10525
+ ]
10526
+ });
10527
+ var bit_string = new KJUR.asn1.DERBitString({
10528
+ hex: "00" + second_sequence.getEncodedHex()
10529
+ });
10530
+ var seq = new KJUR.asn1.DERSequence({
10531
+ array: [first_sequence, bit_string]
10532
+ });
10533
+ return seq.getEncodedHex();
10534
+ };
10535
+ JSEncryptRSAKey2.prototype.getPublicBaseKeyB64 = function() {
10536
+ return hex2b64(this.getPublicBaseKey());
10537
+ };
10538
+ JSEncryptRSAKey2.wordwrap = function(str, width) {
10539
+ width = width || 64;
10540
+ if (!str) {
10541
+ return str;
10542
+ }
10543
+ var regex = "(.{1," + width + "})( +|$\n?)|(.{1," + width + "})";
10544
+ return str.match(RegExp(regex, "g")).join("\n");
10545
+ };
10546
+ JSEncryptRSAKey2.prototype.getPrivateKey = function() {
10547
+ var key = "-----BEGIN RSA PRIVATE KEY-----\n";
10548
+ key += JSEncryptRSAKey2.wordwrap(this.getPrivateBaseKeyB64()) + "\n";
10549
+ key += "-----END RSA PRIVATE KEY-----";
10550
+ return key;
10551
+ };
10552
+ JSEncryptRSAKey2.prototype.getPublicKey = function() {
10553
+ var key = "-----BEGIN PUBLIC KEY-----\n";
10554
+ key += JSEncryptRSAKey2.wordwrap(this.getPublicBaseKeyB64()) + "\n";
10555
+ key += "-----END PUBLIC KEY-----";
10556
+ return key;
10557
+ };
10558
+ JSEncryptRSAKey2.hasPublicKeyProperty = function(obj) {
10559
+ obj = obj || {};
10560
+ return obj.hasOwnProperty("n") && obj.hasOwnProperty("e");
10561
+ };
10562
+ JSEncryptRSAKey2.hasPrivateKeyProperty = function(obj) {
10563
+ obj = obj || {};
10564
+ return obj.hasOwnProperty("n") && obj.hasOwnProperty("e") && obj.hasOwnProperty("d") && obj.hasOwnProperty("p") && obj.hasOwnProperty("q") && obj.hasOwnProperty("dmp1") && obj.hasOwnProperty("dmq1") && obj.hasOwnProperty("coeff");
10565
+ };
10566
+ JSEncryptRSAKey2.prototype.parsePropertiesFrom = function(obj) {
10567
+ this.n = obj.n;
10568
+ this.e = obj.e;
10569
+ if (obj.hasOwnProperty("d")) {
10570
+ this.d = obj.d;
10571
+ this.p = obj.p;
10572
+ this.q = obj.q;
10573
+ this.dmp1 = obj.dmp1;
10574
+ this.dmq1 = obj.dmq1;
10575
+ this.coeff = obj.coeff;
10576
+ }
10577
+ };
10578
+ return JSEncryptRSAKey2;
10579
+ })(RSAKey)
10580
+ );
10581
+ var _a;
10582
+ var version = typeof process !== "undefined" ? (_a = void 0) === null || _a === void 0 ? void 0 : _a.npm_package_version : void 0;
10583
+ var JSEncrypt = (
10584
+ /** @class */
10585
+ (function() {
10586
+ function JSEncrypt2(options) {
10587
+ if (options === void 0) {
10588
+ options = {};
10589
+ }
10590
+ this.default_key_size = options.default_key_size ? parseInt(options.default_key_size, 10) : 1024;
10591
+ this.default_public_exponent = options.default_public_exponent || "010001";
10592
+ this.log = options.log || false;
10593
+ this.key = options.key || null;
10594
+ }
10595
+ JSEncrypt2.prototype.setKey = function(key) {
10596
+ if (key) {
10597
+ if (this.log && this.key) {
10598
+ console.warn("A key was already set, overriding existing.");
10599
+ }
10600
+ this.key = new JSEncryptRSAKey(key);
10601
+ } else if (!this.key && this.log) {
10602
+ console.error("A key was not set.");
10603
+ }
10604
+ };
10605
+ JSEncrypt2.prototype.setPrivateKey = function(privkey) {
10606
+ this.setKey(privkey);
10607
+ };
10608
+ JSEncrypt2.prototype.setPublicKey = function(pubkey) {
10609
+ this.setKey(pubkey);
10610
+ };
10611
+ JSEncrypt2.prototype.decrypt = function(str) {
10612
+ try {
10613
+ return this.getKey().decrypt(b64tohex(str));
10614
+ } catch (ex) {
10615
+ return false;
10616
+ }
10617
+ };
10618
+ JSEncrypt2.prototype.encrypt = function(str) {
10619
+ try {
10620
+ return hex2b64(this.getKey().encrypt(str));
10621
+ } catch (ex) {
10622
+ return false;
10623
+ }
10624
+ };
10625
+ JSEncrypt2.prototype.encryptOAEP = function(str) {
10626
+ try {
10627
+ return hex2b64(this.getKey().encrypt(str, oaep_pad));
10628
+ } catch (ex) {
10629
+ return false;
10630
+ }
10631
+ };
10632
+ JSEncrypt2.prototype.sign = function(str, digestMethod, digestName) {
10633
+ if (digestMethod === void 0) {
10634
+ digestMethod = function(raw) {
10635
+ return raw;
10636
+ };
10637
+ }
10638
+ if (digestName === void 0) {
10639
+ digestName = "";
10640
+ }
10641
+ try {
10642
+ return hex2b64(this.getKey().sign(str, digestMethod, digestName));
10643
+ } catch (ex) {
10644
+ return false;
10645
+ }
10646
+ };
10647
+ JSEncrypt2.prototype.signSha256 = function(str) {
10648
+ return this.sign(str, function(text) {
10649
+ return rstr2hex(rstr_sha256(text));
10650
+ }, "sha256");
10651
+ };
10652
+ JSEncrypt2.prototype.verify = function(str, signature, digestMethod) {
10653
+ if (digestMethod === void 0) {
10654
+ digestMethod = function(raw) {
10655
+ return raw;
10656
+ };
10657
+ }
10658
+ try {
10659
+ return this.getKey().verify(str, b64tohex(signature), digestMethod);
10660
+ } catch (ex) {
10661
+ return false;
10662
+ }
10663
+ };
10664
+ JSEncrypt2.prototype.verifySha256 = function(str, signature) {
10665
+ return this.verify(str, signature, function(text) {
10666
+ return rstr2hex(rstr_sha256(text));
10667
+ });
10668
+ };
10669
+ JSEncrypt2.prototype.getKey = function(cb) {
10670
+ if (!this.key) {
10671
+ this.key = new JSEncryptRSAKey();
10672
+ if (cb && {}.toString.call(cb) === "[object Function]") {
10673
+ this.key.generateAsync(this.default_key_size, this.default_public_exponent, cb);
10674
+ return;
10675
+ }
10676
+ this.key.generate(this.default_key_size, this.default_public_exponent);
10677
+ }
10678
+ return this.key;
10679
+ };
10680
+ JSEncrypt2.prototype.getPrivateKey = function() {
10681
+ return this.getKey().getPrivateKey();
10682
+ };
10683
+ JSEncrypt2.prototype.getPrivateKeyB64 = function() {
10684
+ return this.getKey().getPrivateBaseKeyB64();
10685
+ };
10686
+ JSEncrypt2.prototype.getPublicKey = function() {
10687
+ return this.getKey().getPublicKey();
10688
+ };
10689
+ JSEncrypt2.prototype.getPublicKeyB64 = function() {
10690
+ return this.getKey().getPublicBaseKeyB64();
10691
+ };
10692
+ JSEncrypt2.version = version;
10693
+ return JSEncrypt2;
10694
+ })()
10695
+ );
10696
+ function encrypt(publicKey, txt) {
10697
+ const encryptor = new JSEncrypt();
10698
+ encryptor.setPublicKey(publicKey);
10699
+ return encryptor.encrypt(txt);
10700
+ }
10701
+ function decrypt(privateKey, txt) {
10702
+ const encryptor = new JSEncrypt();
10703
+ encryptor.setPrivateKey(privateKey);
10704
+ return encryptor.decrypt(txt);
10705
+ }
6794
10706
  function to(promise, errorExt) {
6795
10707
  return promise.then((data) => [null, data]).catch((err) => {
6796
10708
  if (errorExt) {
@@ -8443,10 +12355,12 @@ function useServicePagination({
8443
12355
  };
8444
12356
  }
8445
12357
  exports.createEnum = createEnum;
12358
+ exports.decrypt = decrypt;
8446
12359
  exports.decryptBase64 = decryptBase64;
8447
12360
  exports.deleteUrlParams = deleteUrlParams;
8448
12361
  exports.devProxy = devProxy;
8449
12362
  exports.easyCopy = easyCopy;
12363
+ exports.encrypt = encrypt;
8450
12364
  exports.encryptBase64 = encryptBase64;
8451
12365
  exports.encryptWithAes = encryptWithAes;
8452
12366
  exports.extractSlotsWithPrefix = extractSlotsWithPrefix;