1 (function(e){if("function"==typeof bootstrap)bootstrap("ohauth",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeOhauth=e}else"undefined"!=typeof window?window.ohauth=e():global.ohauth=e()})(function(){var define,ses,bootstrap,module,exports;
2 return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
5 var hashes = require('jshashes'),
6 xtend = require('xtend'),
7 sha1 = new hashes.SHA1();
11 ohauth.qsString = function(obj) {
12 return Object.keys(obj).sort().map(function(key) {
13 return ohauth.percentEncode(key) + '=' +
14 ohauth.percentEncode(obj[key]);
18 ohauth.stringQs = function(str) {
19 return str.split('&').filter(function (pair) {
21 }).reduce(function(obj, pair){
22 var parts = pair.split('=');
23 obj[decodeURIComponent(parts[0])] = (null === parts[1]) ?
24 '' : decodeURIComponent(parts[1]);
29 ohauth.rawxhr = function(method, url, data, headers, callback) {
30 var xhr = new XMLHttpRequest(),
31 twoHundred = /^20\d$/;
32 xhr.onreadystatechange = function() {
33 if (4 == xhr.readyState && 0 !== xhr.status) {
34 if (twoHundred.test(xhr.status)) callback(null, xhr);
35 else return callback(xhr, null);
38 xhr.onerror = function(e) { return callback(e, null); };
39 xhr.open(method, url, true);
40 for (var h in headers) xhr.setRequestHeader(h, headers[h]);
44 ohauth.xhr = function(method, url, auth, data, options, callback) {
45 var headers = (options && options.header) || {
46 'Content-Type': 'application/x-www-form-urlencoded'
48 headers.Authorization = 'OAuth ' + ohauth.authHeader(auth);
49 ohauth.rawxhr(method, url, data, headers, callback);
52 ohauth.nonce = function() {
53 for (var o = ''; o.length < 6;) {
54 o += '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'[Math.floor(Math.random() * 61)];
59 ohauth.authHeader = function(obj) {
60 return Object.keys(obj).sort().map(function(key) {
61 return encodeURIComponent(key) + '="' + encodeURIComponent(obj[key]) + '"';
65 ohauth.timestamp = function() { return ~~((+new Date()) / 1000); };
67 ohauth.percentEncode = function(s) {
68 return encodeURIComponent(s)
69 .replace(/\!/g, '%21').replace(/\'/g, '%27')
70 .replace(/\*/g, '%2A').replace(/\(/g, '%28').replace(/\)/g, '%29');
73 ohauth.baseString = function(method, url, params) {
74 if (params.oauth_signature) delete params.oauth_signature;
77 ohauth.percentEncode(url),
78 ohauth.percentEncode(ohauth.qsString(params))].join('&');
81 ohauth.signature = function(oauth_secret, token_secret, baseString) {
83 ohauth.percentEncode(oauth_secret) + '&' +
84 ohauth.percentEncode(token_secret),
89 * Takes an options object for configuration (consumer_key,
90 * consumer_secret, version, signature_method, token, token_secret)
91 * and returns a function that generates the Authorization header
94 * The returned function takes these parameters:
95 * - method: GET/POST/...
96 * - uri: full URI with protocol, port, path and query string
97 * - extra_params: any extra parameters (that are passed in the POST data),
98 * can be an object or a from-urlencoded string.
100 * Returned function returns full OAuth header with "OAuth" string in it.
103 ohauth.headerGenerator = function(options) {
104 options = options || {};
105 var consumer_key = options.consumer_key || '',
106 consumer_secret = options.consumer_secret || '',
107 signature_method = options.signature_method || 'HMAC-SHA1',
108 version = options.version || '1.0',
109 token = options.token || '',
110 token_secret = options.token_secret || '';
112 return function(method, uri, extra_params) {
113 method = method.toUpperCase();
114 if (typeof extra_params === 'string' && extra_params.length > 0) {
115 extra_params = ohauth.stringQs(extra_params);
118 var uri_parts = uri.split('?', 2),
119 base_uri = uri_parts[0];
121 var query_params = uri_parts.length === 2 ?
122 ohauth.stringQs(uri_parts[1]) : {};
125 oauth_consumer_key: consumer_key,
126 oauth_signature_method: signature_method,
127 oauth_version: version,
128 oauth_timestamp: ohauth.timestamp(),
129 oauth_nonce: ohauth.nonce()
132 if (token) oauth_params.oauth_token = token;
134 var all_params = xtend({}, oauth_params, query_params, extra_params),
135 base_str = ohauth.baseString(method, base_uri, all_params);
137 oauth_params.oauth_signature = ohauth.signature(consumer_secret, token_secret, base_str);
139 return 'OAuth ' + ohauth.authHeader(oauth_params);
143 module.exports = ohauth;
145 },{"jshashes":2,"xtend":3}],2:[function(require,module,exports){
146 (function(global){/**
147 * jsHashes - A fast and independent hashing library pure JavaScript implemented (ES5 compliant) for both server and client side
150 * @author Tomas Aparicio <tomas@rijndael-project.com>
151 * @license New BSD (see LICENSE file)
154 * Algorithms specification:
156 * MD5 <http://www.ietf.org/rfc/rfc1321.txt>
157 * RIPEMD-160 <http://homes.esat.kuleuven.be/~bosselae/ripemd160.html>
158 * SHA1 <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
159 * SHA256 <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
160 * SHA512 <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
161 * HMAC <http://www.ietf.org/rfc/rfc2104.txt>
167 // private helper methods
168 function utf8Encode(input) {
169 var x, y, output = '', i = -1, l = input.length;
171 /* Decode utf-16 surrogate pairs */
172 x = input.charCodeAt(i);
173 y = i + 1 < l ? input.charCodeAt(i + 1) : 0;
174 if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
175 x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
178 /* Encode output as utf-8 */
180 output += String.fromCharCode(x);
181 } else if (x <= 0x7FF) {
182 output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
184 } else if (x <= 0xFFFF) {
185 output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
186 0x80 | ((x >>> 6 ) & 0x3F),
188 } else if (x <= 0x1FFFFF) {
189 output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
190 0x80 | ((x >>> 12) & 0x3F),
191 0x80 | ((x >>> 6 ) & 0x3F),
198 function utf8Decode(str_data) {
199 var i, ac, c1, c2, c3, arr = [], l = str_data.length;
200 i = ac = c1 = c2 = c3 = 0;
204 c1 = str_data.charCodeAt(i);
207 arr[ac] = String.fromCharCode(c1);
209 } else if (c1 > 191 && c1 < 224) {
210 c2 = str_data.charCodeAt(i + 1);
211 arr[ac] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
214 c2 = str_data.charCodeAt(i + 1);
215 c3 = str_data.charCodeAt(i + 2);
216 arr[ac] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
224 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
225 * to work around bugs in some JS interpreters.
227 function safe_add(x, y) {
228 var lsw = (x & 0xFFFF) + (y & 0xFFFF),
229 msw = (x >> 16) + (y >> 16) + (lsw >> 16);
230 return (msw << 16) | (lsw & 0xFFFF);
234 * Bitwise rotate a 32-bit number to the left.
236 function bit_rol(num, cnt) {
237 return (num << cnt) | (num >>> (32 - cnt));
241 * Convert a raw string to a hex string
243 function rstr2hex(input, hexcase) {
244 var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef',
245 output = '', x, i = 0, l = input.length;
246 for (; i < l; i+=1) {
247 x = input.charCodeAt(i);
248 output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F);
254 * Encode a string as utf-16
256 function str2rstr_utf16le(input) {
257 var i, l = input.length, output = '';
258 for (i = 0; i < l; i+=1) {
259 output += String.fromCharCode( input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);
264 function str2rstr_utf16be(input) {
265 var i, l = input.length, output = '';
266 for (i = 0; i < l; i+=1) {
267 output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);
273 * Convert an array of big-endian words to a string
275 function binb2rstr(input) {
276 var i, l = input.length * 32, output = '';
277 for (i = 0; i < l; i += 8) {
278 output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
284 * Convert an array of little-endian words to a string
286 function binl2rstr(input) {
287 var i, l = input.length * 32, output = '';
288 for (i = 0;i < l; i += 8) {
289 output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
295 * Convert a raw string to an array of little-endian words
296 * Characters >255 have their high-byte silently ignored.
298 function rstr2binl(input) {
299 var i, l = input.length * 8, output = Array(input.length >> 2), lo = output.length;
300 for (i = 0; i < lo; i+=1) {
303 for (i = 0; i < l; i += 8) {
304 output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
310 * Convert a raw string to an array of big-endian words
311 * Characters >255 have their high-byte silently ignored.
313 function rstr2binb(input) {
314 var i, l = input.length * 8, output = Array(input.length >> 2), lo = output.length;
315 for (i = 0; i < lo; i+=1) {
318 for (i = 0; i < l; i += 8) {
319 output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
325 * Convert a raw string to an arbitrary string encoding
327 function rstr2any(input, encoding) {
328 var divisor = encoding.length,
329 remainders = Array(),
330 i, q, x, ld, quotient, dividend, output, full_length;
332 /* Convert to an array of 16-bit big-endian values, forming the dividend */
333 dividend = Array(Math.ceil(input.length / 2));
334 ld = dividend.length;
335 for (i = 0; i < ld; i+=1) {
336 dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
340 * Repeatedly perform a long division. The binary array forms the dividend,
341 * the length of the encoding is the divisor. Once computed, the quotient
342 * forms the dividend for the next step. We stop when the dividend is zerHashes.
343 * All remainders are stored for later use.
345 while(dividend.length > 0) {
348 for (i = 0; i < dividend.length; i+=1) {
349 x = (x << 16) + dividend[i];
350 q = Math.floor(x / divisor);
352 if (quotient.length > 0 || q > 0) {
353 quotient[quotient.length] = q;
356 remainders[remainders.length] = x;
360 /* Convert the remainders to the output string */
362 for (i = remainders.length - 1; i >= 0; i--) {
363 output += encoding.charAt(remainders[i]);
366 /* Append leading zero equivalents */
367 full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
368 for (i = output.length; i < full_length; i+=1) {
369 output = encoding[0] + output;
375 * Convert a raw string to a base-64 string
377 function rstr2b64(input, b64pad) {
378 var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
380 len = input.length, i, j, triplet;
381 b64pad= b64pad || '=';
382 for (i = 0; i < len; i += 3) {
383 triplet = (input.charCodeAt(i) << 16)
384 | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
385 | (i + 2 < len ? input.charCodeAt(i+2) : 0);
386 for (j = 0; j < 4; j+=1) {
387 if (i * 8 + j * 6 > input.length * 8) {
390 output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
399 * @property {String} version
408 Base64 : function () {
409 // private properties
410 var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
411 pad = '=', // default pad according with the RFC standard
412 url = false, // URL encoding support @todo
413 utf8 = true; // by default enable UTF-8 support encoding
415 // public method for encoding
416 this.encode = function (input) {
422 input = (utf8) ? utf8Encode(input) : input;
424 for (i = 0; i < len; i += 3) {
425 triplet = (input.charCodeAt(i) << 16)
426 | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
427 | (i + 2 < len ? input.charCodeAt(i+2) : 0);
428 for (j = 0; j < 4; j+=1) {
429 if (i * 8 + j * 6 > len * 8) {
432 output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
439 // public method for decoding
440 this.decode = function (input) {
441 // var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
442 var i, o1, o2, o3, h1, h2, h3, h4, bits, ac,
445 if (!input) { return input; }
448 input = input.replace(new RegExp('\\'+pad,'gi'),''); // use '='
451 do { // unpack four hexets into three octets using index points in b64
452 h1 = tab.indexOf(input.charAt(i+=1));
453 h2 = tab.indexOf(input.charAt(i+=1));
454 h3 = tab.indexOf(input.charAt(i+=1));
455 h4 = tab.indexOf(input.charAt(i+=1));
457 bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
459 o1 = bits >> 16 & 0xff;
460 o2 = bits >> 8 & 0xff;
465 arr[ac] = String.fromCharCode(o1);
466 } else if (h4 === 64) {
467 arr[ac] = String.fromCharCode(o1, o2);
469 arr[ac] = String.fromCharCode(o1, o2, o3);
471 } while (i < input.length);
474 dec = (utf8) ? utf8Decode(dec) : dec;
479 // set custom pad string
480 this.setPad = function (str) {
484 // set custom tab string characters
485 this.setTab = function (str) {
489 this.setUTF8 = function (bool) {
490 if (typeof bool === 'boolean') {
502 * @param {String} str Input String
505 CRC32 : function (str) {
506 var crc = 0, x = 0, y = 0, table, i, iTop;
507 str = utf8Encode(str);
510 '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 ',
511 '79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 ',
512 '84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F ',
513 '63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD ',
514 'A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC ',
515 '51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 ',
516 'B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 ',
517 '06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 ',
518 'E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 ',
519 '12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 ',
520 'D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 ',
521 '33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 ',
522 'CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 ',
523 '9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E ',
524 '7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D ',
525 '806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 ',
526 '60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA ',
527 'AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 ',
528 '5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 ',
529 'B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 ',
530 '05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 ',
531 'F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA ',
532 '11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 ',
533 'D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F ',
534 '30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E ',
535 'C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D'
539 for (i = 0, iTop = str.length; i < iTop; i+=1 ) {
540 y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
541 x = '0x' + table.substr( y * 9, 8 );
542 crc = ( crc >>> 8 ) ^ x;
544 // always return a positive number (that's what >>> 0 does)
545 return (crc ^ (-1)) >>> 0;
551 * @param {Object} [config]
553 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
554 * Digest Algorithm, as defined in RFC 1321.
555 * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
556 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
557 * See <http://pajhome.org.uk/crypt/md5> for more infHashes.
559 MD5 : function (options) {
561 * Private config properties. You may need to tweak these to be compatible with
562 * the server-side, but the defaults work in most cases.
563 * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
565 var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
566 b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
567 utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
569 // privileged (public) methods
570 this.hex = function (s) {
571 return rstr2hex(rstr(s, utf8), hexcase);
573 this.b64 = function (s) {
574 return rstr2b64(rstr(s), b64pad);
576 this.any = function(s, e) {
577 return rstr2any(rstr(s, utf8), e);
579 this.hex_hmac = function (k, d) {
580 return rstr2hex(rstr_hmac(k, d), hexcase);
582 this.b64_hmac = function (k, d) {
583 return rstr2b64(rstr_hmac(k,d), b64pad);
585 this.any_hmac = function (k, d, e) {
586 return rstr2any(rstr_hmac(k, d), e);
589 * Perform a simple self-test to see if the VM is working
590 * @return {String} Hexadecimal hash sample
592 this.vm_test = function () {
593 return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
596 * Enable/disable uppercase hexadecimal returned string
598 * @return {Object} this
600 this.setUpperCase = function (a) {
601 if (typeof a === 'boolean' ) {
607 * Defines a base64 pad string
608 * @param {String} Pad
609 * @return {Object} this
611 this.setPad = function (a) {
612 b64pad = a || b64pad;
616 * Defines a base64 pad string
618 * @return {Object} [this]
620 this.setUTF8 = function (a) {
621 if (typeof a === 'boolean') {
630 * Calculate the MD5 of a raw string
633 s = (utf8) ? utf8Encode(s): s;
634 return binl2rstr(binl(rstr2binl(s), s.length * 8));
638 * Calculate the HMAC-MD5, of a key and some data (raw strings)
640 function rstr_hmac(key, data) {
641 var bkey, ipad, opad, hash, i;
643 key = (utf8) ? utf8Encode(key) : key;
644 data = (utf8) ? utf8Encode(data) : data;
645 bkey = rstr2binl(key);
646 if (bkey.length > 16) {
647 bkey = binl(bkey, key.length * 8);
650 ipad = Array(16), opad = Array(16);
651 for (i = 0; i < 16; i+=1) {
652 ipad[i] = bkey[i] ^ 0x36363636;
653 opad[i] = bkey[i] ^ 0x5C5C5C5C;
655 hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
656 return binl2rstr(binl(opad.concat(hash), 512 + 128));
660 * Calculate the MD5 of an array of little-endian words, and a bit length.
662 function binl(x, len) {
663 var i, olda, oldb, oldc, oldd,
670 x[len >> 5] |= 0x80 << ((len) % 32);
671 x[(((len + 64) >>> 9) << 4) + 14] = len;
673 for (i = 0; i < x.length; i += 16) {
679 a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
680 d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
681 c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
682 b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
683 a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
684 d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
685 c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
686 b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
687 a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
688 d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
689 c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
690 b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
691 a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
692 d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
693 c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
694 b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
696 a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
697 d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
698 c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
699 b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
700 a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
701 d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
702 c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
703 b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
704 a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
705 d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
706 c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
707 b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
708 a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
709 d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
710 c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
711 b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
713 a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
714 d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
715 c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
716 b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
717 a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
718 d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
719 c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
720 b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
721 a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
722 d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
723 c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
724 b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
725 a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
726 d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
727 c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
728 b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
730 a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
731 d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
732 c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
733 b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
734 a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
735 d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
736 c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
737 b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
738 a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
739 d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
740 c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
741 b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
742 a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
743 d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
744 c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
745 b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
747 a = safe_add(a, olda);
748 b = safe_add(b, oldb);
749 c = safe_add(c, oldc);
750 d = safe_add(d, oldd);
752 return Array(a, b, c, d);
756 * These functions implement the four basic operations the algorithm uses.
758 function md5_cmn(q, a, b, x, s, t) {
759 return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
761 function md5_ff(a, b, c, d, x, s, t) {
762 return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
764 function md5_gg(a, b, c, d, x, s, t) {
765 return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
767 function md5_hh(a, b, c, d, x, s, t) {
768 return md5_cmn(b ^ c ^ d, a, b, x, s, t);
770 function md5_ii(a, b, c, d, x, s, t) {
771 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
777 * @param {Object} [config]
780 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined in FIPS 180-1
781 * Version 2.2 Copyright Paul Johnston 2000 - 2009.
782 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
783 * See http://pajhome.org.uk/crypt/md5 for details.
785 SHA1 : function (options) {
787 * Private config properties. You may need to tweak these to be compatible with
788 * the server-side, but the defaults work in most cases.
789 * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
791 var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
792 b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
793 utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
796 this.hex = function (s) {
797 return rstr2hex(rstr(s, utf8), hexcase);
799 this.b64 = function (s) {
800 return rstr2b64(rstr(s, utf8), b64pad);
802 this.any = function (s, e) {
803 return rstr2any(rstr(s, utf8), e);
805 this.hex_hmac = function (k, d) {
806 return rstr2hex(rstr_hmac(k, d));
808 this.b64_hmac = function (k, d) {
809 return rstr2b64(rstr_hmac(k, d), b64pad);
811 this.any_hmac = function (k, d, e) {
812 return rstr2any(rstr_hmac(k, d), e);
815 * Perform a simple self-test to see if the VM is working
816 * @return {String} Hexadecimal hash sample
819 this.vm_test = function () {
820 return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
823 * @description Enable/disable uppercase hexadecimal returned string
825 * @return {Object} this
828 this.setUpperCase = function (a) {
829 if (typeof a === 'boolean') {
835 * @description Defines a base64 pad string
836 * @param {string} Pad
837 * @return {Object} this
840 this.setPad = function (a) {
841 b64pad = a || b64pad;
845 * @description Defines a base64 pad string
847 * @return {Object} this
850 this.setUTF8 = function (a) {
851 if (typeof a === 'boolean') {
860 * Calculate the SHA-512 of a raw string
863 s = (utf8) ? utf8Encode(s) : s;
864 return binb2rstr(binb(rstr2binb(s), s.length * 8));
868 * Calculate the HMAC-SHA1 of a key and some data (raw strings)
870 function rstr_hmac(key, data) {
871 var bkey, ipad, opad, i, hash;
872 key = (utf8) ? utf8Encode(key) : key;
873 data = (utf8) ? utf8Encode(data) : data;
874 bkey = rstr2binb(key);
876 if (bkey.length > 16) {
877 bkey = binb(bkey, key.length * 8);
879 ipad = Array(16), opad = Array(16);
880 for (i = 0; i < 16; i+=1) {
881 ipad[i] = bkey[i] ^ 0x36363636;
882 opad[i] = bkey[i] ^ 0x5C5C5C5C;
884 hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
885 return binb2rstr(binb(opad.concat(hash), 512 + 160));
889 * Calculate the SHA-1 of an array of big-endian words, and a bit length
891 function binb(x, len) {
892 var i, j, t, olda, oldb, oldc, oldd, olde,
901 x[len >> 5] |= 0x80 << (24 - len % 32);
902 x[((len + 64 >> 9) << 4) + 15] = len;
904 for (i = 0; i < x.length; i += 16) {
911 for (j = 0; j < 80; j+=1) {
915 w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
917 t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
918 safe_add(safe_add(e, w[j]), sha1_kt(j)));
926 a = safe_add(a, olda);
927 b = safe_add(b, oldb);
928 c = safe_add(c, oldc);
929 d = safe_add(d, oldd);
930 e = safe_add(e, olde);
932 return Array(a, b, c, d, e);
936 * Perform the appropriate triplet combination function for the current
939 function sha1_ft(t, b, c, d) {
940 if (t < 20) { return (b & c) | ((~b) & d); }
941 if (t < 40) { return b ^ c ^ d; }
942 if (t < 60) { return (b & c) | (b & d) | (c & d); }
947 * Determine the appropriate additive constant for the current iteration
949 function sha1_kt(t) {
950 return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
951 (t < 60) ? -1894007588 : -899497514;
955 * @class Hashes.SHA256
958 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined in FIPS 180-2
959 * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
960 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
961 * See http://pajhome.org.uk/crypt/md5 for details.
962 * Also http://anmar.eu.org/projects/jssha2/
964 SHA256 : function (options) {
966 * Private properties configuration variables. You may need to tweak these to be compatible with
967 * the server-side, but the defaults work in most cases.
968 * @see this.setUpperCase() method
969 * @see this.setPad() method
971 var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase */
972 b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', /* base-64 pad character. Default '=' for strict RFC compliance */
973 utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
976 /* privileged (public) methods */
977 this.hex = function (s) {
978 return rstr2hex(rstr(s, utf8));
980 this.b64 = function (s) {
981 return rstr2b64(rstr(s, utf8), b64pad);
983 this.any = function (s, e) {
984 return rstr2any(rstr(s, utf8), e);
986 this.hex_hmac = function (k, d) {
987 return rstr2hex(rstr_hmac(k, d));
989 this.b64_hmac = function (k, d) {
990 return rstr2b64(rstr_hmac(k, d), b64pad);
992 this.any_hmac = function (k, d, e) {
993 return rstr2any(rstr_hmac(k, d), e);
996 * Perform a simple self-test to see if the VM is working
997 * @return {String} Hexadecimal hash sample
1000 this.vm_test = function () {
1001 return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1004 * Enable/disable uppercase hexadecimal returned string
1006 * @return {Object} this
1009 this.setUpperCase = function (a) {
1010 if (typeof a === 'boolean') {
1016 * @description Defines a base64 pad string
1017 * @param {string} Pad
1018 * @return {Object} this
1021 this.setPad = function (a) {
1022 b64pad = a || b64pad;
1026 * Defines a base64 pad string
1028 * @return {Object} this
1031 this.setUTF8 = function (a) {
1032 if (typeof a === 'boolean') {
1041 * Calculate the SHA-512 of a raw string
1043 function rstr(s, utf8) {
1044 s = (utf8) ? utf8Encode(s) : s;
1045 return binb2rstr(binb(rstr2binb(s), s.length * 8));
1049 * Calculate the HMAC-sha256 of a key and some data (raw strings)
1051 function rstr_hmac(key, data) {
1052 key = (utf8) ? utf8Encode(key) : key;
1053 data = (utf8) ? utf8Encode(data) : data;
1055 bkey = rstr2binb(key),
1059 if (bkey.length > 16) { bkey = binb(bkey, key.length * 8); }
1061 for (; i < 16; i+=1) {
1062 ipad[i] = bkey[i] ^ 0x36363636;
1063 opad[i] = bkey[i] ^ 0x5C5C5C5C;
1066 hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
1067 return binb2rstr(binb(opad.concat(hash), 512 + 256));
1071 * Main sha256 function, with its support functions
1073 function sha256_S (X, n) {return ( X >>> n ) | (X << (32 - n));}
1074 function sha256_R (X, n) {return ( X >>> n );}
1075 function sha256_Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}
1076 function sha256_Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}
1077 function sha256_Sigma0256(x) {return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));}
1078 function sha256_Sigma1256(x) {return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));}
1079 function sha256_Gamma0256(x) {return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));}
1080 function sha256_Gamma1256(x) {return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));}
1081 function sha256_Sigma0512(x) {return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39));}
1082 function sha256_Sigma1512(x) {return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));}
1083 function sha256_Gamma0512(x) {return (sha256_S(x, 1) ^ sha256_S(x, 8) ^ sha256_R(x, 7));}
1084 function sha256_Gamma1512(x) {return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));}
1087 1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,
1088 -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,
1089 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,
1090 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,
1091 -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,
1092 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,
1093 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885,
1094 -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,
1095 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,
1096 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,
1097 -1866530822, -1538233109, -1090935817, -965641998
1100 function binb(m, l) {
1101 var HASH = [1779033703, -1150833019, 1013904242, -1521486534,
1102 1359893119, -1694144372, 528734635, 1541459225];
1103 var W = new Array(64);
1104 var a, b, c, d, e, f, g, h;
1107 /* append padding */
1108 m[l >> 5] |= 0x80 << (24 - l % 32);
1109 m[((l + 64 >> 9) << 4) + 15] = l;
1111 for (i = 0; i < m.length; i += 16)
1122 for (j = 0; j < 64; j+=1)
1127 W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),
1128 sha256_Gamma0256(W[j - 15])), W[j - 16]);
1131 T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),
1132 sha256_K[j]), W[j]);
1133 T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
1137 e = safe_add(d, T1);
1141 a = safe_add(T1, T2);
1144 HASH[0] = safe_add(a, HASH[0]);
1145 HASH[1] = safe_add(b, HASH[1]);
1146 HASH[2] = safe_add(c, HASH[2]);
1147 HASH[3] = safe_add(d, HASH[3]);
1148 HASH[4] = safe_add(e, HASH[4]);
1149 HASH[5] = safe_add(f, HASH[5]);
1150 HASH[6] = safe_add(g, HASH[6]);
1151 HASH[7] = safe_add(h, HASH[7]);
1159 * @class Hashes.SHA512
1162 * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined in FIPS 180-2
1163 * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.
1164 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
1165 * See http://pajhome.org.uk/crypt/md5 for details.
1167 SHA512 : function (options) {
1169 * Private properties configuration variables. You may need to tweak these to be compatible with
1170 * the server-side, but the defaults work in most cases.
1171 * @see this.setUpperCase() method
1172 * @see this.setPad() method
1174 var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false , /* hexadecimal output case format. false - lowercase; true - uppercase */
1175 b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', /* base-64 pad character. Default '=' for strict RFC compliance */
1176 utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
1179 /* privileged (public) methods */
1180 this.hex = function (s) {
1181 return rstr2hex(rstr(s));
1183 this.b64 = function (s) {
1184 return rstr2b64(rstr(s), b64pad);
1186 this.any = function (s, e) {
1187 return rstr2any(rstr(s), e);
1189 this.hex_hmac = function (k, d) {
1190 return rstr2hex(rstr_hmac(k, d));
1192 this.b64_hmac = function (k, d) {
1193 return rstr2b64(rstr_hmac(k, d), b64pad);
1195 this.any_hmac = function (k, d, e) {
1196 return rstr2any(rstr_hmac(k, d), e);
1199 * Perform a simple self-test to see if the VM is working
1200 * @return {String} Hexadecimal hash sample
1203 this.vm_test = function () {
1204 return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1207 * @description Enable/disable uppercase hexadecimal returned string
1209 * @return {Object} this
1212 this.setUpperCase = function (a) {
1213 if (typeof a === 'boolean') {
1219 * @description Defines a base64 pad string
1220 * @param {string} Pad
1221 * @return {Object} this
1224 this.setPad = function (a) {
1225 b64pad = a || b64pad;
1229 * @description Defines a base64 pad string
1231 * @return {Object} this
1234 this.setUTF8 = function (a) {
1235 if (typeof a === 'boolean') {
1241 /* private methods */
1244 * Calculate the SHA-512 of a raw string
1247 s = (utf8) ? utf8Encode(s) : s;
1248 return binb2rstr(binb(rstr2binb(s), s.length * 8));
1251 * Calculate the HMAC-SHA-512 of a key and some data (raw strings)
1253 function rstr_hmac(key, data) {
1254 key = (utf8) ? utf8Encode(key) : key;
1255 data = (utf8) ? utf8Encode(data) : data;
1258 bkey = rstr2binb(key),
1259 ipad = Array(32), opad = Array(32);
1261 if (bkey.length > 32) { bkey = binb(bkey, key.length * 8); }
1263 for (; i < 32; i+=1) {
1264 ipad[i] = bkey[i] ^ 0x36363636;
1265 opad[i] = bkey[i] ^ 0x5C5C5C5C;
1268 hash = binb(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);
1269 return binb2rstr(binb(opad.concat(hash), 1024 + 512));
1273 * Calculate the SHA-512 of an array of big-endian dwords, and a bit length
1275 function binb(x, len) {
1278 hash = new Array(16),
1279 //Initial hash values
1281 new int64(0x6a09e667, -205731576),
1282 new int64(-1150833019, -2067093701),
1283 new int64(0x3c6ef372, -23791573),
1284 new int64(-1521486534, 0x5f1d36f1),
1285 new int64(0x510e527f, -1377402159),
1286 new int64(-1694144372, 0x2b3e6c1f),
1287 new int64(0x1f83d9ab, -79577749),
1288 new int64(0x5be0cd19, 0x137e2179)
1290 T1 = new int64(0, 0),
1291 T2 = new int64(0, 0),
1300 //Temporary variables not specified by the document
1301 s0 = new int64(0, 0),
1302 s1 = new int64(0, 0),
1303 Ch = new int64(0, 0),
1304 Maj = new int64(0, 0),
1305 r1 = new int64(0, 0),
1306 r2 = new int64(0, 0),
1307 r3 = new int64(0, 0);
1309 if (sha512_k === undefined) {
1312 new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),
1313 new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),
1314 new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),
1315 new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),
1316 new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),
1317 new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),
1318 new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),
1319 new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),
1320 new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),
1321 new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),
1322 new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),
1323 new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),
1324 new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),
1325 new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),
1326 new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),
1327 new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),
1328 new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),
1329 new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),
1330 new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),
1331 new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),
1332 new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),
1333 new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),
1334 new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),
1335 new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),
1336 new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),
1337 new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),
1338 new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),
1339 new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),
1340 new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),
1341 new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),
1342 new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),
1343 new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),
1344 new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),
1345 new int64(-354779690, -840897762), new int64(-176337025, -294727304),
1346 new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),
1347 new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),
1348 new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),
1349 new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),
1350 new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),
1351 new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817)
1355 for (i=0; i<80; i+=1) {
1356 W[i] = new int64(0, 0);
1359 // append padding to the source string. The format is described in the FIPS.
1360 x[len >> 5] |= 0x80 << (24 - (len & 0x1f));
1361 x[((len + 128 >> 10)<< 5) + 31] = len;
1363 for (i = 0; i<l; i+=32) { //32 dwords is the block size
1373 for (j=0; j<16; j+=1) {
1374 W[j].h = x[i + 2*j];
1375 W[j].l = x[i + 2*j + 1];
1378 for (j=16; j<80; j+=1) {
1380 int64rrot(r1, W[j-2], 19);
1381 int64revrrot(r2, W[j-2], 29);
1382 int64shr(r3, W[j-2], 6);
1383 s1.l = r1.l ^ r2.l ^ r3.l;
1384 s1.h = r1.h ^ r2.h ^ r3.h;
1386 int64rrot(r1, W[j-15], 1);
1387 int64rrot(r2, W[j-15], 8);
1388 int64shr(r3, W[j-15], 7);
1389 s0.l = r1.l ^ r2.l ^ r3.l;
1390 s0.h = r1.h ^ r2.h ^ r3.h;
1392 int64add4(W[j], s1, W[j-7], s0, W[j-16]);
1395 for (j = 0; j < 80; j+=1) {
1397 Ch.l = (e.l & f.l) ^ (~e.l & g.l);
1398 Ch.h = (e.h & f.h) ^ (~e.h & g.h);
1401 int64rrot(r1, e, 14);
1402 int64rrot(r2, e, 18);
1403 int64revrrot(r3, e, 9);
1404 s1.l = r1.l ^ r2.l ^ r3.l;
1405 s1.h = r1.h ^ r2.h ^ r3.h;
1408 int64rrot(r1, a, 28);
1409 int64revrrot(r2, a, 2);
1410 int64revrrot(r3, a, 7);
1411 s0.l = r1.l ^ r2.l ^ r3.l;
1412 s0.h = r1.h ^ r2.h ^ r3.h;
1415 Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);
1416 Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);
1418 int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);
1419 int64add(T2, s0, Maj);
1428 int64add(a, T1, T2);
1430 int64add(H[0], H[0], a);
1431 int64add(H[1], H[1], b);
1432 int64add(H[2], H[2], c);
1433 int64add(H[3], H[3], d);
1434 int64add(H[4], H[4], e);
1435 int64add(H[5], H[5], f);
1436 int64add(H[6], H[6], g);
1437 int64add(H[7], H[7], h);
1440 //represent the hash as an array of 32-bit dwords
1441 for (i=0; i<8; i+=1) {
1443 hash[2*i + 1] = H[i].l;
1448 //A constructor for 64-bit numbers
1449 function int64(h, l) {
1452 //this.toString = int64toString;
1455 //Copies src into dst, assuming both are 64-bit numbers
1456 function int64copy(dst, src) {
1461 //Right-rotates a 64-bit number by shift
1462 //Won't handle cases of shift>=32
1463 //The function revrrot() is for that
1464 function int64rrot(dst, x, shift) {
1465 dst.l = (x.l >>> shift) | (x.h << (32-shift));
1466 dst.h = (x.h >>> shift) | (x.l << (32-shift));
1469 //Reverses the dwords of the source and then rotates right by shift.
1470 //This is equivalent to rotation by 32+shift
1471 function int64revrrot(dst, x, shift) {
1472 dst.l = (x.h >>> shift) | (x.l << (32-shift));
1473 dst.h = (x.l >>> shift) | (x.h << (32-shift));
1476 //Bitwise-shifts right a 64-bit number by shift
1477 //Won't handle shift>=32, but it's never needed in SHA512
1478 function int64shr(dst, x, shift) {
1479 dst.l = (x.l >>> shift) | (x.h << (32-shift));
1480 dst.h = (x.h >>> shift);
1483 //Adds two 64-bit numbers
1484 //Like the original implementation, does not rely on 32-bit operations
1485 function int64add(dst, x, y) {
1486 var w0 = (x.l & 0xffff) + (y.l & 0xffff);
1487 var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);
1488 var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);
1489 var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);
1490 dst.l = (w0 & 0xffff) | (w1 << 16);
1491 dst.h = (w2 & 0xffff) | (w3 << 16);
1494 //Same, except with 4 addends. Works faster than adding them one by one.
1495 function int64add4(dst, a, b, c, d) {
1496 var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);
1497 var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);
1498 var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);
1499 var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);
1500 dst.l = (w0 & 0xffff) | (w1 << 16);
1501 dst.h = (w2 & 0xffff) | (w3 << 16);
1504 //Same, except with 5 addends
1505 function int64add5(dst, a, b, c, d, e) {
1506 var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff),
1507 w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16),
1508 w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16),
1509 w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);
1510 dst.l = (w0 & 0xffff) | (w1 << 16);
1511 dst.h = (w2 & 0xffff) | (w3 << 16);
1515 * @class Hashes.RMD160
1517 * @param {Object} [config]
1519 * A JavaScript implementation of the RIPEMD-160 Algorithm
1520 * Version 2.2 Copyright Jeremy Lin, Paul Johnston 2000 - 2009.
1521 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
1522 * See http://pajhome.org.uk/crypt/md5 for details.
1523 * Also http://www.ocf.berkeley.edu/~jjlin/jsotp/
1525 RMD160 : function (options) {
1527 * Private properties configuration variables. You may need to tweak these to be compatible with
1528 * the server-side, but the defaults work in most cases.
1529 * @see this.setUpperCase() method
1530 * @see this.setPad() method
1532 var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, /* hexadecimal output case format. false - lowercase; true - uppercase */
1533 b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', /* base-64 pad character. Default '=' for strict RFC compliance */
1534 utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
1536 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
1537 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
1538 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
1539 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
1540 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
1543 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
1544 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
1545 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
1546 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
1547 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
1550 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
1551 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
1552 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
1553 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
1554 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
1557 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
1558 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
1559 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
1560 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
1561 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
1564 /* privileged (public) methods */
1565 this.hex = function (s) {
1566 return rstr2hex(rstr(s, utf8));
1568 this.b64 = function (s) {
1569 return rstr2b64(rstr(s, utf8), b64pad);
1571 this.any = function (s, e) {
1572 return rstr2any(rstr(s, utf8), e);
1574 this.hex_hmac = function (k, d) {
1575 return rstr2hex(rstr_hmac(k, d));
1577 this.b64_hmac = function (k, d) {
1578 return rstr2b64(rstr_hmac(k, d), b64pad);
1580 this.any_hmac = function (k, d, e) {
1581 return rstr2any(rstr_hmac(k, d), e);
1584 * Perform a simple self-test to see if the VM is working
1585 * @return {String} Hexadecimal hash sample
1588 this.vm_test = function () {
1589 return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1592 * @description Enable/disable uppercase hexadecimal returned string
1594 * @return {Object} this
1597 this.setUpperCase = function (a) {
1598 if (typeof a === 'boolean' ) { hexcase = a; }
1602 * @description Defines a base64 pad string
1603 * @param {string} Pad
1604 * @return {Object} this
1607 this.setPad = function (a) {
1608 if (typeof a !== 'undefined' ) { b64pad = a; }
1612 * @description Defines a base64 pad string
1614 * @return {Object} this
1617 this.setUTF8 = function (a) {
1618 if (typeof a === 'boolean') { utf8 = a; }
1622 /* private methods */
1625 * Calculate the rmd160 of a raw string
1628 s = (utf8) ? utf8Encode(s) : s;
1629 return binl2rstr(binl(rstr2binl(s), s.length * 8));
1633 * Calculate the HMAC-rmd160 of a key and some data (raw strings)
1635 function rstr_hmac(key, data) {
1636 key = (utf8) ? utf8Encode(key) : key;
1637 data = (utf8) ? utf8Encode(data) : data;
1639 bkey = rstr2binl(key),
1640 ipad = Array(16), opad = Array(16);
1642 if (bkey.length > 16) {
1643 bkey = binl(bkey, key.length * 8);
1646 for (i = 0; i < 16; i+=1) {
1647 ipad[i] = bkey[i] ^ 0x36363636;
1648 opad[i] = bkey[i] ^ 0x5C5C5C5C;
1650 hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
1651 return binl2rstr(binl(opad.concat(hash), 512 + 160));
1655 * Convert an array of little-endian words to a string
1657 function binl2rstr(input) {
1658 var i, output = '', l = input.length * 32;
1659 for (i = 0; i < l; i += 8) {
1660 output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
1666 * Calculate the RIPE-MD160 of an array of little-endian words, and a bit length.
1668 function binl(x, len) {
1678 /* append padding */
1679 x[len >> 5] |= 0x80 << (len % 32);
1680 x[(((len + 64) >>> 9) << 4) + 14] = len;
1683 for (i = 0; i < l; i+=16) {
1684 A1 = A2 = h0; B1 = B2 = h1; C1 = C2 = h2; D1 = D2 = h3; E1 = E2 = h4;
1685 for (j = 0; j <= 79; j+=1) {
1686 T = safe_add(A1, rmd160_f(j, B1, C1, D1));
1687 T = safe_add(T, x[i + rmd160_r1[j]]);
1688 T = safe_add(T, rmd160_K1(j));
1689 T = safe_add(bit_rol(T, rmd160_s1[j]), E1);
1690 A1 = E1; E1 = D1; D1 = bit_rol(C1, 10); C1 = B1; B1 = T;
1691 T = safe_add(A2, rmd160_f(79-j, B2, C2, D2));
1692 T = safe_add(T, x[i + rmd160_r2[j]]);
1693 T = safe_add(T, rmd160_K2(j));
1694 T = safe_add(bit_rol(T, rmd160_s2[j]), E2);
1695 A2 = E2; E2 = D2; D2 = bit_rol(C2, 10); C2 = B2; B2 = T;
1698 T = safe_add(h1, safe_add(C1, D2));
1699 h1 = safe_add(h2, safe_add(D1, E2));
1700 h2 = safe_add(h3, safe_add(E1, A2));
1701 h3 = safe_add(h4, safe_add(A1, B2));
1702 h4 = safe_add(h0, safe_add(B1, C2));
1705 return [h0, h1, h2, h3, h4];
1708 // specific algorithm methods
1709 function rmd160_f(j, x, y, z) {
1710 return ( 0 <= j && j <= 15) ? (x ^ y ^ z) :
1711 (16 <= j && j <= 31) ? (x & y) | (~x & z) :
1712 (32 <= j && j <= 47) ? (x | ~y) ^ z :
1713 (48 <= j && j <= 63) ? (x & z) | (y & ~z) :
1714 (64 <= j && j <= 79) ? x ^ (y | ~z) :
1715 'rmd160_f: j out of range';
1718 function rmd160_K1(j) {
1719 return ( 0 <= j && j <= 15) ? 0x00000000 :
1720 (16 <= j && j <= 31) ? 0x5a827999 :
1721 (32 <= j && j <= 47) ? 0x6ed9eba1 :
1722 (48 <= j && j <= 63) ? 0x8f1bbcdc :
1723 (64 <= j && j <= 79) ? 0xa953fd4e :
1724 'rmd160_K1: j out of range';
1727 function rmd160_K2(j){
1728 return ( 0 <= j && j <= 15) ? 0x50a28be6 :
1729 (16 <= j && j <= 31) ? 0x5c4dd124 :
1730 (32 <= j && j <= 47) ? 0x6d703ef3 :
1731 (48 <= j && j <= 63) ? 0x7a6d76e9 :
1732 (64 <= j && j <= 79) ? 0x00000000 :
1733 'rmd160_K2: j out of range';
1739 (function( window, undefined ) {
1740 var freeExports = false;
1741 if (typeof exports === 'object' ) {
1742 freeExports = exports;
1743 if (exports && typeof global === 'object' && global && global === global.global ) { window = global; }
1746 if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
1747 // define as an anonymous module, so, through path mapping, it can be aliased
1748 define(function () { return Hashes; });
1750 else if ( freeExports ) {
1751 // in Node.js or RingoJS v0.8.0+
1752 if ( typeof module === 'object' && module && module.exports === freeExports ) {
1753 module.exports = Hashes;
1755 // in Narwhal or RingoJS v0.7.0-
1757 freeExports.Hashes = Hashes;
1761 // in a browser or Rhino
1762 window.Hashes = Hashes;
1767 },{}],4:[function(require,module,exports){
1768 module.exports = hasKeys
1770 function hasKeys(source) {
1771 return source !== null &&
1772 (typeof source === "object" ||
1773 typeof source === "function")
1776 },{}],3:[function(require,module,exports){
1777 var Keys = require("object-keys")
1778 var hasKeys = require("./has-keys")
1780 module.exports = extend
1785 for (var i = 0; i < arguments.length; i++) {
1786 var source = arguments[i]
1788 if (!hasKeys(source)) {
1792 var keys = Keys(source)
1794 for (var j = 0; j < keys.length; j++) {
1796 target[name] = source[name]
1803 },{"./has-keys":4,"object-keys":5}],5:[function(require,module,exports){
1804 module.exports = Object.keys || require('./shim');
1807 },{"./shim":6}],6:[function(require,module,exports){
1811 // modified from https://github.com/kriskowal/es5-shim
1812 var has = Object.prototype.hasOwnProperty,
1814 forEach = require('foreach'),
1815 hasDontEnumBug = !({'toString': null}).propertyIsEnumerable('toString'),
1822 "propertyIsEnumerable",
1827 keysShim = function keys(object) {
1828 if (!is.object(object) && !is.array(object)) {
1829 throw new TypeError("Object.keys called on a non-object");
1832 var name, theKeys = [];
1833 for (name in object) {
1834 if (has.call(object, name)) {
1839 if (hasDontEnumBug) {
1840 forEach(dontEnums, function (dontEnum) {
1841 if (has.call(object, dontEnum)) {
1842 theKeys.push(dontEnum);
1849 module.exports = keysShim;
1853 },{"is":7,"foreach":8}],7:[function(require,module,exports){
1857 * the definitive JavaScript type testing library
1859 * @copyright 2013 Enrico Marino
1863 var objProto = Object.prototype;
1864 var owns = objProto.hasOwnProperty;
1865 var toString = objProto.toString;
1866 var isActualNaN = function (value) {
1867 return value !== value;
1869 var NON_HOST_TYPES = {
1880 var is = module.exports = {};
1888 * Test if `value` is a type of `type`.
1890 * @param {Mixed} value value to test
1891 * @param {String} type type
1892 * @return {Boolean} true if `value` is a type of `type`, false otherwise
1897 is.type = function (value, type) {
1898 return typeof value === type;
1903 * Test if `value` is defined.
1905 * @param {Mixed} value value to test
1906 * @return {Boolean} true if 'value' is defined, false otherwise
1910 is.defined = function (value) {
1911 return value !== undefined;
1916 * Test if `value` is empty.
1918 * @param {Mixed} value value to test
1919 * @return {Boolean} true if `value` is empty, false otherwise
1923 is.empty = function (value) {
1924 var type = toString.call(value);
1927 if ('[object Array]' === type || '[object Arguments]' === type) {
1928 return value.length === 0;
1931 if ('[object Object]' === type) {
1932 for (key in value) if (owns.call(value, key)) return false;
1936 if ('[object String]' === type) {
1937 return '' === value;
1945 * Test if `value` is equal to `other`.
1947 * @param {Mixed} value value to test
1948 * @param {Mixed} other value to compare with
1949 * @return {Boolean} true if `value` is equal to `other`, false otherwise
1952 is.equal = function (value, other) {
1953 var type = toString.call(value)
1956 if (type !== toString.call(other)) {
1960 if ('[object Object]' === type) {
1961 for (key in value) {
1962 if (!is.equal(value[key], other[key])) {
1969 if ('[object Array]' === type) {
1971 if (key !== other.length) {
1975 if (!is.equal(value[key], other[key])) {
1982 if ('[object Function]' === type) {
1983 return value.prototype === other.prototype;
1986 if ('[object Date]' === type) {
1987 return value.getTime() === other.getTime();
1990 return value === other;
1995 * Test if `value` is hosted by `host`.
1997 * @param {Mixed} value to test
1998 * @param {Mixed} host host to test with
1999 * @return {Boolean} true if `value` is hosted by `host`, false otherwise
2003 is.hosted = function (value, host) {
2004 var type = typeof host[value];
2005 return type === 'object' ? !!host[value] : !NON_HOST_TYPES[type];
2010 * Test if `value` is an instance of `constructor`.
2012 * @param {Mixed} value value to test
2013 * @return {Boolean} true if `value` is an instance of `constructor`
2017 is.instance = is['instanceof'] = function (value, constructor) {
2018 return value instanceof constructor;
2023 * Test if `value` is null.
2025 * @param {Mixed} value value to test
2026 * @return {Boolean} true if `value` is null, false otherwise
2030 is['null'] = function (value) {
2031 return value === null;
2036 * Test if `value` is undefined.
2038 * @param {Mixed} value value to test
2039 * @return {Boolean} true if `value` is undefined, false otherwise
2043 is.undefined = function (value) {
2044 return value === undefined;
2053 * Test if `value` is an arguments object.
2055 * @param {Mixed} value value to test
2056 * @return {Boolean} true if `value` is an arguments object, false otherwise
2060 is.arguments = function (value) {
2061 var isStandardArguments = '[object Arguments]' === toString.call(value);
2062 var isOldArguments = !is.array(value) && is.arraylike(value) && is.object(value) && is.fn(value.callee);
2063 return isStandardArguments || isOldArguments;
2072 * Test if 'value' is an array.
2074 * @param {Mixed} value value to test
2075 * @return {Boolean} true if `value` is an array, false otherwise
2079 is.array = function (value) {
2080 return '[object Array]' === toString.call(value);
2084 * is.arguments.empty
2085 * Test if `value` is an empty arguments object.
2087 * @param {Mixed} value value to test
2088 * @return {Boolean} true if `value` is an empty arguments object, false otherwise
2091 is.arguments.empty = function (value) {
2092 return is.arguments(value) && value.length === 0;
2097 * Test if `value` is an empty array.
2099 * @param {Mixed} value value to test
2100 * @return {Boolean} true if `value` is an empty array, false otherwise
2103 is.array.empty = function (value) {
2104 return is.array(value) && value.length === 0;
2109 * Test if `value` is an arraylike object.
2111 * @param {Mixed} value value to test
2112 * @return {Boolean} true if `value` is an arguments object, false otherwise
2116 is.arraylike = function (value) {
2117 return !!value && !is.boolean(value)
2118 && owns.call(value, 'length')
2119 && isFinite(value.length)
2120 && is.number(value.length)
2121 && value.length >= 0;
2130 * Test if `value` is a boolean.
2132 * @param {Mixed} value value to test
2133 * @return {Boolean} true if `value` is a boolean, false otherwise
2137 is.boolean = function (value) {
2138 return '[object Boolean]' === toString.call(value);
2143 * Test if `value` is false.
2145 * @param {Mixed} value value to test
2146 * @return {Boolean} true if `value` is false, false otherwise
2150 is['false'] = function (value) {
2151 return is.boolean(value) && (value === false || value.valueOf() === false);
2156 * Test if `value` is true.
2158 * @param {Mixed} value value to test
2159 * @return {Boolean} true if `value` is true, false otherwise
2163 is['true'] = function (value) {
2164 return is.boolean(value) && (value === true || value.valueOf() === true);
2173 * Test if `value` is a date.
2175 * @param {Mixed} value value to test
2176 * @return {Boolean} true if `value` is a date, false otherwise
2180 is.date = function (value) {
2181 return '[object Date]' === toString.call(value);
2190 * Test if `value` is an html element.
2192 * @param {Mixed} value value to test
2193 * @return {Boolean} true if `value` is an HTML Element, false otherwise
2197 is.element = function (value) {
2198 return value !== undefined
2199 && typeof HTMLElement !== 'undefined'
2200 && value instanceof HTMLElement
2201 && value.nodeType === 1;
2210 * Test if `value` is an error object.
2212 * @param {Mixed} value value to test
2213 * @return {Boolean} true if `value` is an error object, false otherwise
2217 is.error = function (value) {
2218 return '[object Error]' === toString.call(value);
2226 * is.fn / is.function (deprecated)
2227 * Test if `value` is a function.
2229 * @param {Mixed} value value to test
2230 * @return {Boolean} true if `value` is a function, false otherwise
2234 is.fn = is['function'] = function (value) {
2235 var isAlert = typeof window !== 'undefined' && value === window.alert;
2236 return isAlert || '[object Function]' === toString.call(value);
2245 * Test if `value` is a number.
2247 * @param {Mixed} value value to test
2248 * @return {Boolean} true if `value` is a number, false otherwise
2252 is.number = function (value) {
2253 return '[object Number]' === toString.call(value);
2258 * Test if `value` is positive or negative infinity.
2260 * @param {Mixed} value value to test
2261 * @return {Boolean} true if `value` is positive or negative Infinity, false otherwise
2264 is.infinite = function (value) {
2265 return value === Infinity || value === -Infinity;
2270 * Test if `value` is a decimal number.
2272 * @param {Mixed} value value to test
2273 * @return {Boolean} true if `value` is a decimal number, false otherwise
2277 is.decimal = function (value) {
2278 return is.number(value) && !isActualNaN(value) && value % 1 !== 0;
2283 * Test if `value` is divisible by `n`.
2285 * @param {Number} value value to test
2286 * @param {Number} n dividend
2287 * @return {Boolean} true if `value` is divisible by `n`, false otherwise
2291 is.divisibleBy = function (value, n) {
2292 var isDividendInfinite = is.infinite(value);
2293 var isDivisorInfinite = is.infinite(n);
2294 var isNonZeroNumber = is.number(value) && !isActualNaN(value) && is.number(n) && !isActualNaN(n) && n !== 0;
2295 return isDividendInfinite || isDivisorInfinite || (isNonZeroNumber && value % n === 0);
2300 * Test if `value` is an integer.
2302 * @param value to test
2303 * @return {Boolean} true if `value` is an integer, false otherwise
2307 is.int = function (value) {
2308 return is.number(value) && !isActualNaN(value) && value % 1 === 0;
2313 * Test if `value` is greater than 'others' values.
2315 * @param {Number} value value to test
2316 * @param {Array} others values to compare with
2317 * @return {Boolean} true if `value` is greater than `others` values
2321 is.maximum = function (value, others) {
2322 if (isActualNaN(value)) {
2323 throw new TypeError('NaN is not a valid value');
2324 } else if (!is.arraylike(others)) {
2325 throw new TypeError('second argument must be array-like');
2327 var len = others.length;
2329 while (--len >= 0) {
2330 if (value < others[len]) {
2340 * Test if `value` is less than `others` values.
2342 * @param {Number} value value to test
2343 * @param {Array} others values to compare with
2344 * @return {Boolean} true if `value` is less than `others` values
2348 is.minimum = function (value, others) {
2349 if (isActualNaN(value)) {
2350 throw new TypeError('NaN is not a valid value');
2351 } else if (!is.arraylike(others)) {
2352 throw new TypeError('second argument must be array-like');
2354 var len = others.length;
2356 while (--len >= 0) {
2357 if (value > others[len]) {
2367 * Test if `value` is not a number.
2369 * @param {Mixed} value value to test
2370 * @return {Boolean} true if `value` is not a number, false otherwise
2374 is.nan = function (value) {
2375 return !is.number(value) || value !== value;
2380 * Test if `value` is an even number.
2382 * @param {Number} value value to test
2383 * @return {Boolean} true if `value` is an even number, false otherwise
2387 is.even = function (value) {
2388 return is.infinite(value) || (is.number(value) && value === value && value % 2 === 0);
2393 * Test if `value` is an odd number.
2395 * @param {Number} value value to test
2396 * @return {Boolean} true if `value` is an odd number, false otherwise
2400 is.odd = function (value) {
2401 return is.infinite(value) || (is.number(value) && value === value && value % 2 !== 0);
2406 * Test if `value` is greater than or equal to `other`.
2408 * @param {Number} value value to test
2409 * @param {Number} other value to compare with
2414 is.ge = function (value, other) {
2415 if (isActualNaN(value) || isActualNaN(other)) {
2416 throw new TypeError('NaN is not a valid value');
2418 return !is.infinite(value) && !is.infinite(other) && value >= other;
2423 * Test if `value` is greater than `other`.
2425 * @param {Number} value value to test
2426 * @param {Number} other value to compare with
2431 is.gt = function (value, other) {
2432 if (isActualNaN(value) || isActualNaN(other)) {
2433 throw new TypeError('NaN is not a valid value');
2435 return !is.infinite(value) && !is.infinite(other) && value > other;
2440 * Test if `value` is less than or equal to `other`.
2442 * @param {Number} value value to test
2443 * @param {Number} other value to compare with
2444 * @return {Boolean} if 'value' is less than or equal to 'other'
2448 is.le = function (value, other) {
2449 if (isActualNaN(value) || isActualNaN(other)) {
2450 throw new TypeError('NaN is not a valid value');
2452 return !is.infinite(value) && !is.infinite(other) && value <= other;
2457 * Test if `value` is less than `other`.
2459 * @param {Number} value value to test
2460 * @param {Number} other value to compare with
2461 * @return {Boolean} if `value` is less than `other`
2465 is.lt = function (value, other) {
2466 if (isActualNaN(value) || isActualNaN(other)) {
2467 throw new TypeError('NaN is not a valid value');
2469 return !is.infinite(value) && !is.infinite(other) && value < other;
2474 * Test if `value` is within `start` and `finish`.
2476 * @param {Number} value value to test
2477 * @param {Number} start lower bound
2478 * @param {Number} finish upper bound
2479 * @return {Boolean} true if 'value' is is within 'start' and 'finish'
2482 is.within = function (value, start, finish) {
2483 if (isActualNaN(value) || isActualNaN(start) || isActualNaN(finish)) {
2484 throw new TypeError('NaN is not a valid value');
2485 } else if (!is.number(value) || !is.number(start) || !is.number(finish)) {
2486 throw new TypeError('all arguments must be numbers');
2488 var isAnyInfinite = is.infinite(value) || is.infinite(start) || is.infinite(finish);
2489 return isAnyInfinite || (value >= start && value <= finish);
2498 * Test if `value` is an object.
2500 * @param {Mixed} value value to test
2501 * @return {Boolean} true if `value` is an object, false otherwise
2505 is.object = function (value) {
2506 return value && '[object Object]' === toString.call(value);
2511 * Test if `value` is a hash - a plain object literal.
2513 * @param {Mixed} value value to test
2514 * @return {Boolean} true if `value` is a hash, false otherwise
2518 is.hash = function (value) {
2519 return is.object(value) && value.constructor === Object && !value.nodeType && !value.setInterval;
2528 * Test if `value` is a regular expression.
2530 * @param {Mixed} value value to test
2531 * @return {Boolean} true if `value` is a regexp, false otherwise
2535 is.regexp = function (value) {
2536 return '[object RegExp]' === toString.call(value);
2545 * Test if `value` is a string.
2547 * @param {Mixed} value value to test
2548 * @return {Boolean} true if 'value' is a string, false otherwise
2552 is.string = function (value) {
2553 return '[object String]' === toString.call(value);
2557 },{}],8:[function(require,module,exports){
2559 var hasOwn = Object.prototype.hasOwnProperty;
2561 module.exports = function forEach (obj, fn, ctx) {
2562 if (typeof fn !== 'function') {
2563 throw new TypeError('iterator must be a function');
2567 for (var i = 0; i < l; i++) {
2568 fn.call(ctx, obj[i], i, obj);
2571 for (var k in obj) {
2572 if (hasOwn.call(obj, k)) {
2573 fn.call(ctx, obj[k], k, obj);