mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 23:14:47 +02:00
Handle situation when user closes oauth dialog window (closes #2858)
This commit is contained in:
+6
-2
@@ -307,8 +307,12 @@ iD.modes.Save = function(context) {
|
||||
};
|
||||
|
||||
mode.enter = function() {
|
||||
context.connection().authenticate(function() {
|
||||
context.ui().sidebar.show(ui);
|
||||
context.connection().authenticate(function(err) {
|
||||
if (err) {
|
||||
cancel();
|
||||
} else {
|
||||
context.ui().sidebar.show(ui);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+204
-189
@@ -36,7 +36,8 @@ module.exports = function(o) {
|
||||
|
||||
// ## Getting a request token
|
||||
var params = timenonce(getAuth(o)),
|
||||
url = o.url + '/oauth/request_token';
|
||||
url = o.url + '/oauth/request_token',
|
||||
timer;
|
||||
|
||||
params.oauth_signature = ohauth.signature(
|
||||
o.oauth_secret, '',
|
||||
@@ -52,6 +53,15 @@ module.exports = function(o) {
|
||||
return x.join('=');
|
||||
}).join(','),
|
||||
popup = window.open('about:blank', 'oauth_window', settings);
|
||||
|
||||
|
||||
timer = setInterval(function() {
|
||||
if (popup.closed) {
|
||||
o.done();
|
||||
clearInterval(timer);
|
||||
callback('not authenticated', null);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// Request a request token. When this is complete, the popup
|
||||
@@ -61,7 +71,10 @@ module.exports = function(o) {
|
||||
|
||||
function reqTokenDone(err, xhr) {
|
||||
o.done();
|
||||
if (err) return callback(err);
|
||||
if (err) {
|
||||
if (timer) clearInterval(timer);
|
||||
return callback(err);
|
||||
}
|
||||
var resp = ohauth.stringQs(xhr.response);
|
||||
token('oauth_request_token_secret', resp.oauth_token_secret);
|
||||
var authorize_url = o.url + '/oauth/authorize?' + ohauth.qsString({
|
||||
@@ -80,6 +93,7 @@ module.exports = function(o) {
|
||||
// Called by a function in a landing page, in the popup window. The
|
||||
// window closes itself.
|
||||
window.authComplete = function(token) {
|
||||
if (timer) clearInterval(timer);
|
||||
var oauth_token = ohauth.stringQs(token.split('?')[1]);
|
||||
get_access_token(oauth_token.oauth_token);
|
||||
delete window.authComplete;
|
||||
@@ -109,6 +123,7 @@ module.exports = function(o) {
|
||||
|
||||
function accessTokenDone(err, xhr) {
|
||||
o.done();
|
||||
if (timer) clearInterval(timer);
|
||||
if (err) return callback(err);
|
||||
var access_token = ohauth.stringQs(xhr.response);
|
||||
token('oauth_token', access_token.oauth_token);
|
||||
@@ -418,11 +433,11 @@ module.exports = function(o) {
|
||||
store.disabled = true
|
||||
}
|
||||
store.enabled = !store.disabled
|
||||
|
||||
|
||||
if (typeof module != 'undefined' && module.exports) { module.exports = store }
|
||||
else if (typeof define === 'function' && define.amd) { define(store) }
|
||||
else { win.store = store }
|
||||
|
||||
|
||||
})(this.window || global);
|
||||
|
||||
})(window)
|
||||
@@ -465,7 +480,7 @@ function extend() {
|
||||
},{"./has-keys":5,"object-keys":6}],7:[function(require,module,exports){
|
||||
(function(global){/**
|
||||
* jsHashes - A fast and independent hashing library pure JavaScript implemented (ES3 compliant) for both server and client side
|
||||
*
|
||||
*
|
||||
* @class Hashes
|
||||
* @author Tomas Aparicio <tomas@rijndael-project.com>
|
||||
* @license New BSD (see LICENSE file)
|
||||
@@ -483,11 +498,11 @@ function extend() {
|
||||
*/
|
||||
(function(){
|
||||
var Hashes;
|
||||
|
||||
|
||||
// private helper methods
|
||||
function utf8Encode(str) {
|
||||
var x, y, output = '', i = -1, l;
|
||||
|
||||
|
||||
if (str && str.length) {
|
||||
l = str.length;
|
||||
while ((i+=1) < l) {
|
||||
@@ -518,15 +533,15 @@ function extend() {
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
function utf8Decode(str) {
|
||||
var i, ac, c1, c2, c3, arr = [], l;
|
||||
i = ac = c1 = c2 = c3 = 0;
|
||||
|
||||
|
||||
if (str && str.length) {
|
||||
l = str.length;
|
||||
str += '';
|
||||
|
||||
|
||||
while (i < l) {
|
||||
c1 = str.charCodeAt(i);
|
||||
ac += 1;
|
||||
@@ -633,9 +648,9 @@ function extend() {
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a raw string to an array of big-endian words
|
||||
* Convert a raw string to an array of big-endian words
|
||||
* Characters >255 have their high-byte silently ignored.
|
||||
*/
|
||||
function rstr2binb(input) {
|
||||
@@ -656,14 +671,14 @@ function extend() {
|
||||
var divisor = encoding.length,
|
||||
remainders = Array(),
|
||||
i, q, x, ld, quotient, dividend, output, full_length;
|
||||
|
||||
|
||||
/* Convert to an array of 16-bit big-endian values, forming the dividend */
|
||||
dividend = Array(Math.ceil(input.length / 2));
|
||||
ld = dividend.length;
|
||||
for (i = 0; i < ld; i+=1) {
|
||||
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Repeatedly perform a long division. The binary array forms the dividend,
|
||||
* the length of the encoding is the divisor. Once computed, the quotient
|
||||
@@ -684,13 +699,13 @@ function extend() {
|
||||
remainders[remainders.length] = x;
|
||||
dividend = quotient;
|
||||
}
|
||||
|
||||
|
||||
/* Convert the remainders to the output string */
|
||||
output = '';
|
||||
for (i = remainders.length - 1; i >= 0; i--) {
|
||||
output += encoding.charAt(remainders[i]);
|
||||
}
|
||||
|
||||
|
||||
/* Append leading zero equivalents */
|
||||
full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
|
||||
for (i = output.length; i < full_length; i+=1) {
|
||||
@@ -712,10 +727,10 @@ function extend() {
|
||||
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
|
||||
| (i + 2 < len ? input.charCodeAt(i+2) : 0);
|
||||
for (j = 0; j < 4; j+=1) {
|
||||
if (i * 8 + j * 6 > input.length * 8) {
|
||||
output += b64pad;
|
||||
} else {
|
||||
output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
|
||||
if (i * 8 + j * 6 > input.length * 8) {
|
||||
output += b64pad;
|
||||
} else {
|
||||
output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,7 +738,7 @@ function extend() {
|
||||
}
|
||||
|
||||
Hashes = {
|
||||
/**
|
||||
/**
|
||||
* @property {String} version
|
||||
* @readonly
|
||||
*/
|
||||
@@ -743,7 +758,7 @@ function extend() {
|
||||
// public method for encoding
|
||||
this.encode = function (input) {
|
||||
var i, j, triplet,
|
||||
output = '',
|
||||
output = '',
|
||||
len = input.length;
|
||||
|
||||
pad = pad || '=';
|
||||
@@ -761,7 +776,7 @@ function extend() {
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
return output;
|
||||
};
|
||||
|
||||
// public method for decoding
|
||||
@@ -833,8 +848,8 @@ function extend() {
|
||||
CRC32 : function (str) {
|
||||
var crc = 0, x = 0, y = 0, table, i, iTop;
|
||||
str = utf8Encode(str);
|
||||
|
||||
table = [
|
||||
|
||||
table = [
|
||||
'00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 ',
|
||||
'79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 ',
|
||||
'84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F ',
|
||||
@@ -852,7 +867,7 @@ function extend() {
|
||||
'7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D ',
|
||||
'806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 ',
|
||||
'60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA ',
|
||||
'AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 ',
|
||||
'AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 ',
|
||||
'5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 ',
|
||||
'B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 ',
|
||||
'05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 ',
|
||||
@@ -877,14 +892,14 @@ function extend() {
|
||||
* @class MD5
|
||||
* @constructor
|
||||
* @param {Object} [config]
|
||||
*
|
||||
*
|
||||
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
||||
* Digest Algorithm, as defined in RFC 1321.
|
||||
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* See <http://pajhome.org.uk/crypt/md5> for more infHashes.
|
||||
*/
|
||||
MD5 : function (options) {
|
||||
MD5 : function (options) {
|
||||
/**
|
||||
* Private config properties. You may need to tweak these to be compatible with
|
||||
* the server-side, but the defaults work in most cases.
|
||||
@@ -894,24 +909,24 @@ function extend() {
|
||||
b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
|
||||
utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
|
||||
|
||||
// privileged (public) methods
|
||||
this.hex = function (s) {
|
||||
// privileged (public) methods
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s, utf8), hexcase);
|
||||
};
|
||||
this.b64 = function (s) {
|
||||
this.b64 = function (s) {
|
||||
return rstr2b64(rstr(s), b64pad);
|
||||
};
|
||||
this.any = function(s, e) {
|
||||
return rstr2any(rstr(s, utf8), e);
|
||||
this.any = function(s, e) {
|
||||
return rstr2any(rstr(s, utf8), e);
|
||||
};
|
||||
this.hex_hmac = function (k, d) {
|
||||
return rstr2hex(rstr_hmac(k, d), hexcase);
|
||||
this.hex_hmac = function (k, d) {
|
||||
return rstr2hex(rstr_hmac(k, d), hexcase);
|
||||
};
|
||||
this.b64_hmac = function (k, d) {
|
||||
return rstr2b64(rstr_hmac(k,d), b64pad);
|
||||
this.b64_hmac = function (k, d) {
|
||||
return rstr2b64(rstr_hmac(k,d), b64pad);
|
||||
};
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
};
|
||||
/**
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
@@ -920,33 +935,33 @@ function extend() {
|
||||
this.vm_test = function () {
|
||||
return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
|
||||
};
|
||||
/**
|
||||
* Enable/disable uppercase hexadecimal returned string
|
||||
* @param {Boolean}
|
||||
/**
|
||||
* Enable/disable uppercase hexadecimal returned string
|
||||
* @param {Boolean}
|
||||
* @return {Object} this
|
||||
*/
|
||||
*/
|
||||
this.setUpperCase = function (a) {
|
||||
if (typeof a === 'boolean' ) {
|
||||
hexcase = a;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Defines a base64 pad string
|
||||
/**
|
||||
* Defines a base64 pad string
|
||||
* @param {String} Pad
|
||||
* @return {Object} this
|
||||
*/
|
||||
*/
|
||||
this.setPad = function (a) {
|
||||
b64pad = a || b64pad;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Defines a base64 pad string
|
||||
* @param {Boolean}
|
||||
/**
|
||||
* Defines a base64 pad string
|
||||
* @param {Boolean}
|
||||
* @return {Object} [this]
|
||||
*/
|
||||
*/
|
||||
this.setUTF8 = function (a) {
|
||||
if (typeof a === 'boolean') {
|
||||
if (typeof a === 'boolean') {
|
||||
utf8 = a;
|
||||
}
|
||||
return this;
|
||||
@@ -961,7 +976,7 @@ function extend() {
|
||||
s = (utf8) ? utf8Encode(s): s;
|
||||
return binl2rstr(binl(rstr2binl(s), s.length * 8));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the HMAC-MD5, of a key and some data (raw strings)
|
||||
*/
|
||||
@@ -971,11 +986,11 @@ function extend() {
|
||||
key = (utf8) ? utf8Encode(key) : key;
|
||||
data = (utf8) ? utf8Encode(data) : data;
|
||||
bkey = rstr2binl(key);
|
||||
if (bkey.length > 16) {
|
||||
bkey = binl(bkey, key.length * 8);
|
||||
if (bkey.length > 16) {
|
||||
bkey = binl(bkey, key.length * 8);
|
||||
}
|
||||
|
||||
ipad = Array(16), opad = Array(16);
|
||||
ipad = Array(16), opad = Array(16);
|
||||
for (i = 0; i < 16; i+=1) {
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
@@ -993,7 +1008,7 @@ function extend() {
|
||||
b = -271733879,
|
||||
c = -1732584194,
|
||||
d = 271733878;
|
||||
|
||||
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << ((len) % 32);
|
||||
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
||||
@@ -1104,7 +1119,7 @@ function extend() {
|
||||
* @class Hashes.SHA1
|
||||
* @param {Object} [config]
|
||||
* @constructor
|
||||
*
|
||||
*
|
||||
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined in FIPS 180-1
|
||||
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
@@ -1121,22 +1136,22 @@ function extend() {
|
||||
utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
|
||||
|
||||
// public methods
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s, utf8), hexcase);
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s, utf8), hexcase);
|
||||
};
|
||||
this.b64 = function (s) {
|
||||
this.b64 = function (s) {
|
||||
return rstr2b64(rstr(s, utf8), b64pad);
|
||||
};
|
||||
this.any = function (s, e) {
|
||||
this.any = function (s, e) {
|
||||
return rstr2any(rstr(s, utf8), e);
|
||||
};
|
||||
this.hex_hmac = function (k, d) {
|
||||
return rstr2hex(rstr_hmac(k, d));
|
||||
};
|
||||
this.b64_hmac = function (k, d) {
|
||||
return rstr2b64(rstr_hmac(k, d), b64pad);
|
||||
this.b64_hmac = function (k, d) {
|
||||
return rstr2b64(rstr_hmac(k, d), b64pad);
|
||||
};
|
||||
this.any_hmac = function (k, d, e) {
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
};
|
||||
/**
|
||||
@@ -1147,34 +1162,34 @@ function extend() {
|
||||
this.vm_test = function () {
|
||||
return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
|
||||
};
|
||||
/**
|
||||
* @description Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* @description Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUpperCase = function (a) {
|
||||
if (typeof a === 'boolean') {
|
||||
hexcase = a;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {string} Pad
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setPad = function (a) {
|
||||
b64pad = a || b64pad;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUTF8 = function (a) {
|
||||
if (typeof a === 'boolean') {
|
||||
utf8 = a;
|
||||
@@ -1235,12 +1250,12 @@ function extend() {
|
||||
oldc = c;
|
||||
oldd = d;
|
||||
olde = e;
|
||||
|
||||
|
||||
for (j = 0; j < 80; j+=1) {
|
||||
if (j < 16) {
|
||||
w[j] = x[i + j];
|
||||
} else {
|
||||
w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
||||
if (j < 16) {
|
||||
w[j] = x[i + j];
|
||||
} else {
|
||||
w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
||||
}
|
||||
t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
|
||||
safe_add(safe_add(e, w[j]), sha1_kt(j)));
|
||||
@@ -1282,7 +1297,7 @@ function extend() {
|
||||
/**
|
||||
* @class Hashes.SHA256
|
||||
* @param {config}
|
||||
*
|
||||
*
|
||||
* A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined in FIPS 180-2
|
||||
* Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
@@ -1302,23 +1317,23 @@ function extend() {
|
||||
sha256_K;
|
||||
|
||||
/* privileged (public) methods */
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s, utf8));
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s, utf8));
|
||||
};
|
||||
this.b64 = function (s) {
|
||||
this.b64 = function (s) {
|
||||
return rstr2b64(rstr(s, utf8), b64pad);
|
||||
};
|
||||
this.any = function (s, e) {
|
||||
return rstr2any(rstr(s, utf8), e);
|
||||
this.any = function (s, e) {
|
||||
return rstr2any(rstr(s, utf8), e);
|
||||
};
|
||||
this.hex_hmac = function (k, d) {
|
||||
return rstr2hex(rstr_hmac(k, d));
|
||||
this.hex_hmac = function (k, d) {
|
||||
return rstr2hex(rstr_hmac(k, d));
|
||||
};
|
||||
this.b64_hmac = function (k, d) {
|
||||
this.b64_hmac = function (k, d) {
|
||||
return rstr2b64(rstr_hmac(k, d), b64pad);
|
||||
};
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
};
|
||||
/**
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
@@ -1328,41 +1343,41 @@ function extend() {
|
||||
this.vm_test = function () {
|
||||
return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
|
||||
};
|
||||
/**
|
||||
* Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUpperCase = function (a) {
|
||||
if (typeof a === 'boolean') {
|
||||
if (typeof a === 'boolean') {
|
||||
hexcase = a;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {string} Pad
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setPad = function (a) {
|
||||
b64pad = a || b64pad;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUTF8 = function (a) {
|
||||
if (typeof a === 'boolean') {
|
||||
utf8 = a;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
// private methods
|
||||
|
||||
/**
|
||||
@@ -1380,21 +1395,21 @@ function extend() {
|
||||
key = (utf8) ? utf8Encode(key) : key;
|
||||
data = (utf8) ? utf8Encode(data) : data;
|
||||
var hash, i = 0,
|
||||
bkey = rstr2binb(key),
|
||||
ipad = Array(16),
|
||||
bkey = rstr2binb(key),
|
||||
ipad = Array(16),
|
||||
opad = Array(16);
|
||||
|
||||
if (bkey.length > 16) { bkey = binb(bkey, key.length * 8); }
|
||||
|
||||
|
||||
for (; i < 16; i+=1) {
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
|
||||
hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
|
||||
return binb2rstr(binb(opad.concat(hash), 512 + 256));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Main sha256 function, with its support functions
|
||||
*/
|
||||
@@ -1410,7 +1425,7 @@ function extend() {
|
||||
function sha256_Sigma1512(x) {return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));}
|
||||
function sha256_Gamma0512(x) {return (sha256_S(x, 1) ^ sha256_S(x, 8) ^ sha256_R(x, 7));}
|
||||
function sha256_Gamma1512(x) {return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));}
|
||||
|
||||
|
||||
sha256_K = [
|
||||
1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,
|
||||
-1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,
|
||||
@@ -1424,18 +1439,18 @@ function extend() {
|
||||
1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,
|
||||
-1866530822, -1538233109, -1090935817, -965641998
|
||||
];
|
||||
|
||||
|
||||
function binb(m, l) {
|
||||
var HASH = [1779033703, -1150833019, 1013904242, -1521486534,
|
||||
1359893119, -1694144372, 528734635, 1541459225];
|
||||
var W = new Array(64);
|
||||
var a, b, c, d, e, f, g, h;
|
||||
var i, j, T1, T2;
|
||||
|
||||
|
||||
/* append padding */
|
||||
m[l >> 5] |= 0x80 << (24 - l % 32);
|
||||
m[((l + 64 >> 9) << 4) + 15] = l;
|
||||
|
||||
|
||||
for (i = 0; i < m.length; i += 16)
|
||||
{
|
||||
a = HASH[0];
|
||||
@@ -1446,16 +1461,16 @@ function extend() {
|
||||
f = HASH[5];
|
||||
g = HASH[6];
|
||||
h = HASH[7];
|
||||
|
||||
|
||||
for (j = 0; j < 64; j+=1)
|
||||
{
|
||||
if (j < 16) {
|
||||
if (j < 16) {
|
||||
W[j] = m[j + i];
|
||||
} else {
|
||||
} else {
|
||||
W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),
|
||||
sha256_Gamma0256(W[j - 15])), W[j - 16]);
|
||||
}
|
||||
|
||||
|
||||
T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),
|
||||
sha256_K[j]), W[j]);
|
||||
T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
|
||||
@@ -1468,7 +1483,7 @@ function extend() {
|
||||
b = a;
|
||||
a = safe_add(T1, T2);
|
||||
}
|
||||
|
||||
|
||||
HASH[0] = safe_add(a, HASH[0]);
|
||||
HASH[1] = safe_add(b, HASH[1]);
|
||||
HASH[2] = safe_add(c, HASH[2]);
|
||||
@@ -1486,11 +1501,11 @@ function extend() {
|
||||
/**
|
||||
* @class Hashes.SHA512
|
||||
* @param {config}
|
||||
*
|
||||
*
|
||||
* A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined in FIPS 180-2
|
||||
* Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||
*/
|
||||
SHA512 : function (options) {
|
||||
/**
|
||||
@@ -1505,22 +1520,22 @@ function extend() {
|
||||
sha512_k;
|
||||
|
||||
/* privileged (public) methods */
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s));
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s));
|
||||
};
|
||||
this.b64 = function (s) {
|
||||
return rstr2b64(rstr(s), b64pad);
|
||||
this.b64 = function (s) {
|
||||
return rstr2b64(rstr(s), b64pad);
|
||||
};
|
||||
this.any = function (s, e) {
|
||||
this.any = function (s, e) {
|
||||
return rstr2any(rstr(s), e);
|
||||
};
|
||||
this.hex_hmac = function (k, d) {
|
||||
return rstr2hex(rstr_hmac(k, d));
|
||||
};
|
||||
this.b64_hmac = function (k, d) {
|
||||
this.b64_hmac = function (k, d) {
|
||||
return rstr2b64(rstr_hmac(k, d), b64pad);
|
||||
};
|
||||
this.any_hmac = function (k, d, e) {
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
};
|
||||
/**
|
||||
@@ -1531,34 +1546,34 @@ function extend() {
|
||||
this.vm_test = function () {
|
||||
return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
|
||||
};
|
||||
/**
|
||||
* @description Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* @description Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUpperCase = function (a) {
|
||||
if (typeof a === 'boolean') {
|
||||
hexcase = a;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {string} Pad
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setPad = function (a) {
|
||||
b64pad = a || b64pad;
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUTF8 = function (a) {
|
||||
if (typeof a === 'boolean') {
|
||||
utf8 = a;
|
||||
@@ -1567,7 +1582,7 @@ function extend() {
|
||||
};
|
||||
|
||||
/* private methods */
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the SHA-512 of a raw string
|
||||
*/
|
||||
@@ -1581,22 +1596,22 @@ function extend() {
|
||||
function rstr_hmac(key, data) {
|
||||
key = (utf8) ? utf8Encode(key) : key;
|
||||
data = (utf8) ? utf8Encode(data) : data;
|
||||
|
||||
var hash, i = 0,
|
||||
|
||||
var hash, i = 0,
|
||||
bkey = rstr2binb(key),
|
||||
ipad = Array(32), opad = Array(32);
|
||||
|
||||
if (bkey.length > 32) { bkey = binb(bkey, key.length * 8); }
|
||||
|
||||
|
||||
for (; i < 32; i+=1) {
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
|
||||
hash = binb(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);
|
||||
return binb2rstr(binb(opad.concat(hash), 1024 + 512));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the SHA-512 of an array of big-endian dwords, and a bit length
|
||||
*/
|
||||
@@ -1679,11 +1694,11 @@ function extend() {
|
||||
new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817)
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<80; i+=1) {
|
||||
W[i] = new int64(0, 0);
|
||||
}
|
||||
|
||||
|
||||
// append padding to the source string. The format is described in the FIPS.
|
||||
x[len >> 5] |= 0x80 << (24 - (len & 0x1f));
|
||||
x[((len + 128 >> 10)<< 5) + 31] = len;
|
||||
@@ -1697,12 +1712,12 @@ function extend() {
|
||||
int64copy(f, H[5]);
|
||||
int64copy(g, H[6]);
|
||||
int64copy(h, H[7]);
|
||||
|
||||
|
||||
for (j=0; j<16; j+=1) {
|
||||
W[j].h = x[i + 2*j];
|
||||
W[j].l = x[i + 2*j + 1];
|
||||
}
|
||||
|
||||
|
||||
for (j=16; j<80; j+=1) {
|
||||
//sigma1
|
||||
int64rrot(r1, W[j-2], 19);
|
||||
@@ -1716,36 +1731,36 @@ function extend() {
|
||||
int64shr(r3, W[j-15], 7);
|
||||
s0.l = r1.l ^ r2.l ^ r3.l;
|
||||
s0.h = r1.h ^ r2.h ^ r3.h;
|
||||
|
||||
|
||||
int64add4(W[j], s1, W[j-7], s0, W[j-16]);
|
||||
}
|
||||
|
||||
|
||||
for (j = 0; j < 80; j+=1) {
|
||||
//Ch
|
||||
Ch.l = (e.l & f.l) ^ (~e.l & g.l);
|
||||
Ch.h = (e.h & f.h) ^ (~e.h & g.h);
|
||||
|
||||
|
||||
//Sigma1
|
||||
int64rrot(r1, e, 14);
|
||||
int64rrot(r2, e, 18);
|
||||
int64revrrot(r3, e, 9);
|
||||
s1.l = r1.l ^ r2.l ^ r3.l;
|
||||
s1.h = r1.h ^ r2.h ^ r3.h;
|
||||
|
||||
|
||||
//Sigma0
|
||||
int64rrot(r1, a, 28);
|
||||
int64revrrot(r2, a, 2);
|
||||
int64revrrot(r3, a, 7);
|
||||
s0.l = r1.l ^ r2.l ^ r3.l;
|
||||
s0.h = r1.h ^ r2.h ^ r3.h;
|
||||
|
||||
|
||||
//Maj
|
||||
Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);
|
||||
Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);
|
||||
|
||||
|
||||
int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);
|
||||
int64add(T2, s0, Maj);
|
||||
|
||||
|
||||
int64copy(h, g);
|
||||
int64copy(g, f);
|
||||
int64copy(f, e);
|
||||
@@ -1764,7 +1779,7 @@ function extend() {
|
||||
int64add(H[6], H[6], g);
|
||||
int64add(H[7], H[7], h);
|
||||
}
|
||||
|
||||
|
||||
//represent the hash as an array of 32-bit dwords
|
||||
for (i=0; i<8; i+=1) {
|
||||
hash[2*i] = H[i].h;
|
||||
@@ -1772,20 +1787,20 @@ function extend() {
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
//A constructor for 64-bit numbers
|
||||
function int64(h, l) {
|
||||
this.h = h;
|
||||
this.l = l;
|
||||
//this.toString = int64toString;
|
||||
}
|
||||
|
||||
|
||||
//Copies src into dst, assuming both are 64-bit numbers
|
||||
function int64copy(dst, src) {
|
||||
dst.h = src.h;
|
||||
dst.l = src.l;
|
||||
}
|
||||
|
||||
|
||||
//Right-rotates a 64-bit number by shift
|
||||
//Won't handle cases of shift>=32
|
||||
//The function revrrot() is for that
|
||||
@@ -1793,21 +1808,21 @@ function extend() {
|
||||
dst.l = (x.l >>> shift) | (x.h << (32-shift));
|
||||
dst.h = (x.h >>> shift) | (x.l << (32-shift));
|
||||
}
|
||||
|
||||
|
||||
//Reverses the dwords of the source and then rotates right by shift.
|
||||
//This is equivalent to rotation by 32+shift
|
||||
function int64revrrot(dst, x, shift) {
|
||||
dst.l = (x.h >>> shift) | (x.l << (32-shift));
|
||||
dst.h = (x.l >>> shift) | (x.h << (32-shift));
|
||||
}
|
||||
|
||||
|
||||
//Bitwise-shifts right a 64-bit number by shift
|
||||
//Won't handle shift>=32, but it's never needed in SHA512
|
||||
function int64shr(dst, x, shift) {
|
||||
dst.l = (x.l >>> shift) | (x.h << (32-shift));
|
||||
dst.h = (x.h >>> shift);
|
||||
}
|
||||
|
||||
|
||||
//Adds two 64-bit numbers
|
||||
//Like the original implementation, does not rely on 32-bit operations
|
||||
function int64add(dst, x, y) {
|
||||
@@ -1818,7 +1833,7 @@ function extend() {
|
||||
dst.l = (w0 & 0xffff) | (w1 << 16);
|
||||
dst.h = (w2 & 0xffff) | (w3 << 16);
|
||||
}
|
||||
|
||||
|
||||
//Same, except with 4 addends. Works faster than adding them one by one.
|
||||
function int64add4(dst, a, b, c, d) {
|
||||
var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);
|
||||
@@ -1828,7 +1843,7 @@ function extend() {
|
||||
dst.l = (w0 & 0xffff) | (w1 << 16);
|
||||
dst.h = (w2 & 0xffff) | (w3 << 16);
|
||||
}
|
||||
|
||||
|
||||
//Same, except with 5 addends
|
||||
function int64add5(dst, a, b, c, d, e) {
|
||||
var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff),
|
||||
@@ -1843,7 +1858,7 @@ function extend() {
|
||||
* @class Hashes.RMD160
|
||||
* @constructor
|
||||
* @param {Object} [config]
|
||||
*
|
||||
*
|
||||
* A JavaScript implementation of the RIPEMD-160 Algorithm
|
||||
* Version 2.2 Copyright Jeremy Lin, Paul Johnston 2000 - 2009.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
@@ -1891,22 +1906,22 @@ function extend() {
|
||||
|
||||
/* privileged (public) methods */
|
||||
this.hex = function (s) {
|
||||
return rstr2hex(rstr(s, utf8));
|
||||
return rstr2hex(rstr(s, utf8));
|
||||
};
|
||||
this.b64 = function (s) {
|
||||
return rstr2b64(rstr(s, utf8), b64pad);
|
||||
};
|
||||
this.any = function (s, e) {
|
||||
this.any = function (s, e) {
|
||||
return rstr2any(rstr(s, utf8), e);
|
||||
};
|
||||
this.hex_hmac = function (k, d) {
|
||||
this.hex_hmac = function (k, d) {
|
||||
return rstr2hex(rstr_hmac(k, d));
|
||||
};
|
||||
this.b64_hmac = function (k, d) {
|
||||
this.b64_hmac = function (k, d) {
|
||||
return rstr2b64(rstr_hmac(k, d), b64pad);
|
||||
};
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
this.any_hmac = function (k, d, e) {
|
||||
return rstr2any(rstr_hmac(k, d), e);
|
||||
};
|
||||
/**
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
@@ -1916,32 +1931,32 @@ function extend() {
|
||||
this.vm_test = function () {
|
||||
return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
|
||||
};
|
||||
/**
|
||||
* @description Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* @description Enable/disable uppercase hexadecimal returned string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUpperCase = function (a) {
|
||||
if (typeof a === 'boolean' ) { hexcase = a; }
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {string} Pad
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setPad = function (a) {
|
||||
if (typeof a !== 'undefined' ) { b64pad = a; }
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
/**
|
||||
* @description Defines a base64 pad string
|
||||
* @param {boolean}
|
||||
* @return {Object} this
|
||||
* @public
|
||||
*/
|
||||
*/
|
||||
this.setUTF8 = function (a) {
|
||||
if (typeof a === 'boolean') { utf8 = a; }
|
||||
return this;
|
||||
@@ -1967,10 +1982,10 @@ function extend() {
|
||||
bkey = rstr2binl(key),
|
||||
ipad = Array(16), opad = Array(16);
|
||||
|
||||
if (bkey.length > 16) {
|
||||
bkey = binl(bkey, key.length * 8);
|
||||
if (bkey.length > 16) {
|
||||
bkey = binl(bkey, key.length * 8);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < 16; i+=1) {
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
@@ -2007,7 +2022,7 @@ function extend() {
|
||||
x[len >> 5] |= 0x80 << (len % 32);
|
||||
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
||||
l = x.length;
|
||||
|
||||
|
||||
for (i = 0; i < l; i+=16) {
|
||||
A1 = A2 = h0; B1 = B2 = h1; C1 = C2 = h2; D1 = D2 = h3; E1 = E2 = h4;
|
||||
for (j = 0; j <= 79; j+=1) {
|
||||
@@ -2033,7 +2048,7 @@ function extend() {
|
||||
return [h0, h1, h2, h3, h4];
|
||||
}
|
||||
|
||||
// specific algorithm methods
|
||||
// specific algorithm methods
|
||||
function rmd160_f(j, x, y, z) {
|
||||
return ( 0 <= j && j <= 15) ? (x ^ y ^ z) :
|
||||
(16 <= j && j <= 31) ? (x & y) | (~x & z) :
|
||||
@@ -2287,7 +2302,7 @@ module.exports = Object.keys || require('./shim');
|
||||
/**!
|
||||
* is
|
||||
* the definitive JavaScript type testing library
|
||||
*
|
||||
*
|
||||
* @copyright 2013 Enrico Marino
|
||||
* @license MIT
|
||||
*/
|
||||
@@ -3012,4 +3027,4 @@ module.exports = function forEach (obj, fn, ctx) {
|
||||
|
||||
},{}]},{},[1])(1)
|
||||
});
|
||||
;
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user