spa
Version:
Single-page applications builder with continuous integration, granular updates and loader.
1 lines • 9.93 kB
JavaScript
(function(){"use strict";var t={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};"undefined"!=typeof module&&module.exports&&(module.exports=t),t.bitArray={bitSlice:function(e,i,r){return e=t.bitArray._shiftRight(e.slice(i/32),32-(31&i)).slice(1),void 0===r?e:t.bitArray.clamp(e,r-i)},extract:function(t,e,i){var r,n=Math.floor(-e-i&31);return r=-32&(e+i-1^e)?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n,r&(1<<i)-1},concat:function(e,i){if(0===e.length||0===i.length){return e.concat(i)}var o=e[e.length-1],s=t.bitArray.getPartial(o);return 32===s?e.concat(i):t.bitArray._shiftRight(i,s,0|o,e.slice(0,e.length-1))},bitLength:function(e){var r,i=e.length;return 0===i?0:(r=e[i-1],32*(i-1)+t.bitArray.getPartial(r))},clamp:function(e,i){if(32*e.length<i){return e}e=e.slice(0,Math.ceil(i/32));var r=e.length;return i=31&i,r>0&&i&&(e[r-1]=t.bitArray.partial(i,e[r-1]&2147483648>>i-1,1)),e},partial:function(t,e,i){return 32===t?e:(i?0|e:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(e,i){if(t.bitArray.bitLength(e)!==t.bitArray.bitLength(i)){return!1}var n,r=0;for(n=0;n<e.length;n++){r|=e[n]^i[n]}return 0===r},_shiftRight:function(e,i,r,n){var o,a,s=0;for(void 0===n&&(n=[]);i>=32;i-=32){n.push(r),r=0}if(0===i){return n.concat(e)}for(o=0;o<e.length;o++){n.push(r|e[o]>>>i),r=e[o]<<32-i}return s=e.length?e[e.length-1]:0,a=t.bitArray.getPartial(s),n.push(t.bitArray.partial(i+a&31,i+a>32?r:n.pop(),1)),n},_xor4:function(t,e){return[t[0]^e[0],t[1]^e[1],t[2]^e[2],t[3]^e[3]]}},t.codec.bytes={fromBits:function(e){var n,o,i=[],r=t.bitArray.bitLength(e);for(n=0;r/8>n;n++){0===(3&n)&&(o=e[n/4]),i.push(o>>>24),o<<=8}return i},toBits:function(e){var r,i=[],n=0;for(r=0;r<e.length;r++){n=n<<8|e[r],3===(3&r)&&(i.push(n),n=0)}return 3&r&&i.push(t.bitArray.partial(8*(3&r),n)),i}},t.codec.utf8String={fromBits:function(e){var n,o,i="",r=t.bitArray.bitLength(e);for(n=0;r/8>n;n++){0===(3&n)&&(o=e[n/4]),i+=String.fromCharCode(o>>>24),o<<=8}return decodeURIComponent(escape(i))},toBits:function(e){e=unescape(encodeURIComponent(e));var r,i=[],n=0;for(r=0;r<e.length;r++){n=n<<8|e.charCodeAt(r),3===(3&r)&&(i.push(n),n=0)}return 3&r&&i.push(t.bitArray.partial(8*(3&r),n)),i}},t.codec.hex={fromBits:function(e){var r,i="";for(r=0;r<e.length;r++){i+=((0|e[r])+0xf00000000000).toString(16).substr(4)}return i.substr(0,t.bitArray.bitLength(e)/4)},toBits:function(e){var i,n,r=[];for(e=e.replace(/\s|0x/g,""),n=e.length,e+="00000000",i=0;i<e.length;i+=8){r.push(0^parseInt(e.substr(i,8),16))}return t.bitArray.clamp(r,4*n)}},t.cipher.aes=function(e){this._tables[0][0][0]||this._precompute();var i,r,n,o,s,a=this._tables[0][4],h=this._tables[1],c=e.length,f=1;if(4!==c&&6!==c&&8!==c){throw new t.exception.invalid("invalid aes key size")}for(this._key=[o=e.slice(0),s=[]],i=c;4*c+28>i;i++){n=o[i-1],(i%c===0||8===c&&i%c===4)&&(n=a[n>>>24]<<24^a[n>>16&255]<<16^a[n>>8&255]<<8^a[255&n],i%c===0&&(n=n<<8^n>>>24^f<<24,f=f<<1^283*(f>>7))),o[i]=o[i-c]^n}for(r=0;i;r++,i--){n=o[3&r?i:i-4],s[r]=4>=i||4>r?n:h[0][a[n>>>24]]^h[1][a[n>>16&255]]^h[2][a[n>>8&255]]^h[3][a[255&n]]}},t.cipher.aes.prototype={encrypt:function(t){return this._crypt(t,0)},decrypt:function(t){return this._crypt(t,1)},_tables:[[[],[],[],[],[]],[[],[],[],[],[]]],_precompute:function(){var n,o,s,c,f,u,l,p,d,t=this._tables[0],e=this._tables[1],i=t[4],r=e[4],a=[],h=[];for(n=0;256>n;n++){h[(a[n]=n<<1^283*(n>>7))^n]=n}for(o=s=0;!i[o];o^=c||1,s=h[s]||1){for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^255&l^99,i[o]=l,r[l]=o,u=a[f=a[c=a[o]]],d=16843009*u^65537*f^257*c^16843008*o,p=257*a[l]^16843008*l,n=0;4>n;n++){t[n][o]=p=p<<24^p>>>8,e[n][l]=d=d<<24^d>>>8}}for(n=0;5>n;n++){t[n]=t[n].slice(0),e[n]=e[n].slice(0)}},_crypt:function(e,i){if(4!==e.length){throw new t.exception.invalid("invalid aes block size")}var h,c,f,l,r=this._key[i],n=e[0]^r[0],o=e[i?3:1]^r[1],s=e[2]^r[2],a=e[i?1:3]^r[3],u=r.length/4-2,p=4,d=[0,0,0,0],g=this._tables[i],_=g[0],y=g[1],m=g[2],b=g[3],v=g[4];for(l=0;u>l;l++){h=_[n>>>24]^y[o>>16&255]^m[s>>8&255]^b[255&a]^r[p],c=_[o>>>24]^y[s>>16&255]^m[a>>8&255]^b[255&n]^r[p+1],f=_[s>>>24]^y[a>>16&255]^m[n>>8&255]^b[255&o]^r[p+2],a=_[a>>>24]^y[n>>16&255]^m[o>>8&255]^b[255&s]^r[p+3],p+=4,n=h,o=c,s=f}for(l=0;4>l;l++){d[i?3&-l:l]=v[n>>>24]<<24^v[o>>16&255]<<16^v[s>>8&255]<<8^v[255&a]^r[p++],h=n,n=o,o=s,s=a,a=h}return d}},t.hash.sha256=function(t){this._key[0]||this._precompute(),t?(this._h=t._h.slice(0),this._buffer=t._buffer.slice(0),this._length=t._length):this.reset()},t.hash.sha256.hash=function(e){return(new t.hash.sha256).update(e).finalize()},t.hash.sha256.prototype={blockSize:512,reset:function(){return this._h=this._init.slice(0),this._buffer=[],this._length=0,this},update:function(e){"string"==typeof e&&(e=t.codec.utf8String.toBits(e));var i,r=this._buffer=t.bitArray.concat(this._buffer,e),n=this._length,o=this._length=n+t.bitArray.bitLength(e);for(i=512+n&-512;o>=i;i+=512){this._block(r.splice(0,16))}return this},finalize:function(){var e,i=this._buffer,r=this._h;for(i=t.bitArray.concat(i,[t.bitArray.partial(1,1)]),e=i.length+2;15&e;e++){i.push(0)}for(i.push(Math.floor(this._length/4294967296)),i.push(0|this._length);i.length;){this._block(i.splice(0,16))}return this.reset(),r},_init:[],_key:[],_precompute:function(){function r(t){return 4294967296*(t-Math.floor(t))|0}var i,t=0,e=2;t:for(;64>t;e++){for(i=2;e>=i*i;i++){if(e%i===0){continue t}}8>t&&(this._init[t]=r(Math.pow(e,.5))),this._key[t]=r(Math.pow(e,1/3)),t++}},_block:function(t){var e,i,r,n,o=t.slice(0),s=this._h,a=this._key,h=s[0],c=s[1],f=s[2],u=s[3],l=s[4],p=s[5],d=s[6],g=s[7];for(e=0;64>e;e++){16>e?i=o[e]:(r=o[e+1&15],n=o[e+14&15],i=o[15&e]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+o[15&e]+o[e+9&15]|0),i=i+g+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(d^l&(p^d))+a[e],g=d,d=p,p=l,l=u+i|0,u=f,f=c,c=h,h=i+(c&f^u&(c^f))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0}s[0]=s[0]+h|0,s[1]=s[1]+c|0,s[2]=s[2]+f|0,s[3]=s[3]+u|0,s[4]=s[4]+l|0,s[5]=s[5]+p|0,s[6]=s[6]+d|0,s[7]=s[7]+g|0}},t.misc.hmac=function(e,i){this._hash=i=i||t.hash.sha256;var n,r=[[],[]],o=i.prototype.blockSize/32;for(this._baseHash=[new i,new i],e.length>o&&(e=i.hash(e)),n=0;o>n;n++){r[0][n]=909522486^e[n],r[1][n]=1549556828^e[n]}this._baseHash[0].update(r[0]),this._baseHash[1].update(r[1]),this._resultHash=new i(this._baseHash[0])},t.misc.hmac.prototype.encrypt=t.misc.hmac.prototype.mac=function(e){if(this._updated){throw new t.exception.invalid("encrypt on already updated hmac called!")}return this.update(e),this.digest(e)},t.misc.hmac.prototype.reset=function(){this._resultHash=new this._hash(this._baseHash[0]),this._updated=!1},t.misc.hmac.prototype.update=function(t){this._updated=!0,this._resultHash.update(t)},t.misc.hmac.prototype.digest=function(){var t=this._resultHash.finalize(),e=new this._hash(this._baseHash[1]).update(t).finalize();return this.reset(),e},t.misc.pbkdf2=function(e,i,r,n,o){if(r=r||1e3,0>n||0>r){throw t.exception.invalid("invalid params to pbkdf2")}"string"==typeof e&&(e=t.codec.utf8String.toBits(e)),"string"==typeof i&&(i=t.codec.utf8String.toBits(i)),o=o||t.misc.hmac;var a,h,c,f,u,s=new o(e),l=[],p=t.bitArray;for(u=1;32*l.length<(n||1);u++){for(a=h=s.encrypt(p.concat(i,[u])),c=1;r>c;c++){for(h=s.encrypt(h),f=0;f<h.length;f++){a[f]^=h[f]}}l=l.concat(a)}return n&&(l=p.clamp(l,n)),l},t.mode.ocb2={name:"ocb2",encrypt:function(e,i,r,n,o,s){if(128!==t.bitArray.bitLength(r)){throw new t.exception.invalid("ocb iv must be 128 bits")}var a,p,d,_,h=t.mode.ocb2._times2,c=t.bitArray,f=c._xor4,u=[0,0,0,0],l=h(e.encrypt(r)),g=[];for(n=n||[],o=o||64,a=0;a+4<i.length;a+=4){p=i.slice(a,a+4),u=f(u,p),g=g.concat(f(l,e.encrypt(f(l,p)))),l=h(l)}return p=i.slice(a),d=c.bitLength(p),_=e.encrypt(f(l,[0,0,0,d])),p=c.clamp(f(p.concat([0,0,0]),_),d),u=f(u,f(p.concat([0,0,0]),_)),u=e.encrypt(f(u,f(l,h(l)))),n.length&&(u=f(u,s?n:t.mode.ocb2.pmac(e,n))),g.concat(c.concat(p,c.clamp(u,o)))},decrypt:function(e,i,r,n,o,s){if(128!==t.bitArray.bitLength(r)){throw new t.exception.invalid("ocb iv must be 128 bits")}o=o||64;var a,p,d,y,h=t.mode.ocb2._times2,c=t.bitArray,f=c._xor4,u=[0,0,0,0],l=h(e.encrypt(r)),g=t.bitArray.bitLength(i)-o,_=[];for(n=n||[],a=0;g/32>a+4;a+=4){p=f(l,e.decrypt(f(l,i.slice(a,a+4)))),u=f(u,p),_=_.concat(p),l=h(l)}if(d=g-32*a,y=e.encrypt(f(l,[0,0,0,d])),p=f(y,c.clamp(i.slice(a),d).concat([0,0,0])),u=f(u,p),u=e.encrypt(f(u,f(l,h(l)))),n.length&&(u=f(u,s?n:t.mode.ocb2.pmac(e,n))),!c.equal(c.clamp(u,o),c.bitSlice(i,g))){throw new t.exception.corrupt("ocb: tag doesn't match")}return _.concat(c.clamp(p,d))},pmac:function(e,i){var r,c,n=t.mode.ocb2._times2,o=t.bitArray,s=o._xor4,a=[0,0,0,0],h=e.encrypt([0,0,0,0]);for(h=s(h,n(n(h))),r=0;r+4<i.length;r+=4){h=n(h),a=s(a,e.encrypt(s(h,i.slice(r,r+4))))}return c=i.slice(r),o.bitLength(c)<128&&(h=s(h,n(h)),c=o.concat(c,[-2147483648,0,0,0])),a=s(a,c),e.encrypt(s(n(s(h,n(h))),a))},_times2:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};var e=function(e){var i;return i=function(i,r,n){var o,s,a,h,c,f,u,l;if(i instanceof ArrayBuffer){l=new Uint8Array(i),s=t.codec.bytes.toBits(l)}else{if(!(i instanceof Buffer)){throw Error("invalid input type")}s=t.codec.bytes.toBits(i)}return f=t.codec.hex.toBits(n.salt),a=t.codec.hex.toBits(n.iv),h=t.misc.pbkdf2(r,f,n.iter).slice(0,n.ks/32),c=new t.cipher.aes(h),o=t.codec.utf8String.toBits(n.auth),u=t.mode[e].decrypt(c,s,a,o,n.ts),t.codec.utf8String.fromBits(u)},function(t,e,r){return i(t,r.options.password,e.decoding)}};return e("ocb2")})();