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