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