diff --git a/dist/monkey.js b/dist/monkey.js index 5a3156f..217cd0a 100644 --- a/dist/monkey.js +++ b/dist/monkey.js @@ -77,13 +77,10 @@ return /******/ (function(modules) { // webpackBootstrap var db = __webpack_require__(24); var NodeRSA = __webpack_require__(25); var CryptoJS = __webpack_require__(10).CryptoJS; - var async = __webpack_require__(66); - var Push = __webpack_require__(69); + var async = __webpack_require__(99); + var Push = __webpack_require__(101); - /* global Offline */ - __webpack_require__(70); - - var zlib = __webpack_require__(71); + var zlib = __webpack_require__(102); var MESSAGE_EVENT = 'Message'; var MESSAGE_SYNC_EVENT = 'MessageSync'; @@ -113,7 +110,7 @@ return /******/ (function(modules) { // webpackBootstrap var EXIT_EVENT = 'Exit'; - __webpack_require__(100).polyfill(); + __webpack_require__(115).polyfill(); (function () { 'use strict'; @@ -221,30 +218,6 @@ return /******/ (function(modules) { // webpackBootstrap //setup socketConnection this.socketConnection = null; - /*Offline.options = {checks: {xhr: {url: 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url=www.google.com&format=json'}}}; - //setup offline events - Offline.on('confirmed-up', function () { - let storedMonkeyId = db.getMonkeyId(); - //if no user logged in, do nothing - if (storedMonkeyId == null || storedMonkeyId === '') { - return; - } - if (this.socketConnection == null && storedMonkeyId != null && storedMonkeyId !== '') { - this.startConnection(); - return; - } - }.bind(this)); - Offline.on('confirmed-down', function () { - if (this.socketConnection != null) { - this.socketConnection.onclose = function(){}; - this.socketConnection.close(); - this.socketConnection = null; - } - this.status=this.enums.Status.OFFLINE; - this._getEmitter().emit(STATUS_CHANGE_EVENT, this.status); - this._getEmitter().emit(DISCONNECT_EVENT, this.status); - }.bind(this));*/ - this.ping(); var storedMonkeyId = db.getMonkeyId(); @@ -286,8 +259,7 @@ return /******/ (function(modules) { // webpackBootstrap proto.checkConnectivity = function checkConnectivity() { if (!this.internet) { var xhr = new (window.ActiveXObject || XMLHttpRequest)("Microsoft.XMLHTTP"); - - xhr.open("GET", "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22www.google.com%22&format=json", true); + xhr.open("GET", "https://" + this.domainUrl + "/ping", true); xhr.onerror = function (e) { if (this.socketConnection != null) { @@ -2210,7 +2182,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 1 */ /***/ function(module, exports, __webpack_require__) { - /* WEBPACK VAR INJECTION */(function(Buffer, global) {/*! + /* WEBPACK VAR INJECTION */(function(global) {/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh @@ -4000,7 +3972,7 @@ return /******/ (function(modules) { // webpackBootstrap return val !== val // eslint-disable-line no-self-compare } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer, (function() { return this; }()))) + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) /***/ }, /* 2 */ @@ -7621,6 +7593,10 @@ return /******/ (function(modules) { // webpackBootstrap }); // end of AJAX CALL }; + apiconnector.getBasicAuth = function () { + return this.getAuthParamsBtoA(main.appKey + ":" + main.appSecret); + }; + apiconnector.getAuthParamsBtoA = function (connectAuthParamsString) { //window.btoa not supported in <=IE9 @@ -8967,11 +8943,11 @@ return /******/ (function(modules) { // webpackBootstrap var constants = __webpack_require__(26); var rsa = __webpack_require__(27); var crypt = __webpack_require__(30); - var ber = __webpack_require__(55).Ber; + var ber = __webpack_require__(88).Ber; var _ = __webpack_require__(28)._; var utils = __webpack_require__(28); - var schemes = __webpack_require__(49); - var formats = __webpack_require__(62); + var schemes = __webpack_require__(82); + var formats = __webpack_require__(95); if (typeof constants.RSA_NO_PADDING == "undefined") { //patch for node v0.10.x, constants do not defined @@ -9381,6 +9357,7 @@ return /******/ (function(modules) { // webpackBootstrap "O_NOFOLLOW": 256, "O_SYNC": 128, "O_SYMLINK": 2097152, + "O_NONBLOCK": 4, "S_IRWXU": 448, "S_IRUSR": 256, "S_IWUSR": 128, @@ -9509,11 +9486,11 @@ return /******/ (function(modules) { // webpackBootstrap "SSL_OP_COOKIE_EXCHANGE": 8192, "SSL_OP_CRYPTOPRO_TLSEXT_BUG": 2147483648, "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS": 2048, - "SSL_OP_EPHEMERAL_RSA": 2097152, + "SSL_OP_EPHEMERAL_RSA": 0, "SSL_OP_LEGACY_SERVER_CONNECT": 4, "SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER": 32, "SSL_OP_MICROSOFT_SESS_ID_BUG": 1, - "SSL_OP_MSIE_SSLV2_RSA_PADDING": 64, + "SSL_OP_MSIE_SSLV2_RSA_PADDING": 0, "SSL_OP_NETSCAPE_CA_DN_BUG": 536870912, "SSL_OP_NETSCAPE_CHALLENGE_BUG": 2, "SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG": 1073741824, @@ -9532,11 +9509,41 @@ return /******/ (function(modules) { // webpackBootstrap "SSL_OP_SINGLE_DH_USE": 1048576, "SSL_OP_SINGLE_ECDH_USE": 524288, "SSL_OP_SSLEAY_080_CLIENT_DH_BUG": 128, - "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG": 16, + "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG": 0, "SSL_OP_TLS_BLOCK_PADDING_BUG": 512, "SSL_OP_TLS_D5_BUG": 256, "SSL_OP_TLS_ROLLBACK_BUG": 8388608, - "NPN_ENABLED": 1 + "ENGINE_METHOD_DSA": 2, + "ENGINE_METHOD_DH": 4, + "ENGINE_METHOD_RAND": 8, + "ENGINE_METHOD_ECDH": 16, + "ENGINE_METHOD_ECDSA": 32, + "ENGINE_METHOD_CIPHERS": 64, + "ENGINE_METHOD_DIGESTS": 128, + "ENGINE_METHOD_STORE": 256, + "ENGINE_METHOD_PKEY_METHS": 512, + "ENGINE_METHOD_PKEY_ASN1_METHS": 1024, + "ENGINE_METHOD_ALL": 65535, + "ENGINE_METHOD_NONE": 0, + "DH_CHECK_P_NOT_SAFE_PRIME": 2, + "DH_CHECK_P_NOT_PRIME": 1, + "DH_UNABLE_TO_CHECK_GENERATOR": 4, + "DH_NOT_SUITABLE_GENERATOR": 8, + "NPN_ENABLED": 1, + "RSA_PKCS1_PADDING": 1, + "RSA_SSLV23_PADDING": 2, + "RSA_NO_PADDING": 3, + "RSA_PKCS1_OAEP_PADDING": 4, + "RSA_X931_PADDING": 5, + "RSA_PKCS1_PSS_PADDING": 6, + "POINT_CONVERSION_COMPRESSED": 2, + "POINT_CONVERSION_UNCOMPRESSED": 4, + "POINT_CONVERSION_HYBRID": 6, + "F_OK": 0, + "R_OK": 4, + "W_OK": 2, + "X_OK": 1, + "UV_UDP_REUSEADDR": 4 }; /***/ }, @@ -9586,10 +9593,10 @@ return /******/ (function(modules) { // webpackBootstrap var _ = __webpack_require__(28)._; var crypt = __webpack_require__(30); - var BigInteger = __webpack_require__(48); + var BigInteger = __webpack_require__(81); var utils = __webpack_require__(28); - var schemes = __webpack_require__(49); - var encryptEngines = __webpack_require__(53); + var schemes = __webpack_require__(82); + var encryptEngines = __webpack_require__(86); exports.BigInteger = BigInteger; module.exports.Key = (function () { @@ -10182,14 +10189,10 @@ return /******/ (function(modules) { // webpackBootstrap var p = __webpack_require__(46)(exports) exports.pbkdf2 = p.pbkdf2 exports.pbkdf2Sync = p.pbkdf2Sync - + __webpack_require__(48)(exports, module.exports); // the least I can do is make error messages for the rest of the node.js/crypto api. each(['createCredentials' - , 'createCipher' - , 'createCipheriv' - , 'createDecipher' - , 'createDecipheriv' , 'createSign' , 'createVerify' , 'createDiffieHellman' @@ -12135,12536 +12138,13303 @@ return /******/ (function(modules) { // webpackBootstrap /* 48 */ /***/ function(module, exports, __webpack_require__) { - /* WEBPACK VAR INJECTION */(function(Buffer) {/* - * Basic JavaScript BN library - subset useful for RSA encryption. - * - * Copyright (c) 2003-2005 Tom Wu - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, - * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - * - * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF - * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT - * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * In addition, the following condition applies: - * - * All redistributions must retain an intact copy of this copyright notice - * and disclaimer. - */ + module.exports = function (crypto, exports) { + exports = exports || {}; + var ciphers = __webpack_require__(49)(crypto); + exports.createCipher = ciphers.createCipher; + exports.createCipheriv = ciphers.createCipheriv; + var deciphers = __webpack_require__(80)(crypto); + exports.createDecipher = deciphers.createDecipher; + exports.createDecipheriv = deciphers.createDecipheriv; + var modes = __webpack_require__(71); + function listCiphers () { + return Object.keys(modes); + } + exports.listCiphers = listCiphers; + }; - /* - * Added Node.js Buffers support - * 2014 rzcoder - */ - var crypt = __webpack_require__(30); - var _ = __webpack_require__(28)._; - // Bits per digit - var dbits; +/***/ }, +/* 49 */ +/***/ function(module, exports, __webpack_require__) { - // JavaScript engine analysis - var canary = 0xdeadbeefcafe; - var j_lm = ((canary & 0xffffff) == 0xefcafe); + /* WEBPACK VAR INJECTION */(function(Buffer) {var aes = __webpack_require__(50); + var Transform = __webpack_require__(51); + var inherits = __webpack_require__(53); + var modes = __webpack_require__(71); + var ebtk = __webpack_require__(72); + var StreamCipher = __webpack_require__(73); + inherits(Cipher, Transform); + function Cipher(mode, key, iv) { + if (!(this instanceof Cipher)) { + return new Cipher(mode, key, iv); + } + Transform.call(this); + this._cache = new Splitter(); + this._cipher = new aes.AES(key); + this._prev = new Buffer(iv.length); + iv.copy(this._prev); + this._mode = mode; + } + Cipher.prototype._transform = function (data, _, next) { + this._cache.add(data); + var chunk; + var thing; + while ((chunk = this._cache.get())) { + thing = this._mode.encrypt(this, chunk); + this.push(thing); + } + next(); + }; + Cipher.prototype._flush = function (next) { + var chunk = this._cache.flush(); + this.push(this._mode.encrypt(this, chunk)); + this._cipher.scrub(); + next(); + }; - // (public) Constructor - function BigInteger(a, b) { - if (a != null) { - if ("number" == typeof a) { - this.fromNumber(a, b); - } else if (Buffer.isBuffer(a)) { - this.fromBuffer(a); - } else if (b == null && "string" != typeof a) { - this.fromByteArray(a); - } else { - this.fromString(a, b); - } - } - } - // return new, unset BigInteger - function nbi() { - return new BigInteger(null); + function Splitter() { + if (!(this instanceof Splitter)) { + return new Splitter(); + } + this.cache = new Buffer(''); } + Splitter.prototype.add = function (data) { + this.cache = Buffer.concat([this.cache, data]); + }; - // am: Compute w_j += (x*this_i), propagate carries, - // c is initial carry, returns final carry. - // c < 3*dvalue, x < 2*dvalue, this_i < dvalue - // We need to select the fastest one that works in this environment. + Splitter.prototype.get = function () { + if (this.cache.length > 15) { + var out = this.cache.slice(0, 16); + this.cache = this.cache.slice(16); + return out; + } + return null; + }; + Splitter.prototype.flush = function () { + var len = 16 - this.cache.length; + var padBuff = new Buffer(len); - // am1: use a single mult and divide to get the high bits, - // max digit bits should be 26 because - // max internal value = 2*dvalue^2-2*dvalue (< 2^53) - function am1(i, x, w, j, c, n) { - while (--n >= 0) { - var v = x * this[i++] + w[j] + c; - c = Math.floor(v / 0x4000000); - w[j++] = v & 0x3ffffff; + var i = -1; + while (++i < len) { + padBuff.writeUInt8(len, i); + } + var out = Buffer.concat([this.cache, padBuff]); + return out; + }; + var modelist = { + ECB: __webpack_require__(74), + CBC: __webpack_require__(75), + CFB: __webpack_require__(77), + OFB: __webpack_require__(78), + CTR: __webpack_require__(79) + }; + module.exports = function (crypto) { + function createCipheriv(suite, password, iv) { + var config = modes[suite]; + if (!config) { + throw new TypeError('invalid suite type'); } - return c; - } - // am2 avoids a big mult-and-extract completely. - // Max digit bits should be <= 30 because we do bitwise ops - // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) - function am2(i, x, w, j, c, n) { - var xl = x & 0x7fff, xh = x >> 15; - while (--n >= 0) { - var l = this[i] & 0x7fff; - var h = this[i++] >> 15; - var m = xh * l + h * xl; - l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff); - c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30); - w[j++] = l & 0x3fffffff; + if (typeof iv === 'string') { + iv = new Buffer(iv); } - return c; - } - // Alternately, set max digit bits to 28 since some - // browsers slow down when dealing with 32-bit numbers. - function am3(i, x, w, j, c, n) { - var xl = x & 0x3fff, xh = x >> 14; - while (--n >= 0) { - var l = this[i] & 0x3fff; - var h = this[i++] >> 14; - var m = xh * l + h * xl; - l = xl * l + ((m & 0x3fff) << 14) + w[j] + c; - c = (l >> 28) + (m >> 14) + xh * h; - w[j++] = l & 0xfffffff; + if (typeof password === 'string') { + password = new Buffer(password); } - return c; + if (password.length !== config.key/8) { + throw new TypeError('invalid key length ' + password.length); + } + if (iv.length !== config.iv) { + throw new TypeError('invalid iv length ' + iv.length); + } + if (config.type === 'stream') { + return new StreamCipher(modelist[config.mode], password, iv); + } + return new Cipher(modelist[config.mode], password, iv); + } + function createCipher (suite, password) { + var config = modes[suite]; + if (!config) { + throw new TypeError('invalid suite type'); + } + var keys = ebtk(crypto, password, config.key, config.iv); + return createCipheriv(suite, keys.key, keys.iv); + } + return { + createCipher: createCipher, + createCipheriv: createCipheriv + }; + }; + + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) + +/***/ }, +/* 50 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(Buffer) {var uint_max = Math.pow(2, 32); + function fixup_uint32(x) { + var ret, x_pos; + ret = x > uint_max || x < 0 ? (x_pos = Math.abs(x) % uint_max, x < 0 ? uint_max - x_pos : x_pos) : x; + return ret; + } + function scrub_vec(v) { + var i, _i, _ref; + for (i = _i = 0, _ref = v.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + v[i] = 0; + } + return false; } - // We need to select the fastest one that works in this environment. - //if (j_lm && (navigator.appName == "Microsoft Internet Explorer")) { - // BigInteger.prototype.am = am2; - // dbits = 30; - //} else if (j_lm && (navigator.appName != "Netscape")) { - // BigInteger.prototype.am = am1; - // dbits = 26; - //} else { // Mozilla/Netscape seems to prefer am3 - // BigInteger.prototype.am = am3; - // dbits = 28; - //} + function Global() { + var i; + this.SBOX = []; + this.INV_SBOX = []; + this.SUB_MIX = (function() { + var _i, _results; + _results = []; + for (i = _i = 0; _i < 4; i = ++_i) { + _results.push([]); + } + return _results; + })(); + this.INV_SUB_MIX = (function() { + var _i, _results; + _results = []; + for (i = _i = 0; _i < 4; i = ++_i) { + _results.push([]); + } + return _results; + })(); + this.init(); + this.RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; + } + + Global.prototype.init = function() { + var d, i, sx, t, x, x2, x4, x8, xi, _i; + d = (function() { + var _i, _results; + _results = []; + for (i = _i = 0; _i < 256; i = ++_i) { + if (i < 128) { + _results.push(i << 1); + } else { + _results.push((i << 1) ^ 0x11b); + } + } + return _results; + })(); + x = 0; + xi = 0; + for (i = _i = 0; _i < 256; i = ++_i) { + sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); + sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; + this.SBOX[x] = sx; + this.INV_SBOX[sx] = x; + x2 = d[x]; + x4 = d[x2]; + x8 = d[x4]; + t = (d[sx] * 0x101) ^ (sx * 0x1010100); + this.SUB_MIX[0][x] = (t << 24) | (t >>> 8); + this.SUB_MIX[1][x] = (t << 16) | (t >>> 16); + this.SUB_MIX[2][x] = (t << 8) | (t >>> 24); + this.SUB_MIX[3][x] = t; + t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); + this.INV_SUB_MIX[0][sx] = (t << 24) | (t >>> 8); + this.INV_SUB_MIX[1][sx] = (t << 16) | (t >>> 16); + this.INV_SUB_MIX[2][sx] = (t << 8) | (t >>> 24); + this.INV_SUB_MIX[3][sx] = t; + if (x === 0) { + x = xi = 1; + } else { + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; + } + } + return true; + }; - // For node.js, we pick am3 with max dbits to 28. - BigInteger.prototype.am = am3; - dbits = 28; + var G = new Global(); - BigInteger.prototype.DB = dbits; - BigInteger.prototype.DM = ((1 << dbits) - 1); - BigInteger.prototype.DV = (1 << dbits); - var BI_FP = 52; - BigInteger.prototype.FV = Math.pow(2, BI_FP); - BigInteger.prototype.F1 = BI_FP - dbits; - BigInteger.prototype.F2 = 2 * dbits - BI_FP; + AES.blockSize = 4 * 4; - // Digit conversions - var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"; - var BI_RC = new Array(); - var rr, vv; - rr = "0".charCodeAt(0); - for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv; - rr = "a".charCodeAt(0); - for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; - rr = "A".charCodeAt(0); - for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv; + AES.prototype.blockSize = AES.blockSize; - function int2char(n) { - return BI_RM.charAt(n); - } - function intAt(s, i) { - var c = BI_RC[s.charCodeAt(i)]; - return (c == null) ? -1 : c; - } + AES.keySize = 256 / 8; - // (protected) copy this to r - function bnpCopyTo(r) { - for (var i = this.t - 1; i >= 0; --i) r[i] = this[i]; - r.t = this.t; - r.s = this.s; - } + AES.prototype.keySize = AES.keySize; - // (protected) set from integer value x, -DV <= x < DV - function bnpFromInt(x) { - this.t = 1; - this.s = (x < 0) ? -1 : 0; - if (x > 0) this[0] = x; - else if (x < -1) this[0] = x + DV; - else this.t = 0; - } + AES.ivSize = AES.blockSize; - // return bigint initialized to value - function nbv(i) { - var r = nbi(); - r.fromInt(i); - return r; + AES.prototype.ivSize = AES.ivSize; + + function bufferToArray(buf) { + var len = buf.length/4; + var out = new Array(len); + var i = -1; + while (++i < len) { + out[i] = buf.readUInt32BE(i * 4); + } + return out; + } + function AES(key) { + this._key = bufferToArray(key); + this._doReset(); } - // (protected) set from string and radix - function bnpFromString(data, radix, unsigned) { - var k; - switch (radix) { - case 2: - k = 1; - break; - case 4: - k = 2; - break; - case 8: - k = 3; - break; - case 16: - k = 4; - break; - case 32: - k = 5; - break; - case 256: - k = 8; - break; - default: - this.fromRadix(data, radix); - return; - } + AES.prototype._doReset = function() { + var invKsRow, keySize, keyWords, ksRow, ksRows, t, _i, _j; + keyWords = this._key; + keySize = keyWords.length; + this._nRounds = keySize + 6; + ksRows = (this._nRounds + 1) * 4; + this._keySchedule = []; + for (ksRow = _i = 0; 0 <= ksRows ? _i < ksRows : _i > ksRows; ksRow = 0 <= ksRows ? ++_i : --_i) { + this._keySchedule[ksRow] = ksRow < keySize ? keyWords[ksRow] : (t = this._keySchedule[ksRow - 1], (ksRow % keySize) === 0 ? (t = (t << 8) | (t >>> 24), t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff], t ^= G.RCON[(ksRow / keySize) | 0] << 24) : keySize > 6 && ksRow % keySize === 4 ? t = (G.SBOX[t >>> 24] << 24) | (G.SBOX[(t >>> 16) & 0xff] << 16) | (G.SBOX[(t >>> 8) & 0xff] << 8) | G.SBOX[t & 0xff] : void 0, this._keySchedule[ksRow - keySize] ^ t); + } + this._invKeySchedule = []; + for (invKsRow = _j = 0; 0 <= ksRows ? _j < ksRows : _j > ksRows; invKsRow = 0 <= ksRows ? ++_j : --_j) { + ksRow = ksRows - invKsRow; + t = this._keySchedule[ksRow - (invKsRow % 4 ? 0 : 4)]; + this._invKeySchedule[invKsRow] = invKsRow < 4 || ksRow <= 4 ? t : G.INV_SUB_MIX[0][G.SBOX[t >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[(t >>> 16) & 0xff]] ^ G.INV_SUB_MIX[2][G.SBOX[(t >>> 8) & 0xff]] ^ G.INV_SUB_MIX[3][G.SBOX[t & 0xff]]; + } + return true; + }; - this.t = 0; - this.s = 0; + AES.prototype.encryptBlock = function(M) { + M = bufferToArray(new Buffer(M)); + var out = this._doCryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX); + var buf = new Buffer(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[1], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[3], 12); + return buf; + }; - var i = data.length; - var mi = false; - var sh = 0; + AES.prototype.decryptBlock = function(M) { + M = bufferToArray(new Buffer(M)); + var temp = [M[3], M[1]]; + M[1] = temp[0]; + M[3] = temp[1]; + var out = this._doCryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX); + var buf = new Buffer(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[3], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[1], 12); + return buf; + }; - while (--i >= 0) { - var x = (k == 8) ? data[i] & 0xff : intAt(data, i); - if (x < 0) { - if (data.charAt(i) == "-") mi = true; - continue; - } - mi = false; - if (sh === 0) - this[this.t++] = x; - else if (sh + k > this.DB) { - this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh; - this[this.t++] = (x >> (this.DB - sh)); - } - else - this[this.t - 1] |= x << sh; - sh += k; - if (sh >= this.DB) sh -= this.DB; - } - if ((!unsigned) && k == 8 && (data[0] & 0x80) != 0) { - this.s = -1; - if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh; - } - this.clamp(); - if (mi) BigInteger.ZERO.subTo(this, this); - } + AES.prototype.scrub = function() { + scrub_vec(this._keySchedule); + scrub_vec(this._invKeySchedule); + scrub_vec(this._key); + }; - function bnpFromByteArray(a, unsigned) { - this.fromString(a, 256, unsigned) - } + AES.prototype._doCryptBlock = function(M, keySchedule, SUB_MIX, SBOX) { + var ksRow, round, s0, s1, s2, s3, t0, t1, t2, t3, _i, _ref; + + s0 = M[0] ^ keySchedule[0]; + s1 = M[1] ^ keySchedule[1]; + s2 = M[2] ^ keySchedule[2]; + s3 = M[3] ^ keySchedule[3]; + ksRow = 4; + for (round = _i = 1, _ref = this._nRounds; 1 <= _ref ? _i < _ref : _i > _ref; round = 1 <= _ref ? ++_i : --_i) { + t0 = SUB_MIX[0][s0 >>> 24] ^ SUB_MIX[1][(s1 >>> 16) & 0xff] ^ SUB_MIX[2][(s2 >>> 8) & 0xff] ^ SUB_MIX[3][s3 & 0xff] ^ keySchedule[ksRow++]; + t1 = SUB_MIX[0][s1 >>> 24] ^ SUB_MIX[1][(s2 >>> 16) & 0xff] ^ SUB_MIX[2][(s3 >>> 8) & 0xff] ^ SUB_MIX[3][s0 & 0xff] ^ keySchedule[ksRow++]; + t2 = SUB_MIX[0][s2 >>> 24] ^ SUB_MIX[1][(s3 >>> 16) & 0xff] ^ SUB_MIX[2][(s0 >>> 8) & 0xff] ^ SUB_MIX[3][s1 & 0xff] ^ keySchedule[ksRow++]; + t3 = SUB_MIX[0][s3 >>> 24] ^ SUB_MIX[1][(s0 >>> 16) & 0xff] ^ SUB_MIX[2][(s1 >>> 8) & 0xff] ^ SUB_MIX[3][s2 & 0xff] ^ keySchedule[ksRow++]; + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; + t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; + t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; + t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; + return [ + fixup_uint32(t0), + fixup_uint32(t1), + fixup_uint32(t2), + fixup_uint32(t3) + ]; - function bnpFromBuffer(a) { - this.fromString(a, 256, true) - } + }; - // (protected) clamp off excess high words - function bnpClamp() { - var c = this.s & this.DM; - while (this.t > 0 && this[this.t - 1] == c) --this.t; - } - // (public) return string representation in given radix - function bnToString(b) { - if (this.s < 0) return "-" + this.negate().toString(b); - var k; - if (b == 16) k = 4; - else if (b == 8) k = 3; - else if (b == 2) k = 1; - else if (b == 32) k = 5; - else if (b == 4) k = 2; - else return this.toRadix(b); - var km = (1 << k) - 1, d, m = false, r = "", i = this.t; - var p = this.DB - (i * this.DB) % k; - if (i-- > 0) { - if (p < this.DB && (d = this[i] >> p) > 0) { - m = true; - r = int2char(d); - } - while (i >= 0) { - if (p < k) { - d = (this[i] & ((1 << p) - 1)) << (k - p); - d |= this[--i] >> (p += this.DB - k); - } - else { - d = (this[i] >> (p -= k)) & km; - if (p <= 0) { - p += this.DB; - --i; - } - } - if (d > 0) m = true; - if (m) r += int2char(d); - } - } - return m ? r : "0"; - } - // (public) -this - function bnNegate() { - var r = nbi(); - BigInteger.ZERO.subTo(this, r); - return r; - } - // (public) |this| - function bnAbs() { - return (this.s < 0) ? this.negate() : this; - } + exports.AES = AES; + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) - // (public) return + if this > a, - if this < a, 0 if equal - function bnCompareTo(a) { - var r = this.s - a.s; - if (r != 0) return r; - var i = this.t; - r = i - a.t; - if (r != 0) return (this.s < 0) ? -r : r; - while (--i >= 0) if ((r = this[i] - a[i]) != 0) return r; - return 0; - } +/***/ }, +/* 51 */ +/***/ function(module, exports, __webpack_require__) { - // returns bit length of the integer x - function nbits(x) { - var r = 1, t; - if ((t = x >>> 16) != 0) { - x = t; - r += 16; - } - if ((t = x >> 8) != 0) { - x = t; - r += 8; - } - if ((t = x >> 4) != 0) { - x = t; - r += 4; - } - if ((t = x >> 2) != 0) { - x = t; - r += 2; - } - if ((t = x >> 1) != 0) { - x = t; - r += 1; - } - return r; - } + /* WEBPACK VAR INJECTION */(function(Buffer) {var Transform = __webpack_require__(52).Transform; + var inherits = __webpack_require__(53); - // (public) return the number of bits in "this" - function bnBitLength() { - if (this.t <= 0) return 0; - return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM)); + module.exports = CipherBase; + inherits(CipherBase, Transform); + function CipherBase() { + Transform.call(this); } + CipherBase.prototype.update = function (data, inputEnd, outputEnc) { + this.write(data, inputEnd); + var outData = new Buffer(''); + var chunk; + while ((chunk = this.read())) { + outData = Buffer.concat([outData, chunk]); + } + if (outputEnc) { + outData = outData.toString(outputEnc); + } + return outData; + }; + CipherBase.prototype.final = function (outputEnc) { + this.end(); + var outData = new Buffer(''); + var chunk; + while ((chunk = this.read())) { + outData = Buffer.concat([outData, chunk]); + } + if (outputEnc) { + outData = outData.toString(outputEnc); + } + return outData; + }; + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) - // (protected) r = this << n*DB - function bnpDLShiftTo(n, r) { - var i; - for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i]; - for (i = n - 1; i >= 0; --i) r[i] = 0; - r.t = this.t + n; - r.s = this.s; - } +/***/ }, +/* 52 */ +/***/ function(module, exports, __webpack_require__) { - // (protected) r = this >> n*DB - function bnpDRShiftTo(n, r) { - for (var i = n; i < this.t; ++i) r[i - n] = this[i]; - r.t = Math.max(this.t - n, 0); - r.s = this.s; - } + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. - // (protected) r = this << n - function bnpLShiftTo(n, r) { - var bs = n % this.DB; - var cbs = this.DB - bs; - var bm = (1 << cbs) - 1; - var ds = Math.floor(n / this.DB), c = (this.s << bs) & this.DM, i; - for (i = this.t - 1; i >= 0; --i) { - r[i + ds + 1] = (this[i] >> cbs) | c; - c = (this[i] & bm) << bs; - } - for (i = ds - 1; i >= 0; --i) r[i] = 0; - r[ds] = c; - r.t = this.t + ds + 1; - r.s = this.s; - r.clamp(); - } + module.exports = Stream; - // (protected) r = this >> n - function bnpRShiftTo(n, r) { - r.s = this.s; - var ds = Math.floor(n / this.DB); - if (ds >= this.t) { - r.t = 0; - return; - } - var bs = n % this.DB; - var cbs = this.DB - bs; - var bm = (1 << bs) - 1; - r[0] = this[ds] >> bs; - for (var i = ds + 1; i < this.t; ++i) { - r[i - ds - 1] |= (this[i] & bm) << cbs; - r[i - ds] = this[i] >> bs; - } - if (bs > 0) r[this.t - ds - 1] |= (this.s & bm) << cbs; - r.t = this.t - ds; - r.clamp(); + var EE = __webpack_require__(5).EventEmitter; + var inherits = __webpack_require__(53); + + inherits(Stream, EE); + Stream.Readable = __webpack_require__(54); + Stream.Writable = __webpack_require__(67); + Stream.Duplex = __webpack_require__(68); + Stream.Transform = __webpack_require__(69); + Stream.PassThrough = __webpack_require__(70); + + // Backwards-compat with node 0.4.x + Stream.Stream = Stream; + + + + // old-style streams. Note that the pipe method (the only relevant + // part of this class) is overridden in the Readable class. + + function Stream() { + EE.call(this); } - // (protected) r = this - a - function bnpSubTo(a, r) { - var i = 0, c = 0, m = Math.min(a.t, this.t); - while (i < m) { - c += this[i] - a[i]; - r[i++] = c & this.DM; - c >>= this.DB; + Stream.prototype.pipe = function(dest, options) { + var source = this; + + function ondata(chunk) { + if (dest.writable) { + if (false === dest.write(chunk) && source.pause) { + source.pause(); + } } - if (a.t < this.t) { - c -= a.s; - while (i < this.t) { - c += this[i]; - r[i++] = c & this.DM; - c >>= this.DB; - } - c += this.s; + } + + source.on('data', ondata); + + function ondrain() { + if (source.readable && source.resume) { + source.resume(); } - else { - c += this.s; - while (i < a.t) { - c -= a[i]; - r[i++] = c & this.DM; - c >>= this.DB; - } - c -= a.s; - } - r.s = (c < 0) ? -1 : 0; - if (c < -1) r[i++] = this.DV + c; - else if (c > 0) r[i++] = c; - r.t = i; - r.clamp(); - } - - // (protected) r = this * a, r != this,a (HAC 14.12) - // "this" should be the larger one if appropriate. - function bnpMultiplyTo(a, r) { - var x = this.abs(), y = a.abs(); - var i = x.t; - r.t = i + y.t; - while (--i >= 0) r[i] = 0; - for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t); - r.s = 0; - r.clamp(); - if (this.s != a.s) BigInteger.ZERO.subTo(r, r); - } + } - // (protected) r = this^2, r != this (HAC 14.16) - function bnpSquareTo(r) { - var x = this.abs(); - var i = r.t = 2 * x.t; - while (--i >= 0) r[i] = 0; - for (i = 0; i < x.t - 1; ++i) { - var c = x.am(i, x[i], r, 2 * i, 0, 1); - if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) { - r[i + x.t] -= x.DV; - r[i + x.t + 1] = 1; - } - } - if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1); - r.s = 0; - r.clamp(); - } + dest.on('drain', ondrain); - // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) - // r != q, this != m. q or r may be null. - function bnpDivRemTo(m, q, r) { - var pm = m.abs(); - if (pm.t <= 0) return; - var pt = this.abs(); - if (pt.t < pm.t) { - if (q != null) q.fromInt(0); - if (r != null) this.copyTo(r); - return; - } - if (r == null) r = nbi(); - var y = nbi(), ts = this.s, ms = m.s; - var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus - if (nsh > 0) { - pm.lShiftTo(nsh, y); - pt.lShiftTo(nsh, r); - } - else { - pm.copyTo(y); - pt.copyTo(r); - } - var ys = y.t; - var y0 = y[ys - 1]; - if (y0 === 0) return; - var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0); - var d1 = this.FV / yt, d2 = (1 << this.F1) / yt, e = 1 << this.F2; - var i = r.t, j = i - ys, t = (q == null) ? nbi() : q; - y.dlShiftTo(j, t); - if (r.compareTo(t) >= 0) { - r[r.t++] = 1; - r.subTo(t, r); - } - BigInteger.ONE.dlShiftTo(ys, t); - t.subTo(y, y); // "negative" y so we can replace sub with am later - while (y.t < ys) y[y.t++] = 0; - while (--j >= 0) { - // Estimate quotient digit - var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2); - if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out - y.dlShiftTo(j, t); - r.subTo(t, r); - while (r[i] < --qd) r.subTo(t, r); - } - } - if (q != null) { - r.drShiftTo(ys, q); - if (ts != ms) BigInteger.ZERO.subTo(q, q); - } - r.t = ys; - r.clamp(); - if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder - if (ts < 0) BigInteger.ZERO.subTo(r, r); - } + // If the 'end' option is not supplied, dest.end() will be called when + // source gets the 'end' or 'close' events. Only dest.end() once. + if (!dest._isStdio && (!options || options.end !== false)) { + source.on('end', onend); + source.on('close', onclose); + } - // (public) this mod a - function bnMod(a) { - var r = nbi(); - this.abs().divRemTo(a, null, r); - if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r); - return r; - } + var didOnEnd = false; + function onend() { + if (didOnEnd) return; + didOnEnd = true; - // Modular reduction using "classic" algorithm - function Classic(m) { - this.m = m; - } - function cConvert(x) { - if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); - else return x; - } - function cRevert(x) { - return x; - } - function cReduce(x) { - x.divRemTo(this.m, null, x); - } - function cMulTo(x, y, r) { - x.multiplyTo(y, r); - this.reduce(r); - } - function cSqrTo(x, r) { - x.squareTo(r); - this.reduce(r); - } + dest.end(); + } - Classic.prototype.convert = cConvert; - Classic.prototype.revert = cRevert; - Classic.prototype.reduce = cReduce; - Classic.prototype.mulTo = cMulTo; - Classic.prototype.sqrTo = cSqrTo; - // (protected) return "-1/this % 2^DB"; useful for Mont. reduction - // justification: - // xy == 1 (mod m) - // xy = 1+km - // xy(2-xy) = (1+km)(1-km) - // x[y(2-xy)] = 1-k^2m^2 - // x[y(2-xy)] == 1 (mod m^2) - // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2 - // should reduce x and y(2-xy) by m^2 at each step to keep size bounded. - // JS multiply "overflows" differently from C/C++, so care is needed here. - function bnpInvDigit() { - if (this.t < 1) return 0; - var x = this[0]; - if ((x & 1) === 0) return 0; - var y = x & 3; // y == 1/x mod 2^2 - y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4 - y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8 - y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16 - // last step - calculate inverse mod DV directly; - // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints - y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits - // we really want the negative inverse, and -DV < y < DV - return (y > 0) ? this.DV - y : -y; - } + function onclose() { + if (didOnEnd) return; + didOnEnd = true; - // Montgomery reduction - function Montgomery(m) { - this.m = m; - this.mp = m.invDigit(); - this.mpl = this.mp & 0x7fff; - this.mph = this.mp >> 15; - this.um = (1 << (m.DB - 15)) - 1; - this.mt2 = 2 * m.t; - } + if (typeof dest.destroy === 'function') dest.destroy(); + } - // xR mod m - function montConvert(x) { - var r = nbi(); - x.abs().dlShiftTo(this.m.t, r); - r.divRemTo(this.m, null, r); - if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r); - return r; - } + // don't leave dangling pipes when there are errors. + function onerror(er) { + cleanup(); + if (EE.listenerCount(this, 'error') === 0) { + throw er; // Unhandled stream error in pipe. + } + } - // x/R mod m - function montRevert(x) { - var r = nbi(); - x.copyTo(r); - this.reduce(r); - return r; - } + source.on('error', onerror); + dest.on('error', onerror); - // x = x/R mod m (HAC 14.32) - function montReduce(x) { - while (x.t <= this.mt2) // pad x so am has enough room later - x[x.t++] = 0; - for (var i = 0; i < this.m.t; ++i) { - // faster way of calculating u0 = x[i]*mp mod DV - var j = x[i] & 0x7fff; - var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM; - // use am to combine the multiply-shift-add into one call - j = i + this.m.t; - x[j] += this.m.am(0, u0, x, i, 0, this.m.t); - // propagate carry - while (x[j] >= x.DV) { - x[j] -= x.DV; - x[++j]++; - } - } - x.clamp(); - x.drShiftTo(this.m.t, x); - if (x.compareTo(this.m) >= 0) x.subTo(this.m, x); - } + // remove all the event listeners that were added. + function cleanup() { + source.removeListener('data', ondata); + dest.removeListener('drain', ondrain); - // r = "x^2/R mod m"; x != r - function montSqrTo(x, r) { - x.squareTo(r); - this.reduce(r); - } + source.removeListener('end', onend); + source.removeListener('close', onclose); - // r = "xy/R mod m"; x,y != r - function montMulTo(x, y, r) { - x.multiplyTo(y, r); - this.reduce(r); - } + source.removeListener('error', onerror); + dest.removeListener('error', onerror); - Montgomery.prototype.convert = montConvert; - Montgomery.prototype.revert = montRevert; - Montgomery.prototype.reduce = montReduce; - Montgomery.prototype.mulTo = montMulTo; - Montgomery.prototype.sqrTo = montSqrTo; + source.removeListener('end', cleanup); + source.removeListener('close', cleanup); - // (protected) true iff this is even - function bnpIsEven() { - return ((this.t > 0) ? (this[0] & 1) : this.s) === 0; - } + dest.removeListener('close', cleanup); + } - // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) - function bnpExp(e, z) { - if (e > 0xffffffff || e < 1) return BigInteger.ONE; - var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e) - 1; - g.copyTo(r); - while (--i >= 0) { - z.sqrTo(r, r2); - if ((e & (1 << i)) > 0) z.mulTo(r2, g, r); - else { - var t = r; - r = r2; - r2 = t; - } - } - return z.revert(r); - } + source.on('end', cleanup); + source.on('close', cleanup); - // (public) this^e % m, 0 <= e < 2^32 - function bnModPowInt(e, m) { - var z; - if (e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); - return this.exp(e, z); - } + dest.on('close', cleanup); - // Copyright (c) 2005-2009 Tom Wu - // All Rights Reserved. - // See "LICENSE" for details. + dest.emit('pipe', source); - // Extended JavaScript BN functions, required for RSA private ops. + // Allow for unix-like usage: A.pipe(B).pipe(C) + return dest; + }; - // Version 1.1: new BigInteger("0", 10) returns "proper" zero - // Version 1.2: square() API, isProbablePrime fix - //(public) - function bnClone() { - var r = nbi(); - this.copyTo(r); - return r; - } +/***/ }, +/* 53 */ +/***/ function(module, exports) { - //(public) return value as integer - function bnIntValue() { - if (this.s < 0) { - if (this.t == 1) return this[0] - this.DV; - else if (this.t === 0) return -1; - } - else if (this.t == 1) return this[0]; - else if (this.t === 0) return 0; - // assumes 16 < DB < 32 - return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0]; + if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; + } else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } } - //(public) return value as byte - function bnByteValue() { - return (this.t == 0) ? this.s : (this[0] << 24) >> 24; - } - //(public) return value as short (assumes DB>=16) - function bnShortValue() { - return (this.t == 0) ? this.s : (this[0] << 16) >> 16; - } +/***/ }, +/* 54 */ +/***/ function(module, exports, __webpack_require__) { - //(protected) return x s.t. r^x < DV - function bnpChunkSize(r) { - return Math.floor(Math.LN2 * this.DB / Math.log(r)); - } + var Stream = (function (){ + try { + return __webpack_require__(52); // hack to fix a circular dependency issue when used with browserify + } catch(_){} + }()); + exports = module.exports = __webpack_require__(55); + exports.Stream = Stream || exports; + exports.Readable = exports; + exports.Writable = __webpack_require__(60); + exports.Duplex = __webpack_require__(59); + exports.Transform = __webpack_require__(65); + exports.PassThrough = __webpack_require__(66); - //(public) 0 if this === 0, 1 if this > 0 - function bnSigNum() { - if (this.s < 0) return -1; - else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0; - else return 1; - } - //(protected) convert to radix string - function bnpToRadix(b) { - if (b == null) b = 10; - if (this.signum() === 0 || b < 2 || b > 36) return "0"; - var cs = this.chunkSize(b); - var a = Math.pow(b, cs); - var d = nbv(a), y = nbi(), z = nbi(), r = ""; - this.divRemTo(d, y, z); - while (y.signum() > 0) { - r = (a + z.intValue()).toString(b).substr(1) + r; - y.divRemTo(d, y, z); - } - return z.intValue().toString(b) + r; - } +/***/ }, +/* 55 */ +/***/ function(module, exports, __webpack_require__) { - //(protected) convert from radix string - function bnpFromRadix(s, b) { - this.fromInt(0); - if (b == null) b = 10; - var cs = this.chunkSize(b); - var d = Math.pow(b, cs), mi = false, j = 0, w = 0; - for (var i = 0; i < s.length; ++i) { - var x = intAt(s, i); - if (x < 0) { - if (s.charAt(i) == "-" && this.signum() === 0) mi = true; - continue; - } - w = b * w + x; - if (++j >= cs) { - this.dMultiply(d); - this.dAddOffset(w, 0); - j = 0; - w = 0; - } - } - if (j > 0) { - this.dMultiply(Math.pow(b, j)); - this.dAddOffset(w, 0); - } - if (mi) BigInteger.ZERO.subTo(this, this); - } + /* WEBPACK VAR INJECTION */(function(process) {'use strict'; - //(protected) alternate constructor - function bnpFromNumber(a, b) { - if ("number" == typeof b) { - // new BigInteger(int,int,RNG) - if (a < 2) this.fromInt(1); - else { - this.fromNumber(a); - if (!this.testBit(a - 1)) // force MSB set - this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this); - if (this.isEven()) this.dAddOffset(1, 0); // force odd - while (!this.isProbablePrime(b)) { - this.dAddOffset(2, 0); - if (this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a - 1), this); - } - } - } else { - // new BigInteger(int,RNG) - var x = crypt.randomBytes((a >> 3) + 1) - var t = a & 7; + module.exports = Readable; - if (t > 0) - x[0] &= ((1 << t) - 1); - else - x[0] = 0; + /**/ + var processNextTick = __webpack_require__(56); + /**/ - this.fromByteArray(x); - } - } + /**/ + var isArray = __webpack_require__(4); + /**/ - //(public) convert to bigendian byte array - function bnToByteArray() { - var i = this.t, r = new Array(); - r[0] = this.s; - var p = this.DB - (i * this.DB) % 8, d, k = 0; - if (i-- > 0) { - if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) - r[k++] = d | (this.s << (this.DB - p)); - while (i >= 0) { - if (p < 8) { - d = (this[i] & ((1 << p) - 1)) << (8 - p); - d |= this[--i] >> (p += this.DB - 8); - } - else { - d = (this[i] >> (p -= 8)) & 0xff; - if (p <= 0) { - p += this.DB; - --i; - } - } - if ((d & 0x80) != 0) d |= -256; - if (k === 0 && (this.s & 0x80) != (d & 0x80)) ++k; - if (k > 0 || d != this.s) r[k++] = d; - } - } - return r; - } + /**/ + var Buffer = __webpack_require__(1).Buffer; + /**/ - /** - * return Buffer object - * @param trim {boolean} slice buffer if first element == 0 - * @returns {Buffer} - */ - function bnToBuffer(trimOrSize) { - var res = new Buffer(this.toByteArray()); - if (trimOrSize === true && res[0] === 0) { - res = res.slice(1); - } else if (_.isNumber(trimOrSize)) { - if (res.length > trimOrSize) { - for (var i = 0; i < res.length - trimOrSize; i++) { - if (res[i] !== 0) { - return null; - } - } - return res.slice(res.length - trimOrSize); - } else if (res.length < trimOrSize) { - var padded = new Buffer(trimOrSize); - padded.fill(0, 0, trimOrSize - res.length); - res.copy(padded, trimOrSize - res.length); - return padded; - } - } - return res; - } + Readable.ReadableState = ReadableState; - function bnEquals(a) { - return (this.compareTo(a) == 0); - } - function bnMin(a) { - return (this.compareTo(a) < 0) ? this : a; - } - function bnMax(a) { - return (this.compareTo(a) > 0) ? this : a; - } + var EE = __webpack_require__(5); - //(protected) r = this op a (bitwise) - function bnpBitwiseTo(a, op, r) { - var i, f, m = Math.min(a.t, this.t); - for (i = 0; i < m; ++i) r[i] = op(this[i], a[i]); - if (a.t < this.t) { - f = a.s & this.DM; - for (i = m; i < this.t; ++i) r[i] = op(this[i], f); - r.t = this.t; - } - else { - f = this.s & this.DM; - for (i = m; i < a.t; ++i) r[i] = op(f, a[i]); - r.t = a.t; - } - r.s = op(this.s, a.s); - r.clamp(); - } + /**/ + var EElistenerCount = function (emitter, type) { + return emitter.listeners(type).length; + }; + /**/ - //(public) this & a - function op_and(x, y) { - return x & y; - } - function bnAnd(a) { - var r = nbi(); - this.bitwiseTo(a, op_and, r); - return r; - } + /**/ + var Stream; + (function () { + try { + Stream = __webpack_require__(52); + } catch (_) {} finally { + if (!Stream) Stream = __webpack_require__(5).EventEmitter; + } + })(); + /**/ - //(public) this | a - function op_or(x, y) { - return x | y; - } - function bnOr(a) { - var r = nbi(); - this.bitwiseTo(a, op_or, r); - return r; - } + var Buffer = __webpack_require__(1).Buffer; - //(public) this ^ a - function op_xor(x, y) { - return x ^ y; - } - function bnXor(a) { - var r = nbi(); - this.bitwiseTo(a, op_xor, r); - return r; - } + /**/ + var util = __webpack_require__(57); + util.inherits = __webpack_require__(53); + /**/ - //(public) this & ~a - function op_andnot(x, y) { - return x & ~y; - } - function bnAndNot(a) { - var r = nbi(); - this.bitwiseTo(a, op_andnot, r); - return r; + /**/ + var debugUtil = __webpack_require__(58); + var debug = undefined; + if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog('stream'); + } else { + debug = function () {}; } + /**/ - //(public) ~this - function bnNot() { - var r = nbi(); - for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i]; - r.t = this.t; - r.s = ~this.s; - return r; - } + var StringDecoder; - //(public) this << n - function bnShiftLeft(n) { - var r = nbi(); - if (n < 0) this.rShiftTo(-n, r); else this.lShiftTo(n, r); - return r; - } + util.inherits(Readable, Stream); - //(public) this >> n - function bnShiftRight(n) { - var r = nbi(); - if (n < 0) this.lShiftTo(-n, r); else this.rShiftTo(n, r); - return r; - } + var Duplex; + function ReadableState(options, stream) { + Duplex = Duplex || __webpack_require__(59); - //return index of lowest 1-bit in x, x < 2^31 - function lbit(x) { - if (x === 0) return -1; - var r = 0; - if ((x & 0xffff) === 0) { - x >>= 16; - r += 16; - } - if ((x & 0xff) === 0) { - x >>= 8; - r += 8; - } - if ((x & 0xf) === 0) { - x >>= 4; - r += 4; - } - if ((x & 3) === 0) { - x >>= 2; - r += 2; - } - if ((x & 1) === 0) ++r; - return r; - } + options = options || {}; - //(public) returns index of lowest 1-bit (or -1 if none) - function bnGetLowestSetBit() { - for (var i = 0; i < this.t; ++i) - if (this[i] != 0) return i * this.DB + lbit(this[i]); - if (this.s < 0) return this.t * this.DB; - return -1; - } + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; - //return number of 1 bits in x - function cbit(x) { - var r = 0; - while (x != 0) { - x &= x - 1; - ++r; - } - return r; - } + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode; - //(public) return number of set bits - function bnBitCount() { - var r = 0, x = this.s & this.DM; - for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x); - return r; - } + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; - //(public) true iff nth bit is set - function bnTestBit(n) { - var j = Math.floor(n / this.DB); - if (j >= this.t) return (this.s != 0); - return ((this[j] & (1 << (n % this.DB))) != 0); - } + // cast to ints. + this.highWaterMark = ~ ~this.highWaterMark; - //(protected) this op (1<>= this.DB; - } - if (a.t < this.t) { - c += a.s; - while (i < this.t) { - c += this[i]; - r[i++] = c & this.DM; - c >>= this.DB; - } - c += this.s; - } - else { - c += this.s; - while (i < a.t) { - c += a[i]; - r[i++] = c & this.DM; - c >>= this.DB; - } - c += a.s; - } - r.s = (c < 0) ? -1 : 0; - if (c > 0) r[i++] = c; - else if (c < -1) r[i++] = this.DV + c; - r.t = i; - r.clamp(); - } + // when piping, we only care about 'readable' events that happen + // after read()ing all the bytes and not getting any pushback. + this.ranOut = false; - //(public) this + a - function bnAdd(a) { - var r = nbi(); - this.addTo(a, r); - return r; - } + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; - //(public) this - a - function bnSubtract(a) { - var r = nbi(); - this.subTo(a, r); - return r; - } + // if true, a maybeReadMore has been scheduled + this.readingMore = false; - //(public) this * a - function bnMultiply(a) { - var r = nbi(); - this.multiplyTo(a, r); - return r; + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) StringDecoder = __webpack_require__(64).StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } } - // (public) this^2 - function bnSquare() { - var r = nbi(); - this.squareTo(r); - return r; - } + var Duplex; + function Readable(options) { + Duplex = Duplex || __webpack_require__(59); - //(public) this / a - function bnDivide(a) { - var r = nbi(); - this.divRemTo(a, r, null); - return r; - } + if (!(this instanceof Readable)) return new Readable(options); - //(public) this % a - function bnRemainder(a) { - var r = nbi(); - this.divRemTo(a, null, r); - return r; - } + this._readableState = new ReadableState(options, this); - //(public) [this/a,this%a] - function bnDivideAndRemainder(a) { - var q = nbi(), r = nbi(); - this.divRemTo(a, q, r); - return new Array(q, r); - } + // legacy + this.readable = true; - //(protected) this *= n, this >= 0, 1 < n < DV - function bnpDMultiply(n) { - this[this.t] = this.am(0, n - 1, this, 0, 0, this.t); - ++this.t; - this.clamp(); + if (options && typeof options.read === 'function') this._read = options.read; + + Stream.call(this); } - //(protected) this += n << w words, this >= 0 - function bnpDAddOffset(n, w) { - if (n === 0) return; - while (this.t <= w) this[this.t++] = 0; - this[w] += n; - while (this[w] >= this.DV) { - this[w] -= this.DV; - if (++w >= this.t) this[this.t++] = 0; - ++this[w]; + // Manually shove something into the read() buffer. + // This returns true if the highWaterMark has not been hit yet, + // similar to how Writable.write() returns true if you should + // write() some more. + Readable.prototype.push = function (chunk, encoding) { + var state = this._readableState; + + if (!state.objectMode && typeof chunk === 'string') { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = new Buffer(chunk, encoding); + encoding = ''; } - } + } - //A "null" reducer - function NullExp() { - } - function nNop(x) { - return x; - } - function nMulTo(x, y, r) { - x.multiplyTo(y, r); - } - function nSqrTo(x, r) { - x.squareTo(r); - } + return readableAddChunk(this, state, chunk, encoding, false); + }; - NullExp.prototype.convert = nNop; - NullExp.prototype.revert = nNop; - NullExp.prototype.mulTo = nMulTo; - NullExp.prototype.sqrTo = nSqrTo; + // Unshift should *always* be something directly out of read() + Readable.prototype.unshift = function (chunk) { + var state = this._readableState; + return readableAddChunk(this, state, chunk, '', true); + }; - //(public) this^e - function bnPow(e) { - return this.exp(e, new NullExp()); - } + Readable.prototype.isPaused = function () { + return this._readableState.flowing === false; + }; - //(protected) r = lower n words of "this * a", a.t <= n - //"this" should be the larger one if appropriate. - function bnpMultiplyLowerTo(a, n, r) { - var i = Math.min(this.t + a.t, n); - r.s = 0; // assumes a,this >= 0 - r.t = i; - while (i > 0) r[--i] = 0; - var j; - for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t); - for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i); - r.clamp(); - } + function readableAddChunk(stream, state, chunk, encoding, addToFront) { + var er = chunkInvalid(state, chunk); + if (er) { + stream.emit('error', er); + } else if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (state.ended && !addToFront) { + var e = new Error('stream.push() after EOF'); + stream.emit('error', e); + } else if (state.endEmitted && addToFront) { + var e = new Error('stream.unshift() after end event'); + stream.emit('error', e); + } else { + var skipAdd; + if (state.decoder && !addToFront && !encoding) { + chunk = state.decoder.write(chunk); + skipAdd = !state.objectMode && chunk.length === 0; + } - //(protected) r = "this * a" without lower n words, n > 0 - //"this" should be the larger one if appropriate. - function bnpMultiplyUpperTo(a, n, r) { - --n; - var i = r.t = this.t + a.t - n; - r.s = 0; // assumes a,this >= 0 - while (--i >= 0) r[i] = 0; - for (i = Math.max(n - this.t, 0); i < a.t; ++i) - r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n); - r.clamp(); - r.drShiftTo(1, r); - } + if (!addToFront) state.reading = false; - //Barrett modular reduction - function Barrett(m) { - // setup Barrett - this.r2 = nbi(); - this.q3 = nbi(); - BigInteger.ONE.dlShiftTo(2 * m.t, this.r2); - this.mu = this.r2.divide(m); - this.m = m; - } + // Don't add to the buffer if we've decoded to an empty string chunk and + // we're not in object mode + if (!skipAdd) { + // if we want the data now, just emit it. + if (state.flowing && state.length === 0 && !state.sync) { + stream.emit('data', chunk); + stream.read(0); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); - function barrettConvert(x) { - if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m); - else if (x.compareTo(this.m) < 0) return x; - else { - var r = nbi(); - x.copyTo(r); - this.reduce(r); - return r; + if (state.needReadable) emitReadable(stream); + } + } + + maybeReadMore(stream, state); } - } + } else if (!addToFront) { + state.reading = false; + } - function barrettRevert(x) { - return x; + return needMoreData(state); } - //x = x mod m (HAC 14.42) - function barrettReduce(x) { - x.drShiftTo(this.m.t - 1, this.r2); - if (x.t > this.m.t + 1) { - x.t = this.m.t + 1; - x.clamp(); - } - this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3); - this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); - while (x.compareTo(this.r2) < 0) x.dAddOffset(1, this.m.t + 1); - x.subTo(this.r2, x); - while (x.compareTo(this.m) >= 0) x.subTo(this.m, x); + // if it's past the high water mark, we can push in some more. + // Also, if we have no data yet, we can stand some + // more bytes. This is to work around cases where hwm=0, + // such as the repl. Also, if the push() triggered a + // readable event, and the user called read(largeNumber) such that + // needReadable was set, then we ought to push more, so that another + // 'readable' event will be triggered. + function needMoreData(state) { + return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); } - //r = x^2 mod m; x != r - function barrettSqrTo(x, r) { - x.squareTo(r); - this.reduce(r); - } + // backwards compatibility. + Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = __webpack_require__(64).StringDecoder; + this._readableState.decoder = new StringDecoder(enc); + this._readableState.encoding = enc; + return this; + }; - //r = x*y mod m; x,y != r - function barrettMulTo(x, y, r) { - x.multiplyTo(y, r); - this.reduce(r); + // Don't raise the hwm > 8MB + var MAX_HWM = 0x800000; + function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + n = MAX_HWM; + } else { + // Get the next highest power of 2 + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + return n; } - Barrett.prototype.convert = barrettConvert; - Barrett.prototype.revert = barrettRevert; - Barrett.prototype.reduce = barrettReduce; - Barrett.prototype.mulTo = barrettMulTo; - Barrett.prototype.sqrTo = barrettSqrTo; + function howMuchToRead(n, state) { + if (state.length === 0 && state.ended) return 0; - //(public) this^e % m (HAC 14.85) - function bnModPow(e, m) { - var i = e.bitLength(), k, r = nbv(1), z; - if (i <= 0) return r; - else if (i < 18) k = 1; - else if (i < 48) k = 3; - else if (i < 144) k = 4; - else if (i < 768) k = 5; - else k = 6; - if (i < 8) - z = new Classic(m); - else if (m.isEven()) - z = new Barrett(m); - else - z = new Montgomery(m); + if (state.objectMode) return n === 0 ? 0 : 1; - // precomputation - var g = new Array(), n = 3, k1 = k - 1, km = (1 << k) - 1; - g[1] = z.convert(this); - if (k > 1) { - var g2 = nbi(); - z.sqrTo(g[1], g2); - while (n <= km) { - g[n] = nbi(); - z.mulTo(g2, g[n - 2], g[n]); - n += 2; - } - } + if (n === null || isNaN(n)) { + // only flow one buffer at a time + if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length; + } - var j = e.t - 1, w, is1 = true, r2 = nbi(), t; - i = nbits(e[j]) - 1; - while (j >= 0) { - if (i >= k1) w = (e[j] >> (i - k1)) & km; - else { - w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i); - if (j > 0) w |= e[j - 1] >> (this.DB + i - k1); - } + if (n <= 0) return 0; - n = k; - while ((w & 1) === 0) { - w >>= 1; - --n; - } - if ((i -= n) < 0) { - i += this.DB; - --j; - } - if (is1) { // ret == 1, don't bother squaring or multiplying it - g[w].copyTo(r); - is1 = false; - } - else { - while (n > 1) { - z.sqrTo(r, r2); - z.sqrTo(r2, r); - n -= 2; - } - if (n > 0) z.sqrTo(r, r2); else { - t = r; - r = r2; - r2 = t; - } - z.mulTo(r2, g[w], r); - } + // If we're asking for more than the target buffer level, + // then raise the water mark. Bump up to the next highest + // power of 2, to prevent increasing it excessively in tiny + // amounts. + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); - while (j >= 0 && (e[j] & (1 << i)) === 0) { - z.sqrTo(r, r2); - t = r; - r = r2; - r2 = t; - if (--i < 0) { - i = this.DB - 1; - --j; - } - } + // don't have that much. return null, unless we've ended. + if (n > state.length) { + if (!state.ended) { + state.needReadable = true; + return 0; + } else { + return state.length; } - return z.revert(r); - } + } - //(public) gcd(this,a) (HAC 14.54) - function bnGCD(a) { - var x = (this.s < 0) ? this.negate() : this.clone(); - var y = (a.s < 0) ? a.negate() : a.clone(); - if (x.compareTo(y) < 0) { - var t = x; - x = y; - y = t; - } - var i = x.getLowestSetBit(), g = y.getLowestSetBit(); - if (g < 0) return x; - if (i < g) g = i; - if (g > 0) { - x.rShiftTo(g, x); - y.rShiftTo(g, y); - } - while (x.signum() > 0) { - if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x); - if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y); - if (x.compareTo(y) >= 0) { - x.subTo(y, x); - x.rShiftTo(1, x); - } - else { - y.subTo(x, y); - y.rShiftTo(1, y); - } - } - if (g > 0) y.lShiftTo(g, y); - return y; + return n; } - //(protected) this % n, n < 2^26 - function bnpModInt(n) { - if (n <= 0) return 0; - var d = this.DV % n, r = (this.s < 0) ? n - 1 : 0; - if (this.t > 0) - if (d === 0) r = this[0] % n; - else for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n; - return r; - } + // you can override either this method, or the async _read(n) below. + Readable.prototype.read = function (n) { + debug('read', n); + var state = this._readableState; + var nOrig = n; - //(public) 1/this % m (HAC 14.61) - function bnModInverse(m) { - var ac = m.isEven(); - if ((this.isEven() && ac) || m.signum() === 0) return BigInteger.ZERO; - var u = m.clone(), v = this.clone(); - var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); - while (u.signum() != 0) { - while (u.isEven()) { - u.rShiftTo(1, u); - if (ac) { - if (!a.isEven() || !b.isEven()) { - a.addTo(this, a); - b.subTo(m, b); - } - a.rShiftTo(1, a); - } - else if (!b.isEven()) b.subTo(m, b); - b.rShiftTo(1, b); - } - while (v.isEven()) { - v.rShiftTo(1, v); - if (ac) { - if (!c.isEven() || !d.isEven()) { - c.addTo(this, c); - d.subTo(m, d); - } - c.rShiftTo(1, c); - } - else if (!d.isEven()) d.subTo(m, d); - d.rShiftTo(1, d); - } - if (u.compareTo(v) >= 0) { - u.subTo(v, u); - if (ac) a.subTo(c, a); - b.subTo(d, b); - } - else { - v.subTo(u, v); - if (ac) c.subTo(a, c); - d.subTo(b, d); - } - } - if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; - if (d.compareTo(m) >= 0) return d.subtract(m); - if (d.signum() < 0) d.addTo(m, d); else return d; - if (d.signum() < 0) return d.add(m); else return d; - } + if (typeof n !== 'number' || n > 0) state.emittedReadable = false; - 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]; - var lplim = (1 << 26) / lowprimes[lowprimes.length - 1]; + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { + debug('read: emitReadable', state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); + return null; + } - //(public) test primality with certainty >= 1-.5^t - function bnIsProbablePrime(t) { - var i, x = this.abs(); - if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) { - for (i = 0; i < lowprimes.length; ++i) - if (x[0] == lowprimes[i]) return true; - return false; - } - if (x.isEven()) return false; - i = 1; - while (i < lowprimes.length) { - var m = lowprimes[i], j = i + 1; - while (j < lowprimes.length && m < lplim) m *= lowprimes[j++]; - m = x.modInt(m); - while (i < j) if (m % lowprimes[i++] === 0) return false; - } - return x.millerRabin(t); - } + n = howMuchToRead(n, state); - //(protected) true if probably prime (HAC 4.24, Miller-Rabin) - function bnpMillerRabin(t) { - var n1 = this.subtract(BigInteger.ONE); - var k = n1.getLowestSetBit(); - if (k <= 0) return false; - var r = n1.shiftRight(k); - t = (t + 1) >> 1; - if (t > lowprimes.length) t = lowprimes.length; - var a = nbi(); - for (var i = 0; i < t; ++i) { - //Pick bases at random, instead of starting at 2 - a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]); - var y = a.modPow(r, this); - if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1; - while (j++ < k && y.compareTo(n1) != 0) { - y = y.modPowInt(2, this); - if (y.compareTo(BigInteger.ONE) === 0) return false; - } - if (y.compareTo(n1) != 0) return false; - } - } - return true; - } + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this); + return null; + } - // protected - BigInteger.prototype.copyTo = bnpCopyTo; - BigInteger.prototype.fromInt = bnpFromInt; - BigInteger.prototype.fromString = bnpFromString; - BigInteger.prototype.fromByteArray = bnpFromByteArray; - BigInteger.prototype.fromBuffer = bnpFromBuffer; - BigInteger.prototype.clamp = bnpClamp; - BigInteger.prototype.dlShiftTo = bnpDLShiftTo; - BigInteger.prototype.drShiftTo = bnpDRShiftTo; - BigInteger.prototype.lShiftTo = bnpLShiftTo; - BigInteger.prototype.rShiftTo = bnpRShiftTo; - BigInteger.prototype.subTo = bnpSubTo; - BigInteger.prototype.multiplyTo = bnpMultiplyTo; - BigInteger.prototype.squareTo = bnpSquareTo; - BigInteger.prototype.divRemTo = bnpDivRemTo; - BigInteger.prototype.invDigit = bnpInvDigit; - BigInteger.prototype.isEven = bnpIsEven; - BigInteger.prototype.exp = bnpExp; + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. - BigInteger.prototype.chunkSize = bnpChunkSize; - BigInteger.prototype.toRadix = bnpToRadix; - BigInteger.prototype.fromRadix = bnpFromRadix; - BigInteger.prototype.fromNumber = bnpFromNumber; - BigInteger.prototype.bitwiseTo = bnpBitwiseTo; - BigInteger.prototype.changeBit = bnpChangeBit; - BigInteger.prototype.addTo = bnpAddTo; - BigInteger.prototype.dMultiply = bnpDMultiply; - BigInteger.prototype.dAddOffset = bnpDAddOffset; - BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; - BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; - BigInteger.prototype.modInt = bnpModInt; - BigInteger.prototype.millerRabin = bnpMillerRabin; + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug('need readable', doRead); + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug('length less than watermark', doRead); + } - // public - BigInteger.prototype.toString = bnToString; - BigInteger.prototype.negate = bnNegate; - BigInteger.prototype.abs = bnAbs; - BigInteger.prototype.compareTo = bnCompareTo; - BigInteger.prototype.bitLength = bnBitLength; - BigInteger.prototype.mod = bnMod; - BigInteger.prototype.modPowInt = bnModPowInt; + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug('reading or ended', doRead); + } - BigInteger.prototype.clone = bnClone; - BigInteger.prototype.intValue = bnIntValue; - BigInteger.prototype.byteValue = bnByteValue; - BigInteger.prototype.shortValue = bnShortValue; - BigInteger.prototype.signum = bnSigNum; - BigInteger.prototype.toByteArray = bnToByteArray; - BigInteger.prototype.toBuffer = bnToBuffer; - BigInteger.prototype.equals = bnEquals; - BigInteger.prototype.min = bnMin; - BigInteger.prototype.max = bnMax; - BigInteger.prototype.and = bnAnd; - BigInteger.prototype.or = bnOr; - BigInteger.prototype.xor = bnXor; - BigInteger.prototype.andNot = bnAndNot; - BigInteger.prototype.not = bnNot; - BigInteger.prototype.shiftLeft = bnShiftLeft; - BigInteger.prototype.shiftRight = bnShiftRight; - BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit; - BigInteger.prototype.bitCount = bnBitCount; - BigInteger.prototype.testBit = bnTestBit; - BigInteger.prototype.setBit = bnSetBit; - BigInteger.prototype.clearBit = bnClearBit; - BigInteger.prototype.flipBit = bnFlipBit; - BigInteger.prototype.add = bnAdd; - BigInteger.prototype.subtract = bnSubtract; - BigInteger.prototype.multiply = bnMultiply; - BigInteger.prototype.divide = bnDivide; - BigInteger.prototype.remainder = bnRemainder; - BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder; - BigInteger.prototype.modPow = bnModPow; - BigInteger.prototype.modInverse = bnModInverse; - BigInteger.prototype.pow = bnPow; - BigInteger.prototype.gcd = bnGCD; - BigInteger.prototype.isProbablePrime = bnIsProbablePrime; - BigInteger.int2char = int2char; + if (doRead) { + debug('do read'); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + } - // "constants" - BigInteger.ZERO = nbv(0); - BigInteger.ONE = nbv(1); + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (doRead && !state.reading) n = howMuchToRead(nOrig, state); - // JSBN-specific extension - BigInteger.prototype.square = bnSquare; + var ret; + if (n > 0) ret = fromList(n, state);else ret = null; - //BigInteger interfaces not implemented in jsbn: + if (ret === null) { + state.needReadable = true; + n = 0; + } - //BigInteger(int signum, byte[] magnitude) - //double doubleValue() - //float floatValue() - //int hashCode() - //long longValue() - //static BigInteger valueOf(long val) + state.length -= n; - module.exports = BigInteger; - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (state.length === 0 && !state.ended) state.needReadable = true; -/***/ }, -/* 49 */ -/***/ function(module, exports, __webpack_require__) { + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended && state.length === 0) endReadable(this); - module.exports = { - pkcs1: __webpack_require__(50), - pkcs1_oaep: __webpack_require__(51), - pss: __webpack_require__(52), + if (ret !== null) this.emit('data', ret); - /** - * Check if scheme has padding methods - * @param scheme {string} - * @returns {Boolean} - */ - isEncryption: function (scheme) { - return module.exports[scheme] && module.exports[scheme].isEncryption; - }, + return ret; + }; - /** - * Check if scheme has sign/verify methods - * @param scheme {string} - * @returns {Boolean} - */ - isSignature: function (scheme) { - return module.exports[scheme] && module.exports[scheme].isSignature; + function chunkInvalid(state, chunk) { + var er = null; + if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); + } + return er; + } + + function onEofChunk(stream, state) { + if (state.ended) return; + if (state.decoder) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; } - }; + } + state.ended = true; -/***/ }, -/* 50 */ -/***/ function(module, exports, __webpack_require__) { + // emit 'readable' now to make sure it gets picked up. + emitReadable(stream); + } - /* WEBPACK VAR INJECTION */(function(Buffer) {/** - * PKCS1 padding and signature scheme - */ + // Don't emit readable right away in sync mode, because this can trigger + // another read() call => stack overflow. This way, it might trigger + // a nextTick recursion warning, but that's not so bad. + function emitReadable(stream) { + var state = stream._readableState; + state.needReadable = false; + if (!state.emittedReadable) { + debug('emitReadable', state.flowing); + state.emittedReadable = true; + if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream); + } + } - var BigInteger = __webpack_require__(48); - var crypt = __webpack_require__(30); - var constants = __webpack_require__(26); - var SIGN_INFO_HEAD = { - md2: new Buffer('3020300c06082a864886f70d020205000410', 'hex'), - md5: new Buffer('3020300c06082a864886f70d020505000410', 'hex'), - sha1: new Buffer('3021300906052b0e03021a05000414', 'hex'), - sha224: new Buffer('302d300d06096086480165030402040500041c', 'hex'), - sha256: new Buffer('3031300d060960864801650304020105000420', 'hex'), - sha384: new Buffer('3041300d060960864801650304020205000430', 'hex'), - sha512: new Buffer('3051300d060960864801650304020305000440', 'hex'), - ripemd160: new Buffer('3021300906052b2403020105000414', 'hex'), - rmd160: new Buffer('3021300906052b2403020105000414', 'hex') - }; + function emitReadable_(stream) { + debug('emit readable'); + stream.emit('readable'); + flow(stream); + } - var SIGN_ALG_TO_HASH_ALIASES = { - 'ripemd160': 'rmd160' - }; + // at this point, the user has presumably seen the 'readable' event, + // and called read() to consume some data. that may have triggered + // in turn another _read(n) call, in which case reading = true if + // it's in progress. + // However, if we're not ended, or reading, and the length < hwm, + // then go ahead and try to read some more preemptively. + function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + processNextTick(maybeReadMore_, stream, state); + } + } - var DEFAULT_HASH_FUNCTION = 'sha256'; + function maybeReadMore_(stream, state) { + var len = state.length; + while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { + debug('maybeReadMore read 0'); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break;else len = state.length; + } + state.readingMore = false; + } - module.exports = { - isEncryption: true, - isSignature: true + // abstract method. to be overridden in specific implementation classes. + // call cb(er, data) where data is <= n in length. + // for virtual (non-string, non-buffer) streams, "length" is somewhat + // arbitrary, and perhaps not very meaningful. + Readable.prototype._read = function (n) { + this.emit('error', new Error('not implemented')); }; - module.exports.makeScheme = function (key, options) { - function Scheme(key, options) { - this.key = key; - this.options = options; - } - - Scheme.prototype.maxMessageLength = function () { - if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == constants.RSA_NO_PADDING) { - return this.key.encryptedDataLength; - } - return this.key.encryptedDataLength - 11; - }; + Readable.prototype.pipe = function (dest, pipeOpts) { + var src = this; + var state = this._readableState; - /** - * Pad input Buffer to encryptedDataLength bytes, and return new Buffer - * alg: PKCS#1 - * @param buffer - * @returns {Buffer} - */ - Scheme.prototype.encPad = function (buffer, options) { - options = options || {}; - var filled; - if (buffer.length > this.key.maxMessageLength) { - throw new Error("Message too long for RSA (n=" + this.key.encryptedDataLength + ", l=" + buffer.length + ")"); - } - if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == constants.RSA_NO_PADDING) { - //RSA_NO_PADDING treated like JAVA left pad with zero character - return this.pkcs0pad(buffer); - } + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); - /* Type 1: zeros padding for private key encrypt */ - if (options.type === 1) { - filled = new Buffer(this.key.encryptedDataLength - buffer.length - 1); - filled.fill(0xff, 0, filled.length - 1); - filled[0] = 1; - filled[filled.length - 1] = 0; + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; - return Buffer.concat([filled, buffer]); - } else { - /* random padding for public key encrypt */ - filled = new Buffer(this.key.encryptedDataLength - buffer.length); - filled[0] = 0; - filled[1] = 2; - var rand = crypt.randomBytes(filled.length - 3); - for (var i = 0; i < rand.length; i++) { - var r = rand[i]; - while (r === 0) { // non-zero only - r = crypt.randomBytes(1)[0]; - } - filled[i + 2] = r; - } - filled[filled.length - 1] = 0; - return Buffer.concat([filled, buffer]); - } - }; + var endFn = doEnd ? onend : cleanup; + if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); - /** - * Unpad input Buffer and, if valid, return the Buffer object - * alg: PKCS#1 (type 2, random) - * @param buffer - * @returns {Buffer} - */ - Scheme.prototype.encUnPad = function (buffer, options) { - options = options || {}; - var i = 0; + dest.on('unpipe', onunpipe); + function onunpipe(readable) { + debug('onunpipe'); + if (readable === src) { + cleanup(); + } + } - if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == constants.RSA_NO_PADDING) { - //RSA_NO_PADDING treated like JAVA left pad with zero character - return this.pkcs0unpad(buffer); - } + function onend() { + debug('onend'); + dest.end(); + } - if (buffer.length < 4) { - return null; - } + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on('drain', ondrain); - /* Type 1: zeros padding for private key decrypt */ - if (options.type === 1) { - if (buffer[0] !== 0 && buffer[1] !== 1) { - return null; - } - i = 3; - while (buffer[i] !== 0) { - if (buffer[i] != 0xFF || ++i >= buffer.length) { - return null; - } - } - } else { - /* random padding for public key decrypt */ - if (buffer[0] !== 0 && buffer[1] !== 2) { - return null; - } - i = 3; - while (buffer[i] !== 0) { - if (++i >= buffer.length) { - return null; - } - } - } - return buffer.slice(i + 1, buffer.length); - }; + var cleanedUp = false; + function cleanup() { + debug('cleanup'); + // cleanup event handlers once the pipe is broken + dest.removeListener('close', onclose); + dest.removeListener('finish', onfinish); + dest.removeListener('drain', ondrain); + dest.removeListener('error', onerror); + dest.removeListener('unpipe', onunpipe); + src.removeListener('end', onend); + src.removeListener('end', cleanup); + src.removeListener('data', ondata); - Scheme.prototype.sign = function (buffer) { - var hashAlgorithm = this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION; - if (this.options.environment === 'browser') { - hashAlgorithm = SIGN_ALG_TO_HASH_ALIASES[hashAlgorithm] || hashAlgorithm; + cleanedUp = true; - var hasher = crypt.createHash(hashAlgorithm); - hasher.update(buffer); - var hash = this.pkcs1pad(hasher.digest(), hashAlgorithm); - var res = this.key.$doPrivate(new BigInteger(hash)).toBuffer(this.key.encryptedDataLength); + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } - return res; - } else { - var signer = crypt.createSign('RSA-' + hashAlgorithm.toUpperCase()); - signer.update(buffer); - return signer.sign(this.options.rsaUtils.exportKey('private')); - } - }; + src.on('data', ondata); + function ondata(chunk) { + debug('ondata'); + var ret = dest.write(chunk); + if (false === ret) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + if (state.pipesCount === 1 && state.pipes[0] === dest && src.listenerCount('data') === 1 && !cleanedUp) { + debug('false write response, pause', src._readableState.awaitDrain); + src._readableState.awaitDrain++; + } + src.pause(); + } + } - Scheme.prototype.verify = function (buffer, signature, signature_encoding) { - if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == constants.RSA_NO_PADDING) { - //RSA_NO_PADDING has no verify data - return false; - } - var hashAlgorithm = this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION; - if (this.options.environment === 'browser') { - hashAlgorithm = SIGN_ALG_TO_HASH_ALIASES[hashAlgorithm] || hashAlgorithm; + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug('onerror', er); + unpipe(); + dest.removeListener('error', onerror); + if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); + } + // This is a brutally ugly hack to make sure that our error handler + // is attached before any userland ones. NEVER DO THIS. + if (!dest._events || !dest._events.error) dest.on('error', onerror);else if (isArray(dest._events.error)) dest._events.error.unshift(onerror);else dest._events.error = [onerror, dest._events.error]; - if (signature_encoding) { - signature = new Buffer(signature, signature_encoding); - } + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener('finish', onfinish); + unpipe(); + } + dest.once('close', onclose); + function onfinish() { + debug('onfinish'); + dest.removeListener('close', onclose); + unpipe(); + } + dest.once('finish', onfinish); - var hasher = crypt.createHash(hashAlgorithm); - hasher.update(buffer); - var hash = this.pkcs1pad(hasher.digest(), hashAlgorithm); - var m = this.key.$doPublic(new BigInteger(signature)); + function unpipe() { + debug('unpipe'); + src.unpipe(dest); + } - return m.toBuffer().toString('hex') == hash.toString('hex'); - } else { - var verifier = crypt.createVerify('RSA-' + hashAlgorithm.toUpperCase()); - verifier.update(buffer); - return verifier.verify(this.options.rsaUtils.exportKey('public'), signature, signature_encoding); - } - }; + // tell the dest that it's being piped to + dest.emit('pipe', src); - /** - * PKCS#1 zero pad input buffer to max data length - * @param hashBuf - * @param hashAlgorithm - * @returns {*} - */ - Scheme.prototype.pkcs0pad = function (buffer) { - var filled = new Buffer(this.key.maxMessageLength - buffer.length); - filled.fill(0); - return Buffer.concat([filled, buffer]); + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug('pipe resume'); + src.resume(); + } - return filled; - }; + return dest; + }; - Scheme.prototype.pkcs0unpad = function (buffer) { - var unPad; - if (typeof buffer.lastIndexOf == "function") { //patch for old node version - unPad = buffer.slice(buffer.lastIndexOf('\0') + 1, buffer.length); - } else { - unPad = buffer.slice(String.prototype.lastIndexOf.call(buffer, '\0') + 1, buffer.length); - } + function pipeOnDrain(src) { + return function () { + var state = src._readableState; + debug('pipeOnDrain', state.awaitDrain); + if (state.awaitDrain) state.awaitDrain--; + if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { + state.flowing = true; + flow(src); + } + }; + } - return unPad; - }; + Readable.prototype.unpipe = function (dest) { + var state = this._readableState; - /** - * PKCS#1 pad input buffer to max data length - * @param hashBuf - * @param hashAlgorithm - * @returns {*} - */ - Scheme.prototype.pkcs1pad = function (hashBuf, hashAlgorithm) { - var digest = SIGN_INFO_HEAD[hashAlgorithm]; - if (!digest) { - throw Error('Unsupported hash algorithm'); - } + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) return this; - var data = Buffer.concat([digest, hashBuf]); + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) return this; - if (data.length + 10 > this.key.encryptedDataLength) { - throw Error('Key is too short for signing algorithm (' + hashAlgorithm + ')'); - } + if (!dest) dest = state.pipes; - var filled = new Buffer(this.key.encryptedDataLength - data.length - 1); - filled.fill(0xff, 0, filled.length - 1); - filled[0] = 1; - filled[filled.length - 1] = 0; + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) dest.emit('unpipe', this); + return this; + } - var res = Buffer.concat([filled, data]); + // slow case. multiple pipe destinations. - return res; - }; + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; - return new Scheme(key, options); - }; + for (var _i = 0; _i < len; _i++) { + dests[_i].emit('unpipe', this); + }return this; + } + // try to find the right one. + var i = indexOf(state.pipes, dest); + if (i === -1) return this; + state.pipes.splice(i, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) + dest.emit('unpipe', this); -/***/ }, -/* 51 */ -/***/ function(module, exports, __webpack_require__) { + return this; + }; - /* WEBPACK VAR INJECTION */(function(Buffer) {/** - * PKCS_OAEP signature scheme - */ + // set up data events if they are asked for + // Ensure readable listeners eventually get something + Readable.prototype.on = function (ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); - var BigInteger = __webpack_require__(48); - var crypt = __webpack_require__(30); + // If listening to data, and it has not explicitly been paused, + // then call resume to start the flow of data on the next tick. + if (ev === 'data' && false !== this._readableState.flowing) { + this.resume(); + } - module.exports = { - isEncryption: true, - isSignature: false - }; + if (ev === 'readable' && !this._readableState.endEmitted) { + var state = this._readableState; + if (!state.readableListening) { + state.readableListening = true; + state.emittedReadable = false; + state.needReadable = true; + if (!state.reading) { + processNextTick(nReadingNextTick, this); + } else if (state.length) { + emitReadable(this, state); + } + } + } - module.exports.digestLength = { - md4: 16, - md5: 16, - ripemd160: 20, - rmd160: 20, - sha: 20, - sha1: 20, - sha224: 28, - sha256: 32, - sha384: 48, - sha512: 64 + return res; }; + Readable.prototype.addListener = Readable.prototype.on; - var DEFAULT_HASH_FUNCTION = 'sha1'; + function nReadingNextTick(self) { + debug('readable nexttick read 0'); + self.read(0); + } - /* - * OAEP Mask Generation Function 1 - * Generates a buffer full of pseudorandom bytes given seed and maskLength. - * Giving the same seed, maskLength, and hashFunction will result in the same exact byte values in the buffer. - * - * https://tools.ietf.org/html/rfc3447#appendix-B.2.1 - * - * Parameters: - * seed [Buffer] The pseudo random seed for this function - * maskLength [int] The length of the output - * hashFunction [String] The hashing function to use. Will accept any valid crypto hash. Default "sha1" - * Supports "sha1" and "sha256". - * To add another algorythm the algorythem must be accepted by crypto.createHash, and then the length of the output of the hash function (the digest) must be added to the digestLength object below. - * Most RSA implementations will be expecting sha1 - */ - module.exports.eme_oaep_mgf1 = function (seed, maskLength, hashFunction) { - hashFunction = hashFunction || DEFAULT_HASH_FUNCTION; - var hLen = module.exports.digestLength[hashFunction]; - var count = Math.ceil(maskLength / hLen); - var T = new Buffer(hLen * count); - var c = new Buffer(4); - for (var i = 0; i < count; ++i) { - var hash = crypt.createHash(hashFunction); - hash.update(seed); - c.writeUInt32BE(i, 0); - hash.update(c); - hash.digest().copy(T, i * hLen); - } - return T.slice(0, maskLength); + // pause() and resume() are remnants of the legacy readable stream API + // If the user uses them, then switch into old mode. + Readable.prototype.resume = function () { + var state = this._readableState; + if (!state.flowing) { + debug('resume'); + state.flowing = true; + resume(this, state); + } + return this; }; - module.exports.makeScheme = function (key, options) { - function Scheme(key, options) { - this.key = key; - this.options = options; - } - - Scheme.prototype.maxMessageLength = function () { - return this.key.encryptedDataLength - 2 * module.exports.digestLength[this.options.encryptionSchemeOptions.hash || DEFAULT_HASH_FUNCTION] - 2; - }; + function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + processNextTick(resume_, stream, state); + } + } - /** - * Pad input - * alg: PKCS1_OAEP - * - * https://tools.ietf.org/html/rfc3447#section-7.1.1 - */ - Scheme.prototype.encPad = function (buffer) { - var hash = this.options.encryptionSchemeOptions.hash || DEFAULT_HASH_FUNCTION; - var mgf = this.options.encryptionSchemeOptions.mgf || module.exports.eme_oaep_mgf1; - var label = this.options.encryptionSchemeOptions.label || new Buffer(0); - var emLen = this.key.encryptedDataLength; + function resume_(stream, state) { + if (!state.reading) { + debug('resume read 0'); + stream.read(0); + } - var hLen = module.exports.digestLength[hash]; + state.resumeScheduled = false; + stream.emit('resume'); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); + } - // Make sure we can put message into an encoded message of emLen bytes - if (buffer.length > emLen - 2 * hLen - 2) { - throw new Error("Message is too long to encode into an encoded message with a length of " + emLen + " bytes, increase" + - "emLen to fix this error (minimum value for given parameters and options: " + (emLen - 2 * hLen - 2) + ")"); - } + Readable.prototype.pause = function () { + debug('call pause flowing=%j', this._readableState.flowing); + if (false !== this._readableState.flowing) { + debug('pause'); + this._readableState.flowing = false; + this.emit('pause'); + } + return this; + }; - var lHash = crypt.createHash(hash); - lHash.update(label); - lHash = lHash.digest(); + function flow(stream) { + var state = stream._readableState; + debug('flow', state.flowing); + if (state.flowing) { + do { + var chunk = stream.read(); + } while (null !== chunk && state.flowing); + } + } - var PS = new Buffer(emLen - buffer.length - 2 * hLen - 1); // Padding "String" - PS.fill(0); // Fill the buffer with octets of 0 - PS[PS.length - 1] = 1; + // wrap an old-style stream as the async data source. + // This is *not* part of the readable stream interface. + // It is an ugly unfortunate mess of history. + Readable.prototype.wrap = function (stream) { + var state = this._readableState; + var paused = false; - var DB = Buffer.concat([lHash, PS, buffer]); - var seed = crypt.randomBytes(hLen); + var self = this; + stream.on('end', function () { + debug('wrapped end'); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) self.push(chunk); + } - // mask = dbMask - var mask = mgf(seed, DB.length, hash); - // XOR DB and dbMask together. - for (var i = 0; i < DB.length; i++) { - DB[i] ^= mask[i]; - } - // DB = maskedDB + self.push(null); + }); - // mask = seedMask - mask = mgf(DB, hLen, hash); - // XOR seed and seedMask together. - for (i = 0; i < seed.length; i++) { - seed[i] ^= mask[i]; - } - // seed = maskedSeed + stream.on('data', function (chunk) { + debug('wrapped data'); + if (state.decoder) chunk = state.decoder.write(chunk); - var em = new Buffer(1 + seed.length + DB.length); - em[0] = 0; - seed.copy(em, 1); - DB.copy(em, 1 + seed.length); + // don't skip over falsy values in objectMode + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; - return em; - }; + var ret = self.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); - /** - * Unpad input - * alg: PKCS1_OAEP - * - * Note: This method works within the buffer given and modifies the values. It also returns a slice of the EM as the return Message. - * If the implementation requires that the EM parameter be unmodified then the implementation should pass in a clone of the EM buffer. - * - * https://tools.ietf.org/html/rfc3447#section-7.1.2 - */ - Scheme.prototype.encUnPad = function (buffer) { - var hash = this.options.encryptionSchemeOptions.hash || DEFAULT_HASH_FUNCTION; - var mgf = this.options.encryptionSchemeOptions.mgf || module.exports.eme_oaep_mgf1; - var label = this.options.encryptionSchemeOptions.label || new Buffer(0); + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === 'function') { + this[i] = function (method) { + return function () { + return stream[method].apply(stream, arguments); + }; + }(i); + } + } - var hLen = module.exports.digestLength[hash]; + // proxy certain important events. + var events = ['error', 'close', 'destroy', 'pause', 'resume']; + forEach(events, function (ev) { + stream.on(ev, self.emit.bind(self, ev)); + }); - // Check to see if buffer is a properly encoded OAEP message - if (buffer.length < 2 * hLen + 2) { - throw new Error("Error decoding message, the supplied message is not long enough to be a valid OAEP encoded message"); - } + // when we try to consume some more bytes, simply unpause the + // underlying stream. + self._read = function (n) { + debug('wrapped _read', n); + if (paused) { + paused = false; + stream.resume(); + } + }; - var seed = buffer.slice(1, hLen + 1); // seed = maskedSeed - var DB = buffer.slice(1 + hLen); // DB = maskedDB + return self; + }; - var mask = mgf(DB, hLen, hash); // seedMask - // XOR maskedSeed and seedMask together to get the original seed. - for (var i = 0; i < seed.length; i++) { - seed[i] ^= mask[i]; - } + // exposed for testing purposes only. + Readable._fromList = fromList; - mask = mgf(seed, DB.length, hash); // dbMask - // XOR DB and dbMask together to get the original data block. - for (i = 0; i < DB.length; i++) { - DB[i] ^= mask[i]; - } + // Pluck off n bytes from an array of buffers. + // Length is the combined lengths of all the buffers in the list. + function fromList(n, state) { + var list = state.buffer; + var length = state.length; + var stringMode = !!state.decoder; + var objectMode = !!state.objectMode; + var ret; - var lHash = crypt.createHash(hash); - lHash.update(label); - lHash = lHash.digest(); + // nothing in the list, definitely empty. + if (list.length === 0) return null; - var lHashEM = DB.slice(0, hLen); - if (lHashEM.toString("hex") != lHash.toString("hex")) { - throw new Error("Error decoding message, the lHash calculated from the label provided and the lHash in the encrypted data do not match."); - } + if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) { + // read it all, truncate the array. + if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length); + list.length = 0; + } else { + // read just some of it. + if (n < list[0].length) { + // just take a part of the first list item. + // slice is the same for buffers and strings. + var buf = list[0]; + ret = buf.slice(0, n); + list[0] = buf.slice(n); + } else if (n === list[0].length) { + // first list is a perfect match + ret = list.shift(); + } else { + // complex case. + // we have enough to cover it, but it spans past the first buffer. + if (stringMode) ret = '';else ret = new Buffer(n); - // Filter out padding - i = hLen; - while (DB[i++] === 0 && i < DB.length); - if (DB[i - 1] != 1) { - throw new Error("Error decoding message, there is no padding message separator byte"); - } + var c = 0; + for (var i = 0, l = list.length; i < l && c < n; i++) { + var buf = list[0]; + var cpy = Math.min(n - c, buf.length); - return DB.slice(i); // Message - }; + if (stringMode) ret += buf.slice(0, cpy);else buf.copy(ret, c, 0, cpy); - return new Scheme(key, options); - }; + if (cpy < buf.length) list[0] = buf.slice(cpy);else list.shift(); - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) + c += cpy; + } + } + } -/***/ }, -/* 52 */ -/***/ function(module, exports, __webpack_require__) { + return ret; + } - /* WEBPACK VAR INJECTION */(function(Buffer) {/** - * PSS signature scheme - */ + function endReadable(stream) { + var state = stream._readableState; - var BigInteger = __webpack_require__(48); - var crypt = __webpack_require__(30); + // If we get here before consuming all the bytes, then that is a + // bug in node. Should never happen. + if (state.length > 0) throw new Error('endReadable called on non-empty stream'); - module.exports = { - isEncryption: false, - isSignature: true - }; + if (!state.endEmitted) { + state.ended = true; + processNextTick(endReadableNT, state, stream); + } + } - var DEFAULT_HASH_FUNCTION = 'sha1'; - var DEFAULT_SALT_LENGTH = 20; + function endReadableNT(state, stream) { + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit('end'); + } + } - module.exports.makeScheme = function (key, options) { - var OAEP = __webpack_require__(49).pkcs1_oaep; - - /** - * @param key - * @param options - * options [Object] An object that contains the following keys that specify certain options for encoding. - * └>signingSchemeOptions - * ├>hash [String] Hash function to use when encoding and generating masks. Must be a string accepted by node's crypto.createHash function. (default = "sha1") - * ├>mgf [function] The mask generation function to use when encoding. (default = mgf1SHA1) - * └>sLen [uint] The length of the salt to generate. (default = 20) - * @constructor - */ - function Scheme(key, options) { - this.key = key; - this.options = options; - } + function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } + } - Scheme.prototype.sign = function (buffer) { - var mHash = crypt.createHash(this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION); - mHash.update(buffer); + function indexOf(xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + return -1; + } + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(29))) - var encoded = this.emsa_pss_encode(mHash.digest(), this.key.keySize - 1); - return this.key.$doPrivate(new BigInteger(encoded)).toBuffer(this.key.encryptedDataLength); - }; +/***/ }, +/* 56 */ +/***/ function(module, exports, __webpack_require__) { - Scheme.prototype.verify = function (buffer, signature, signature_encoding) { - if (signature_encoding) { - signature = new Buffer(signature, signature_encoding); - } - signature = new BigInteger(signature); + /* WEBPACK VAR INJECTION */(function(process) {'use strict'; - var emLen = Math.ceil((this.key.keySize - 1) / 8); - var m = this.key.$doPublic(signature).toBuffer(emLen); + if (!process.version || + process.version.indexOf('v0.') === 0 || + process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) { + module.exports = nextTick; + } else { + module.exports = process.nextTick; + } + + function nextTick(fn, arg1, arg2, arg3) { + if (typeof fn !== 'function') { + throw new TypeError('"callback" argument must be a function'); + } + var len = arguments.length; + var args, i; + switch (len) { + case 0: + case 1: + return process.nextTick(fn); + case 2: + return process.nextTick(function afterTickOne() { + fn.call(null, arg1); + }); + case 3: + return process.nextTick(function afterTickTwo() { + fn.call(null, arg1, arg2); + }); + case 4: + return process.nextTick(function afterTickThree() { + fn.call(null, arg1, arg2, arg3); + }); + default: + args = new Array(len - 1); + i = 0; + while (i < args.length) { + args[i++] = arguments[i]; + } + return process.nextTick(function afterTick() { + fn.apply(null, args); + }); + } + } - var mHash = crypt.createHash(this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION); - mHash.update(buffer); + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(29))) - return this.emsa_pss_verify(mHash.digest(), m, this.key.keySize - 1); - }; +/***/ }, +/* 57 */ +/***/ function(module, exports, __webpack_require__) { - /* - * https://tools.ietf.org/html/rfc3447#section-9.1.1 - * - * mHash [Buffer] Hashed message to encode - * emBits [uint] Maximum length of output in bits. Must be at least 8hLen + 8sLen + 9 (hLen = Hash digest length in bytes | sLen = length of salt in bytes) - * @returns {Buffer} The encoded message - */ - Scheme.prototype.emsa_pss_encode = function (mHash, emBits) { - var hash = this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION; - var mgf = this.options.signingSchemeOptions.mgf || OAEP.eme_oaep_mgf1; - var sLen = this.options.signingSchemeOptions.saltLength || DEFAULT_SALT_LENGTH; + /* WEBPACK VAR INJECTION */(function(Buffer) {// Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. - var hLen = OAEP.digestLength[hash]; - var emLen = Math.ceil(emBits / 8); + // NOTE: These type checking functions intentionally don't use `instanceof` + // because it is fragile and can be easily faked with `Object.create()`. - if (emLen < hLen + sLen + 2) { - throw new Error("Output length passed to emBits(" + emBits + ") is too small for the options " + - "specified(" + hash + ", " + sLen + "). To fix this issue increase the value of emBits. (minimum size: " + - (8 * hLen + 8 * sLen + 9) + ")" - ); - } + function isArray(arg) { + if (Array.isArray) { + return Array.isArray(arg); + } + return objectToString(arg) === '[object Array]'; + } + exports.isArray = isArray; - var salt = crypt.randomBytes(sLen); + function isBoolean(arg) { + return typeof arg === 'boolean'; + } + exports.isBoolean = isBoolean; - var Mapostrophe = new Buffer(8 + hLen + sLen); - Mapostrophe.fill(0, 0, 8); - mHash.copy(Mapostrophe, 8); - salt.copy(Mapostrophe, 8 + mHash.length); + function isNull(arg) { + return arg === null; + } + exports.isNull = isNull; - var H = crypt.createHash(hash); - H.update(Mapostrophe); - H = H.digest(); + function isNullOrUndefined(arg) { + return arg == null; + } + exports.isNullOrUndefined = isNullOrUndefined; - var PS = new Buffer(emLen - salt.length - hLen - 2); - PS.fill(0); + function isNumber(arg) { + return typeof arg === 'number'; + } + exports.isNumber = isNumber; - var DB = new Buffer(PS.length + 1 + salt.length); - PS.copy(DB); - DB[PS.length] = 0x01; - salt.copy(DB, PS.length + 1); + function isString(arg) { + return typeof arg === 'string'; + } + exports.isString = isString; - var dbMask = mgf(H, DB.length, hash); + function isSymbol(arg) { + return typeof arg === 'symbol'; + } + exports.isSymbol = isSymbol; - // XOR DB and dbMask together - var maskedDB = new Buffer(DB.length); - for (var i = 0; i < dbMask.length; i++) { - maskedDB[i] = DB[i] ^ dbMask[i]; - } + function isUndefined(arg) { + return arg === void 0; + } + exports.isUndefined = isUndefined; - var bits = 8 * emLen - emBits; - var mask = 255 ^ (255 >> 8 - bits << 8 - bits); - maskedDB[0] = maskedDB[0] & mask; + function isRegExp(re) { + return objectToString(re) === '[object RegExp]'; + } + exports.isRegExp = isRegExp; - var EM = new Buffer(maskedDB.length + H.length + 1); - maskedDB.copy(EM, 0); - H.copy(EM, maskedDB.length); - EM[EM.length - 1] = 0xbc; + function isObject(arg) { + return typeof arg === 'object' && arg !== null; + } + exports.isObject = isObject; - return EM; - }; + function isDate(d) { + return objectToString(d) === '[object Date]'; + } + exports.isDate = isDate; - /* - * https://tools.ietf.org/html/rfc3447#section-9.1.2 - * - * mHash [Buffer] Hashed message - * EM [Buffer] Signature - * emBits [uint] Length of EM in bits. Must be at least 8hLen + 8sLen + 9 to be a valid signature. (hLen = Hash digest length in bytes | sLen = length of salt in bytes) - * @returns {Boolean} True if signature(EM) matches message(M) - */ - Scheme.prototype.emsa_pss_verify = function (mHash, EM, emBits) { - var hash = this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION; - var mgf = this.options.signingSchemeOptions.mgf || OAEP.eme_oaep_mgf1; - var sLen = this.options.signingSchemeOptions.saltLength || DEFAULT_SALT_LENGTH; + function isError(e) { + return (objectToString(e) === '[object Error]' || e instanceof Error); + } + exports.isError = isError; - var hLen = OAEP.digestLength[hash]; - var emLen = Math.ceil(emBits / 8); + function isFunction(arg) { + return typeof arg === 'function'; + } + exports.isFunction = isFunction; - if (emLen < hLen + sLen + 2 || EM[EM.length - 1] != 0xbc) { - return false; - } + function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; + } + exports.isPrimitive = isPrimitive; - var DB = new Buffer(emLen - hLen - 1); - EM.copy(DB, 0, 0, emLen - hLen - 1); + exports.isBuffer = Buffer.isBuffer; - var mask = 0; - for (var i = 0, bits = 8 * emLen - emBits; i < bits; i++) { - mask |= 1 << (7 - i); - } + function objectToString(o) { + return Object.prototype.toString.call(o); + } - if ((DB[0] & mask) !== 0) { - return false; - } + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) - var H = EM.slice(emLen - hLen - 1, emLen - 1); - var dbMask = mgf(H, DB.length, hash); +/***/ }, +/* 58 */ +/***/ function(module, exports) { - // Unmask DB - for (i = 0; i < DB.length; i++) { - DB[i] ^= dbMask[i]; - } + /* (ignored) */ - bits = 8 * emLen - emBits; - mask = 255 ^ (255 >> 8 - bits << 8 - bits); - DB[0] = DB[0] & mask; +/***/ }, +/* 59 */ +/***/ function(module, exports, __webpack_require__) { - // Filter out padding - for (i = 0; DB[i] === 0 && i < DB.length; i++); - if (DB[i] != 1) { - return false; - } + // a duplex stream is just a stream that is both readable and writable. + // Since JS doesn't have multiple prototypal inheritance, this class + // prototypally inherits from Readable, and then parasitically from + // Writable. - var salt = DB.slice(DB.length - sLen); + 'use strict'; - var Mapostrophe = new Buffer(8 + hLen + sLen); - Mapostrophe.fill(0, 0, 8); - mHash.copy(Mapostrophe, 8); - salt.copy(Mapostrophe, 8 + mHash.length); + /**/ - var Hapostrophe = crypt.createHash(hash); - Hapostrophe.update(Mapostrophe); - Hapostrophe = Hapostrophe.digest(); - - return H.toString("hex") === Hapostrophe.toString("hex"); - }; - - return new Scheme(key, options); - }; - - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) - -/***/ }, -/* 53 */ -/***/ function(module, exports, __webpack_require__) { - - var crypt = __webpack_require__(30); - - module.exports = { - getEngine: function (keyPair, options) { - var engine = __webpack_require__(54); - if (options.environment === 'node') { - if (typeof crypt.publicEncrypt === 'function' && typeof crypt.privateDecrypt === 'function') { - if (typeof crypt.privateEncrypt === 'function' && typeof crypt.publicDecrypt === 'function') { - engine = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"./io.js\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - } else { - engine = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"./node12.js\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - } - } - } - return engine(keyPair, options); - } + var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + }return keys; }; + /**/ -/***/ }, -/* 54 */ -/***/ function(module, exports, __webpack_require__) { - - var BigInteger = __webpack_require__(48); - var schemes = __webpack_require__(49); - - module.exports = function (keyPair, options) { - var pkcs1Scheme = schemes.pkcs1.makeScheme(keyPair, options); - - return { - encrypt: function (buffer, usePrivate) { - var m, c; - if (usePrivate) { - /* Type 1: zeros padding for private key encrypt */ - m = new BigInteger(pkcs1Scheme.encPad(buffer, {type: 1})); - c = keyPair.$doPrivate(m); - } else { - m = new BigInteger(keyPair.encryptionScheme.encPad(buffer)); - c = keyPair.$doPublic(m); - } - return c.toBuffer(keyPair.encryptedDataLength); - }, + module.exports = Duplex; - decrypt: function (buffer, usePublic) { - var m, c = new BigInteger(buffer); + /**/ + var processNextTick = __webpack_require__(56); + /**/ - if (usePublic) { - m = keyPair.$doPublic(c); - /* Type 1: zeros padding for private key decrypt */ - return pkcs1Scheme.encUnPad(m.toBuffer(keyPair.encryptedDataLength), {type: 1}); - } else { - m = keyPair.$doPrivate(c); - return keyPair.encryptionScheme.encUnPad(m.toBuffer(keyPair.encryptedDataLength)); - } - } - }; - }; + /**/ + var util = __webpack_require__(57); + util.inherits = __webpack_require__(53); + /**/ -/***/ }, -/* 55 */ -/***/ function(module, exports, __webpack_require__) { + var Readable = __webpack_require__(55); + var Writable = __webpack_require__(60); - // Copyright 2011 Mark Cavage All rights reserved. + util.inherits(Duplex, Readable); - // If you have no idea what ASN.1 or BER is, see this: - // ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc + var keys = objectKeys(Writable.prototype); + for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; + } - var Ber = __webpack_require__(56); + function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); + Readable.call(this, options); + Writable.call(this, options); + if (options && options.readable === false) this.readable = false; - ///--- Exported API + if (options && options.writable === false) this.writable = false; - module.exports = { + this.allowHalfOpen = true; + if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; - Ber: Ber, + this.once('end', onend); + } - BerReader: Ber.Reader, + // the no-half-open enforcer + function onend() { + // if we allow half-open state, or if the writable side ended, + // then we're ok. + if (this.allowHalfOpen || this._writableState.ended) return; - BerWriter: Ber.Writer + // no more data can be written. + // But allow more writes to happen in this tick. + processNextTick(onEndNT, this); + } - }; + function onEndNT(self) { + self.end(); + } + function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } + } /***/ }, -/* 56 */ +/* 60 */ /***/ function(module, exports, __webpack_require__) { - // Copyright 2011 Mark Cavage All rights reserved. + /* WEBPACK VAR INJECTION */(function(process, setImmediate) {// A bit simpler than readable streams. + // Implement an async ._write(chunk, encoding, cb), and it'll handle all + // the drain event emission and buffering. - var errors = __webpack_require__(57); - var types = __webpack_require__(58); + 'use strict'; - var Reader = __webpack_require__(59); - var Writer = __webpack_require__(61); + module.exports = Writable; + /**/ + var processNextTick = __webpack_require__(56); + /**/ - ///--- Exports + /**/ + var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; + /**/ - module.exports = { + /**/ + var Buffer = __webpack_require__(1).Buffer; + /**/ - Reader: Reader, + Writable.WritableState = WritableState; - Writer: Writer + /**/ + var util = __webpack_require__(57); + util.inherits = __webpack_require__(53); + /**/ + /**/ + var internalUtil = { + deprecate: __webpack_require__(63) }; + /**/ - for (var t in types) { - if (types.hasOwnProperty(t)) - module.exports[t] = types[t]; - } - for (var e in errors) { - if (errors.hasOwnProperty(e)) - module.exports[e] = errors[e]; - } + /**/ + var Stream; + (function () { + try { + Stream = __webpack_require__(52); + } catch (_) {} finally { + if (!Stream) Stream = __webpack_require__(5).EventEmitter; + } + })(); + /**/ + var Buffer = __webpack_require__(1).Buffer; -/***/ }, -/* 57 */ -/***/ function(module, exports) { + util.inherits(Writable, Stream); - // Copyright 2011 Mark Cavage All rights reserved. + function nop() {} + function WriteReq(chunk, encoding, cb) { + this.chunk = chunk; + this.encoding = encoding; + this.callback = cb; + this.next = null; + } - module.exports = { + var Duplex; + function WritableState(options, stream) { + Duplex = Duplex || __webpack_require__(59); - newInvalidAsn1Error: function(msg) { - var e = new Error(); - e.name = 'InvalidAsn1Error'; - e.message = msg || ''; - return e; - } + options = options || {}; - }; + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode; -/***/ }, -/* 58 */ -/***/ function(module, exports) { + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; - // Copyright 2011 Mark Cavage All rights reserved. + // cast to ints. + this.highWaterMark = ~ ~this.highWaterMark; + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; - module.exports = { - EOC: 0, - Boolean: 1, - Integer: 2, - BitString: 3, - OctetString: 4, - Null: 5, - OID: 6, - ObjectDescriptor: 7, - External: 8, - Real: 9, // float - Enumeration: 10, - PDV: 11, - Utf8String: 12, - RelativeOID: 13, - Sequence: 16, - Set: 17, - NumericString: 18, - PrintableString: 19, - T61String: 20, - VideotexString: 21, - IA5String: 22, - UTCTime: 23, - GeneralizedTime: 24, - GraphicString: 25, - VisibleString: 26, - GeneralString: 28, - UniversalString: 29, - CharacterString: 30, - BMPString: 31, - Constructor: 32, - Context: 128 - }; + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; -/***/ }, -/* 59 */ -/***/ function(module, exports, __webpack_require__) { + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; - /* WEBPACK VAR INJECTION */(function(Buffer) {// Copyright 2011 Mark Cavage All rights reserved. + // a flag to see when we're in the middle of a write. + this.writing = false; - var assert = __webpack_require__(60); + // when true all writes will be buffered until .uncork() call + this.corked = 0; - var ASN1 = __webpack_require__(58); - var errors = __webpack_require__(57); + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; - ///--- Globals + // the callback that's passed to _write(chunk,cb) + this.onwrite = function (er) { + onwrite(stream, er); + }; - var newInvalidAsn1Error = errors.newInvalidAsn1Error; + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; + // the amount that is being written when _write is called. + this.writelen = 0; + this.bufferedRequest = null; + this.lastBufferedRequest = null; - ///--- API + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; - function Reader(data) { - if (!data || !Buffer.isBuffer(data)) - throw new TypeError('data must be a node Buffer'); + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; - this._buf = data; - this._size = data.length; + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; - // These hold the "current" state - this._len = 0; - this._offset = 0; - } + // count buffered requests + this.bufferedRequestCount = 0; - Object.defineProperty(Reader.prototype, 'length', { - enumerable: true, - get: function () { return (this._len); } - }); + // create the two objects needed to store the corked requests + // they are not a linked list, as no new elements are inserted in there + this.corkedRequestsFree = new CorkedRequest(this); + this.corkedRequestsFree.next = new CorkedRequest(this); + } - Object.defineProperty(Reader.prototype, 'offset', { - enumerable: true, - get: function () { return (this._offset); } - }); + WritableState.prototype.getBuffer = function writableStateGetBuffer() { + var current = this.bufferedRequest; + var out = []; + while (current) { + out.push(current); + current = current.next; + } + return out; + }; - Object.defineProperty(Reader.prototype, 'remain', { - get: function () { return (this._size - this._offset); } - }); + (function () { + try { + Object.defineProperty(WritableState.prototype, 'buffer', { + get: internalUtil.deprecate(function () { + return this.getBuffer(); + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.') + }); + } catch (_) {} + })(); - Object.defineProperty(Reader.prototype, 'buffer', { - get: function () { return (this._buf.slice(this._offset)); } - }); + var Duplex; + function Writable(options) { + Duplex = Duplex || __webpack_require__(59); + // Writable ctor is applied to Duplexes, though they're not + // instanceof Writable, they're instanceof Readable. + if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options); - /** - * Reads a single byte and advances offset; you can pass in `true` to make this - * a "peek" operation (i.e., get the byte, but don't advance the offset). - * - * @param {Boolean} peek true means don't move offset. - * @return {Number} the next byte, null if not enough data. - */ - Reader.prototype.readByte = function(peek) { - if (this._size - this._offset < 1) - return null; + this._writableState = new WritableState(options, this); - var b = this._buf[this._offset] & 0xff; + // legacy. + this.writable = true; - if (!peek) - this._offset += 1; + if (options) { + if (typeof options.write === 'function') this._write = options.write; - return b; - }; + if (typeof options.writev === 'function') this._writev = options.writev; + } + Stream.call(this); + } - Reader.prototype.peek = function() { - return this.readByte(true); + // Otherwise people can pipe Writable streams, which is just wrong. + Writable.prototype.pipe = function () { + this.emit('error', new Error('Cannot pipe. Not readable.')); }; + function writeAfterEnd(stream, cb) { + var er = new Error('write after end'); + // TODO: defer error events consistently everywhere, not just the cb + stream.emit('error', er); + processNextTick(cb, er); + } - /** - * Reads a (potentially) variable length off the BER buffer. This call is - * not really meant to be called directly, as callers have to manipulate - * the internal buffer afterwards. - * - * As a result of this call, you can call `Reader.length`, until the - * next thing called that does a readLength. - * - * @return {Number} the amount of offset to advance the buffer. - * @throws {InvalidAsn1Error} on bad ASN.1 - */ - Reader.prototype.readLength = function(offset) { - if (offset === undefined) - offset = this._offset; - - if (offset >= this._size) - return null; - - var lenB = this._buf[offset++] & 0xff; - if (lenB === null) - return null; + // If we get something that is not a buffer, string, null, or undefined, + // and we're not in objectMode, then that's an error. + // Otherwise stream chunks are all considered to be of length=1, and the + // watermarks determine how many objects to keep in the buffer, rather than + // how many bytes or characters. + function validChunk(stream, state, chunk, cb) { + var valid = true; - if ((lenB & 0x80) == 0x80) { - lenB &= 0x7f; + if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { + var er = new TypeError('Invalid non-string/buffer chunk'); + stream.emit('error', er); + processNextTick(cb, er); + valid = false; + } + return valid; + } - if (lenB == 0) - throw newInvalidAsn1Error('Indefinite length not supported'); + Writable.prototype.write = function (chunk, encoding, cb) { + var state = this._writableState; + var ret = false; - if (lenB > 4) - throw newInvalidAsn1Error('encoding too long'); + if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } - if (this._size - offset < lenB) - return null; + if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; - this._len = 0; - for (var i = 0; i < lenB; i++) - this._len = (this._len << 8) + (this._buf[offset++] & 0xff); + if (typeof cb !== 'function') cb = nop; - } else { - // Wasn't a variable length - this._len = lenB; + if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, chunk, encoding, cb); } - return offset; + return ret; }; + Writable.prototype.cork = function () { + var state = this._writableState; - /** - * Parses the next sequence in this BER buffer. - * - * To get the length of the sequence, call `Reader.length`. - * - * @return {Number} the sequence's tag. - */ - Reader.prototype.readSequence = function(tag) { - var seq = this.peek(); - if (seq === null) - return null; - if (tag !== undefined && tag !== seq) - throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + - ': got 0x' + seq.toString(16)); - - var o = this.readLength(this._offset + 1); // stored in `length` - if (o === null) - return null; - - this._offset = o; - return seq; + state.corked++; }; + Writable.prototype.uncork = function () { + var state = this._writableState; - Reader.prototype.readInt = function() { - return this._readTag(ASN1.Integer); - }; - + if (state.corked) { + state.corked--; - Reader.prototype.readBoolean = function() { - return (this._readTag(ASN1.Boolean) === 0 ? false : true); + if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); + } }; - - Reader.prototype.readEnumeration = function() { - return this._readTag(ASN1.Enumeration); + Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === 'string') encoding = encoding.toLowerCase(); + if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding); + this._writableState.defaultEncoding = encoding; }; + function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { + chunk = new Buffer(chunk, encoding); + } + return chunk; + } - Reader.prototype.readString = function(tag, retbuf) { - if (!tag) - tag = ASN1.OctetString; - - var b = this.peek(); - if (b === null) - return null; + // if we're already writing something, then just put this + // in the queue, and wait our turn. Otherwise, call _write + // If we return false, then we need a drain event, so set that flag. + function writeOrBuffer(stream, state, chunk, encoding, cb) { + chunk = decodeChunk(state, chunk, encoding); - if (b !== tag) - throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + - ': got 0x' + b.toString(16)); + if (Buffer.isBuffer(chunk)) encoding = 'buffer'; + var len = state.objectMode ? 1 : chunk.length; - var o = this.readLength(this._offset + 1); // stored in `length` + state.length += len; - if (o === null) - return null; + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) state.needDrain = true; - if (this.length > this._size - o) - return null; + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = new WriteReq(chunk, encoding, cb); + if (last) { + last.next = state.lastBufferedRequest; + } else { + state.bufferedRequest = state.lastBufferedRequest; + } + state.bufferedRequestCount += 1; + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } - this._offset = o; + return ret; + } - if (this.length === 0) - return retbuf ? new Buffer(0) : ''; + function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; + } - var str = this._buf.slice(this._offset, this._offset + this.length); - this._offset += this.length; + function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + if (sync) processNextTick(cb, er);else cb(er); - return retbuf ? str : str.toString('utf8'); - }; + stream._writableState.errorEmitted = true; + stream.emit('error', er); + } - Reader.prototype.readOID = function(tag) { - if (!tag) - tag = ASN1.OID; + function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; + } - var b = this.readString(tag, true); - if (b === null) - return null; + function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; - var values = []; - var value = 0; + onwriteStateUpdate(state); - for (var i = 0; i < b.length; i++) { - var byte = b[i] & 0xff; + if (er) onwriteError(stream, state, sync, er, cb);else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state); - value <<= 7; - value += byte & 0x7f; - if ((byte & 0x80) == 0) { - values.push(value); - value = 0; + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { + clearBuffer(stream, state); } + + if (sync) { + /**/ + asyncWrite(afterWrite, stream, state, finished, cb); + /**/ + } else { + afterWrite(stream, state, finished, cb); + } } + } - value = values.shift(); - values.unshift(value % 40); - values.unshift((value / 40) >> 0); + function afterWrite(stream, state, finished, cb) { + if (!finished) onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); + } - return values.join('.'); - }; - - - Reader.prototype._readTag = function(tag) { - assert.ok(tag !== undefined); - - var b = this.peek(); + // Must force callback to be called on nextTick, so that we don't + // emit 'drain' before the write() consumer gets the 'false' return + // value, and has a chance to attach a 'drain' listener. + function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit('drain'); + } + } - if (b === null) - return null; + // if there's something in the buffer waiting, then process it + function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; - if (b !== tag) - throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + - ': got 0x' + b.toString(16)); + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; - var o = this.readLength(this._offset + 1); // stored in `length` - if (o === null) - return null; + var count = 0; + while (entry) { + buffer[count] = entry; + entry = entry.next; + count += 1; + } - if (this.length > 4) - throw newInvalidAsn1Error('Integer too long: ' + this.length); + doWrite(stream, state, true, state.length, buffer, '', holder.finish); - if (this.length > this._size - o) - return null; - this._offset = o; + // doWrite is always async, defer these to save a bit of time + // as the hot path ends with doWrite + state.pendingcb++; + state.lastBufferedRequest = null; + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; - var fb = this._buf[this._offset]; - var value = 0; + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + break; + } + } - for (var i = 0; i < this.length; i++) { - value <<= 8; - value |= (this._buf[this._offset++] & 0xff); + if (entry === null) state.lastBufferedRequest = null; } - if ((fb & 0x80) == 0x80 && i !== 4) - value -= (1 << (i * 8)); + state.bufferedRequestCount = 0; + state.bufferedRequest = entry; + state.bufferProcessing = false; + } - return value >> 0; + Writable.prototype._write = function (chunk, encoding, cb) { + cb(new Error('not implemented')); }; + Writable.prototype._writev = null; + Writable.prototype.end = function (chunk, encoding, cb) { + var state = this._writableState; - ///--- Exported API - - module.exports = Reader; + if (typeof chunk === 'function') { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } - /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer)) + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); -/***/ }, -/* 60 */ -/***/ function(module, exports, __webpack_require__) { + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); + } - /* WEBPACK VAR INJECTION */(function(global) {'use strict'; + // ignore unnecessary end() calls. + if (!state.ending && !state.finished) endWritable(this, state, cb); + }; - // compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js - // original notice: + function needFinish(state) { + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; + } - /*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ - function compare(a, b) { - if (a === b) { - return 0; + function prefinish(stream, state) { + if (!state.prefinished) { + state.prefinished = true; + stream.emit('prefinish'); } + } - var x = a.length; - var y = b.length; - - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break; + function finishMaybe(stream, state) { + var need = needFinish(state); + if (need) { + if (state.pendingcb === 0) { + prefinish(stream, state); + state.finished = true; + stream.emit('finish'); + } else { + prefinish(stream, state); } } - - if (x < y) { - return -1; - } - if (y < x) { - return 1; - } - return 0; + return need; } - function isBuffer(b) { - if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { - return global.Buffer.isBuffer(b); + + function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) processNextTick(cb);else stream.once('finish', cb); } - return !!(b != null && b._isBuffer); + state.ended = true; + stream.writable = false; } - // based on node assert, original notice: + // It seems a linked list but it is not + // there will be only 2 of these for each stream + function CorkedRequest(state) { + var _this = this; - // http://wiki.commonjs.org/wiki/Unit_Testing/1.0 - // - // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! - // - // Originally from narwhal.js (http://narwhaljs.org) - // Copyright (c) 2009 Thomas Robinson <280north.com> - // - // Permission is hereby granted, free of charge, to any person obtaining a copy - // of this software and associated documentation files (the 'Software'), to - // deal in the Software without restriction, including without limitation the - // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - // sell copies of the Software, and to permit persons to whom the Software is - // furnished to do so, subject to the following conditions: - // - // The above copyright notice and this permission notice shall be included in - // all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + this.next = null; + this.entry = null; - var util = __webpack_require__(37); - var hasOwn = Object.prototype.hasOwnProperty; - var pSlice = Array.prototype.slice; - var functionsHaveNames = (function () { - return function foo() {}.name === 'foo'; - }()); - function pToString (obj) { - return Object.prototype.toString.call(obj); + this.finish = function (err) { + var entry = _this.entry; + _this.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } + if (state.corkedRequestsFree) { + state.corkedRequestsFree.next = _this; + } else { + state.corkedRequestsFree = _this; + } + }; } - function isView(arrbuf) { - if (isBuffer(arrbuf)) { - return false; - } - if (typeof global.ArrayBuffer !== 'function') { - return false; - } - if (typeof ArrayBuffer.isView === 'function') { - return ArrayBuffer.isView(arrbuf); - } - if (!arrbuf) { - return false; - } - if (arrbuf instanceof DataView) { - return true; - } - if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) { - return true; + /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(29), __webpack_require__(61).setImmediate)) + +/***/ }, +/* 61 */ +/***/ function(module, exports, __webpack_require__) { + + var apply = Function.prototype.apply; + + // DOM APIs, for completeness + + exports.setTimeout = function() { + return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout); + }; + exports.setInterval = function() { + return new Timeout(apply.call(setInterval, window, arguments), clearInterval); + }; + exports.clearTimeout = + exports.clearInterval = function(timeout) { + if (timeout) { + timeout.close(); } - return false; + }; + + function Timeout(id, clearFn) { + this._id = id; + this._clearFn = clearFn; } - // 1. The assert module provides functions that throw - // AssertionError's when particular conditions are not met. The - // assert module must conform to the following interface. + Timeout.prototype.unref = Timeout.prototype.ref = function() {}; + Timeout.prototype.close = function() { + this._clearFn.call(window, this._id); + }; - var assert = module.exports = ok; + // Does not start the time, just sets up the members needed. + exports.enroll = function(item, msecs) { + clearTimeout(item._idleTimeoutId); + item._idleTimeout = msecs; + }; - // 2. The AssertionError is defined in assert. - // new assert.AssertionError({ message: message, - // actual: actual, - // expected: expected }) + exports.unenroll = function(item) { + clearTimeout(item._idleTimeoutId); + item._idleTimeout = -1; + }; - var regex = /\s*function\s+([^\(\s]*)\s*/; - // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js - function getName(func) { - if (!util.isFunction(func)) { - return; - } - if (functionsHaveNames) { - return func.name; + exports._unrefActive = exports.active = function(item) { + clearTimeout(item._idleTimeoutId); + + var msecs = item._idleTimeout; + if (msecs >= 0) { + item._idleTimeoutId = setTimeout(function onTimeout() { + if (item._onTimeout) + item._onTimeout(); + }, msecs); } - var str = func.toString(); - var match = str.match(regex); - return match && match[1]; - } - assert.AssertionError = function AssertionError(options) { - this.name = 'AssertionError'; - this.actual = options.actual; - this.expected = options.expected; - this.operator = options.operator; - if (options.message) { - this.message = options.message; - this.generatedMessage = false; - } else { - this.message = getMessage(this); - this.generatedMessage = true; - } - var stackStartFunction = options.stackStartFunction || fail; - if (Error.captureStackTrace) { - Error.captureStackTrace(this, stackStartFunction); - } else { - // non v8 browsers so we can have a stacktrace - var err = new Error(); - if (err.stack) { - var out = err.stack; + }; - // try to strip useless frames - var fn_name = getName(stackStartFunction); - var idx = out.indexOf('\n' + fn_name); - if (idx >= 0) { - // once we have located the function frame - // we need to strip out everything before it (and its line) - var next_line = out.indexOf('\n', idx + 1); - out = out.substring(next_line + 1); + // setimmediate attaches itself to the global object + __webpack_require__(62); + exports.setImmediate = setImmediate; + exports.clearImmediate = clearImmediate; + + +/***/ }, +/* 62 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) { + "use strict"; + + if (global.setImmediate) { + return; + } + + var nextHandle = 1; // Spec says greater than zero + var tasksByHandle = {}; + var currentlyRunningATask = false; + var doc = global.document; + var registerImmediate; + + function setImmediate(callback) { + // Callback can either be a function or a string + if (typeof callback !== "function") { + callback = new Function("" + callback); } + // Copy function arguments + var args = new Array(arguments.length - 1); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i + 1]; + } + // Store and register the task + var task = { callback: callback, args: args }; + tasksByHandle[nextHandle] = task; + registerImmediate(nextHandle); + return nextHandle++; + } - this.stack = out; + function clearImmediate(handle) { + delete tasksByHandle[handle]; } - } - }; - // assert.AssertionError instanceof Error - util.inherits(assert.AssertionError, Error); + function run(task) { + var callback = task.callback; + var args = task.args; + switch (args.length) { + case 0: + callback(); + break; + case 1: + callback(args[0]); + break; + case 2: + callback(args[0], args[1]); + break; + case 3: + callback(args[0], args[1], args[2]); + break; + default: + callback.apply(undefined, args); + break; + } + } - function truncate(s, n) { - if (typeof s === 'string') { - return s.length < n ? s : s.slice(0, n); - } else { - return s; - } - } - function inspect(something) { - if (functionsHaveNames || !util.isFunction(something)) { - return util.inspect(something); - } - var rawname = getName(something); - var name = rawname ? ': ' + rawname : ''; - return '[Function' + name + ']'; - } - function getMessage(self) { - return truncate(inspect(self.actual), 128) + ' ' + - self.operator + ' ' + - truncate(inspect(self.expected), 128); - } + function runIfPresent(handle) { + // From the spec: "Wait until any invocations of this algorithm started before this one have completed." + // So if we're currently running a task, we'll need to delay this invocation. + if (currentlyRunningATask) { + // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a + // "too much recursion" error. + setTimeout(runIfPresent, 0, handle); + } else { + var task = tasksByHandle[handle]; + if (task) { + currentlyRunningATask = true; + try { + run(task); + } finally { + clearImmediate(handle); + currentlyRunningATask = false; + } + } + } + } - // At present only the three keys mentioned above are used and - // understood by the spec. Implementations or sub modules can pass - // other keys to the AssertionError's constructor - they will be - // ignored. + function installNextTickImplementation() { + registerImmediate = function(handle) { + process.nextTick(function () { runIfPresent(handle); }); + }; + } - // 3. All of the following functions must throw an AssertionError - // when a corresponding condition is not met, with a message that - // may be undefined if not provided. All assertion methods provide - // both the actual and expected values to the assertion error for - // display purposes. + function canUsePostMessage() { + // The test against `importScripts` prevents this implementation from being installed inside a web worker, + // where `global.postMessage` means something completely different and can't be used for this purpose. + if (global.postMessage && !global.importScripts) { + var postMessageIsAsynchronous = true; + var oldOnMessage = global.onmessage; + global.onmessage = function() { + postMessageIsAsynchronous = false; + }; + global.postMessage("", "*"); + global.onmessage = oldOnMessage; + return postMessageIsAsynchronous; + } + } - function fail(actual, expected, message, operator, stackStartFunction) { - throw new assert.AssertionError({ - message: message, - actual: actual, - expected: expected, - operator: operator, - stackStartFunction: stackStartFunction - }); - } + function installPostMessageImplementation() { + // Installs an event handler on `global` for the `message` event: see + // * https://developer.mozilla.org/en/DOM/window.postMessage + // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages - // EXTENSION! allows for well behaved errors defined elsewhere. - assert.fail = fail; + var messagePrefix = "setImmediate$" + Math.random() + "$"; + var onGlobalMessage = function(event) { + if (event.source === global && + typeof event.data === "string" && + event.data.indexOf(messagePrefix) === 0) { + runIfPresent(+event.data.slice(messagePrefix.length)); + } + }; - // 4. Pure assertion tests whether a value is truthy, as determined - // by !!guard. - // assert.ok(guard, message_opt); - // This statement is equivalent to assert.equal(true, !!guard, - // message_opt);. To test strictly for the value true, use - // assert.strictEqual(true, guard, message_opt);. + if (global.addEventListener) { + global.addEventListener("message", onGlobalMessage, false); + } else { + global.attachEvent("onmessage", onGlobalMessage); + } - function ok(value, message) { - if (!value) fail(value, true, message, '==', assert.ok); - } - assert.ok = ok; + registerImmediate = function(handle) { + global.postMessage(messagePrefix + handle, "*"); + }; + } - // 5. The equality assertion tests shallow, coercive equality with - // ==. - // assert.equal(actual, expected, message_opt); + function installMessageChannelImplementation() { + var channel = new MessageChannel(); + channel.port1.onmessage = function(event) { + var handle = event.data; + runIfPresent(handle); + }; - assert.equal = function equal(actual, expected, message) { - if (actual != expected) fail(actual, expected, message, '==', assert.equal); - }; + registerImmediate = function(handle) { + channel.port2.postMessage(handle); + }; + } - // 6. The non-equality assertion tests for whether two objects are not equal - // with != assert.notEqual(actual, expected, message_opt); + function installReadyStateChangeImplementation() { + var html = doc.documentElement; + registerImmediate = function(handle) { + // Create a