'use strict';

let hexcase = 0;
let b64pad = "";
function hex_sha1(s) {
  return rstr2hex(rstr_sha1(str2rstr_utf8(s)));
}
function b64_sha1(s) {
  return rstr2b64(rstr_sha1(str2rstr_utf8(s)));
}
function any_sha1(s, e) {
  return rstr2any(rstr_sha1(str2rstr_utf8(s)), e);
}
function hex_hmac_sha1(k, d) {
  return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)));
}
function b64_hmac_sha1(k, d) {
  return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)));
}
function any_hmac_sha1(k, d, e) {
  return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e);
}
function rstr_sha1(s) {
  return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));
}
function rstr_hmac_sha1(key, data) {
  let bkey = rstr2binb(key);
  if (bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);
  const ipad = Array.from({ length: 16 }), opad = Array.from({ length: 16 });
  for (let i = 0; i < 16; i++) {
    ipad[i] = bkey[i] ^ 909522486;
    opad[i] = bkey[i] ^ 1549556828;
  }
  const hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
  return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));
}
function rstr2hex(input) {
  try {
    hexcase;
  } catch {
    hexcase = 0;
  }
  const hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  let output = "";
  let x;
  for (let i = 0; i < input.length; i++) {
    x = input.charCodeAt(i);
    output += hex_tab.charAt(x >>> 4 & 15) + hex_tab.charAt(x & 15);
  }
  return output;
}
function rstr2b64(input) {
  try {
    b64pad;
  } catch {
    b64pad = "";
  }
  const tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  let output = "";
  const len = input.length;
  for (let i = 0; i < len; i += 3) {
    const triplet = input.charCodeAt(i) << 16 | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
    for (let j = 0; j < 4; j++) {
      if (i * 8 + j * 6 > input.length * 8) output += b64pad;
      else output += tab.charAt(triplet >>> 6 * (3 - j) & 63);
    }
  }
  return output;
}
function rstr2any(input, encoding) {
  const divisor = encoding.length;
  const remainders = [];
  let i, q, x, quotient;
  let dividend = Array.from({ length: Math.ceil(input.length / 2) });
  for (i = 0; i < dividend.length; i++) {
    dividend[i] = input.charCodeAt(i * 2) << 8 | input.charCodeAt(i * 2 + 1);
  }
  while (dividend.length > 0) {
    quotient = [];
    x = 0;
    for (i = 0; i < dividend.length; i++) {
      x = (x << 16) + dividend[i];
      q = Math.floor(x / divisor);
      x -= q * divisor;
      if (quotient.length > 0 || q > 0) quotient[quotient.length] = q;
    }
    remainders[remainders.length] = x;
    dividend = quotient;
  }
  let output = "";
  for (i = remainders.length - 1; i >= 0; i--) output += encoding.charAt(remainders[i]);
  const full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
  for (i = output.length; i < full_length; i++) output = encoding[0] + output;
  return output;
}
function str2rstr_utf8(input) {
  let output = "";
  let i = -1;
  let x, y;
  while (++i < input.length) {
    x = input.charCodeAt(i);
    y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
    if (55296 <= x && x <= 56319 && 56320 <= y && y <= 57343) {
      x = 65536 + ((x & 1023) << 10) + (y & 1023);
      i++;
    }
    if (x <= 127) output += String.fromCharCode(x);
    else if (x <= 2047) output += String.fromCharCode(192 | x >>> 6 & 31, 128 | x & 63);
    else if (x <= 65535) output += String.fromCharCode(224 | x >>> 12 & 15, 128 | x >>> 6 & 63, 128 | x & 63);
    else if (x <= 2097151)
      output += String.fromCharCode(240 | x >>> 18 & 7, 128 | x >>> 12 & 63, 128 | x >>> 6 & 63, 128 | x & 63);
  }
  return output;
}
function rstr2binb(input) {
  const output = Array.from({ length: input.length >> 2 });
  for (let i = 0; i < output.length; i++) output[i] = 0;
  for (let i = 0; i < input.length * 8; i += 8) output[i >> 5] |= (input.charCodeAt(i / 8) & 255) << 24 - i % 32;
  return output;
}
function binb2rstr(input) {
  let output = "";
  for (let i = 0; i < input.length * 32; i += 8) output += String.fromCharCode(input[i >> 5] >>> 24 - i % 32 & 255);
  return output;
}
function binb_sha1(x, len) {
  x[len >> 5] |= 128 << 24 - len % 32;
  x[(len + 64 >> 9 << 4) + 15] = len;
  const w = Array.from({ length: 80 });
  let a = 1732584193;
  let b = -271733879;
  let c = -1732584194;
  let d = 271733878;
  let e = -1009589776;
  for (let i = 0; i < x.length; i += 16) {
    const olda = a;
    const oldb = b;
    const oldc = c;
    const oldd = d;
    const olde = e;
    for (let j = 0; j < 80; j++) {
      if (j < 16) w[j] = x[i + j];
      else w[j] = bit_rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
      const t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)), safe_add(safe_add(e, w[j]), sha1_kt(j)));
      e = d;
      d = c;
      c = bit_rol(b, 30);
      b = a;
      a = t;
    }
    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
    e = safe_add(e, olde);
  }
  return [a, b, c, d, e];
}
function sha1_ft(t, b, c, d) {
  if (t < 20) return b & c | ~b & d;
  if (t < 40) return b ^ c ^ d;
  if (t < 60) return b & c | b & d | c & d;
  return b ^ c ^ d;
}
function sha1_kt(t) {
  return t < 20 ? 1518500249 : t < 40 ? 1859775393 : t < 60 ? -1894007588 : -899497514;
}
function safe_add(x, y) {
  const lsw = (x & 65535) + (y & 65535);
  const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return msw << 16 | lsw & 65535;
}
function bit_rol(num, cnt) {
  return num << cnt | num >>> 32 - cnt;
}

exports.any_hmac_sha1 = any_hmac_sha1;
exports.any_sha1 = any_sha1;
exports.b64_hmac_sha1 = b64_hmac_sha1;
exports.b64_sha1 = b64_sha1;
exports.hex_hmac_sha1 = hex_hmac_sha1;
exports.hex_sha1 = hex_sha1;
//# sourceMappingURL=sha1.js.map
