Cleanup OpenPGP.js and prepare for using Rollup

This commit is contained in:
djmaze 2021-05-18 10:59:13 +02:00
parent f6bba786ed
commit c571a4fbe7
22 changed files with 5522 additions and 582 deletions

File diff suppressed because it is too large Load diff

56
vendors/openpgp-2.6.2/rollup.config.js vendored Normal file
View file

@ -0,0 +1,56 @@
/*
npm install rollup rollup-plugin-includepaths rollup-plugin-babel rollup-plugin-external-globals rollup-plugin-html rollup-plugin-terser
rollup -c
*/
import includePaths from 'rollup-plugin-includepaths';
import { terser } from "rollup-plugin-terser";
//import resolve from '@rollup/plugin-node-resolve';
//import replace from '@rollup/plugin-replace';
//import commonjs from '@rollup/plugin-commonjs';
let includePathOptions = {
include: {},
paths: ['src'],
external: [],
extensions: ['.js']
};
let terserConfig = {
output: {
comments: false
},
keep_classnames: true, // Required for AbstractModel and AbstractCollectionModel
compress:{
ecma: 6,
drop_console: true
/*
,hoist_props: false
,keep_fargs: false
,toplevel: true
,unsafe_arrows: true // Issue with knockoutjs
,unsafe_methods: true
,unsafe_proto: true
*/
}
// ,mangle: {reserved:['SendMessage']}
};
export default [{
input: 'src/index.js',
output: [
{file: 'dist/snappymail/openpgp.js', format: 'iife'}, // format: 'es'
{file: 'dist/snappymail/openpgp.min.js', format: 'iife', plugins: [terser(terserConfig)], }
],
plugins: [
includePaths(includePathOptions)
// ,commonjs()
/*
replace({
'OpenPGP.js VERSION': `OpenPGP.js ${pkg.version}`,
'require(': 'void(',
delimiters: ['', '']
})
*/
]
}];

2898
vendors/openpgp-2.6.2/src/asmcrypto.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,23 +0,0 @@
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var n=void 0,u=!0,aa=this;function ba(e,d){var c=e.split("."),f=aa;!(c[0]in f)&&f.execScript&&f.execScript("var "+c[0]);for(var a;c.length&&(a=c.shift());)!c.length&&d!==n?f[a]=d:f=f[a]?f[a]:f[a]={}};var C="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function K(e,d){this.index="number"===typeof d?d:0;this.d=0;this.buffer=e instanceof(C?Uint8Array:Array)?e:new (C?Uint8Array:Array)(32768);if(2*this.buffer.length<=this.index)throw Error("invalid index");this.buffer.length<=this.index&&ca(this)}function ca(e){var d=e.buffer,c,f=d.length,a=new (C?Uint8Array:Array)(f<<1);if(C)a.set(d);else for(c=0;c<f;++c)a[c]=d[c];return e.buffer=a}
K.prototype.a=function(e,d,c){var f=this.buffer,a=this.index,b=this.d,k=f[a],m;c&&1<d&&(e=8<d?(L[e&255]<<24|L[e>>>8&255]<<16|L[e>>>16&255]<<8|L[e>>>24&255])>>32-d:L[e]>>8-d);if(8>d+b)k=k<<d|e,b+=d;else for(m=0;m<d;++m)k=k<<1|e>>d-m-1&1,8===++b&&(b=0,f[a++]=L[k],k=0,a===f.length&&(f=ca(this)));f[a]=k;this.buffer=f;this.d=b;this.index=a};K.prototype.finish=function(){var e=this.buffer,d=this.index,c;0<this.d&&(e[d]<<=8-this.d,e[d]=L[e[d]],d++);C?c=e.subarray(0,d):(e.length=d,c=e);return c};
var ga=new (C?Uint8Array:Array)(256),M;for(M=0;256>M;++M){for(var R=M,S=R,ha=7,R=R>>>1;R;R>>>=1)S<<=1,S|=R&1,--ha;ga[M]=(S<<ha&255)>>>0}var L=ga;function ja(e){this.buffer=new (C?Uint16Array:Array)(2*e);this.length=0}ja.prototype.getParent=function(e){return 2*((e-2)/4|0)};ja.prototype.push=function(e,d){var c,f,a=this.buffer,b;c=this.length;a[this.length++]=d;for(a[this.length++]=e;0<c;)if(f=this.getParent(c),a[c]>a[f])b=a[c],a[c]=a[f],a[f]=b,b=a[c+1],a[c+1]=a[f+1],a[f+1]=b,c=f;else break;return this.length};
ja.prototype.pop=function(){var e,d,c=this.buffer,f,a,b;d=c[0];e=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(b=0;;){a=2*b+2;if(a>=this.length)break;a+2<this.length&&c[a+2]>c[a]&&(a+=2);if(c[a]>c[b])f=c[b],c[b]=c[a],c[a]=f,f=c[b+1],c[b+1]=c[a+1],c[a+1]=f;else break;b=a}return{index:e,value:d,length:this.length}};function ka(e,d){this.e=ma;this.f=0;this.input=C&&e instanceof Array?new Uint8Array(e):e;this.c=0;d&&(d.lazy&&(this.f=d.lazy),"number"===typeof d.compressionType&&(this.e=d.compressionType),d.outputBuffer&&(this.b=C&&d.outputBuffer instanceof Array?new Uint8Array(d.outputBuffer):d.outputBuffer),"number"===typeof d.outputIndex&&(this.c=d.outputIndex));this.b||(this.b=new (C?Uint8Array:Array)(32768))}var ma=2,T=[],U;
for(U=0;288>U;U++)switch(u){case 143>=U:T.push([U+48,8]);break;case 255>=U:T.push([U-144+400,9]);break;case 279>=U:T.push([U-256+0,7]);break;case 287>=U:T.push([U-280+192,8]);break;default:throw"invalid literal: "+U;}
ka.prototype.h=function(){var e,d,c,f,a=this.input;switch(this.e){case 0:c=0;for(f=a.length;c<f;){d=C?a.subarray(c,c+65535):a.slice(c,c+65535);c+=d.length;var b=d,k=c===f,m=n,g=n,p=n,v=n,x=n,l=this.b,h=this.c;if(C){for(l=new Uint8Array(this.b.buffer);l.length<=h+b.length+5;)l=new Uint8Array(l.length<<1);l.set(this.b)}m=k?1:0;l[h++]=m|0;g=b.length;p=~g+65536&65535;l[h++]=g&255;l[h++]=g>>>8&255;l[h++]=p&255;l[h++]=p>>>8&255;if(C)l.set(b,h),h+=b.length,l=l.subarray(0,h);else{v=0;for(x=b.length;v<x;++v)l[h++]=
b[v];l.length=h}this.c=h;this.b=l}break;case 1:var q=new K(C?new Uint8Array(this.b.buffer):this.b,this.c);q.a(1,1,u);q.a(1,2,u);var t=na(this,a),w,da,z;w=0;for(da=t.length;w<da;w++)if(z=t[w],K.prototype.a.apply(q,T[z]),256<z)q.a(t[++w],t[++w],u),q.a(t[++w],5),q.a(t[++w],t[++w],u);else if(256===z)break;this.b=q.finish();this.c=this.b.length;break;case ma:var B=new K(C?new Uint8Array(this.b.buffer):this.b,this.c),ra,J,N,O,P,Ia=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],W,sa,X,ta,ea,ia=Array(19),
ua,Q,fa,y,va;ra=ma;B.a(1,1,u);B.a(ra,2,u);J=na(this,a);W=oa(this.j,15);sa=pa(W);X=oa(this.i,7);ta=pa(X);for(N=286;257<N&&0===W[N-1];N--);for(O=30;1<O&&0===X[O-1];O--);var wa=N,xa=O,F=new (C?Uint32Array:Array)(wa+xa),r,G,s,Y,E=new (C?Uint32Array:Array)(316),D,A,H=new (C?Uint8Array:Array)(19);for(r=G=0;r<wa;r++)F[G++]=W[r];for(r=0;r<xa;r++)F[G++]=X[r];if(!C){r=0;for(Y=H.length;r<Y;++r)H[r]=0}r=D=0;for(Y=F.length;r<Y;r+=G){for(G=1;r+G<Y&&F[r+G]===F[r];++G);s=G;if(0===F[r])if(3>s)for(;0<s--;)E[D++]=0,
H[0]++;else for(;0<s;)A=138>s?s:138,A>s-3&&A<s&&(A=s-3),10>=A?(E[D++]=17,E[D++]=A-3,H[17]++):(E[D++]=18,E[D++]=A-11,H[18]++),s-=A;else if(E[D++]=F[r],H[F[r]]++,s--,3>s)for(;0<s--;)E[D++]=F[r],H[F[r]]++;else for(;0<s;)A=6>s?s:6,A>s-3&&A<s&&(A=s-3),E[D++]=16,E[D++]=A-3,H[16]++,s-=A}e=C?E.subarray(0,D):E.slice(0,D);ea=oa(H,7);for(y=0;19>y;y++)ia[y]=ea[Ia[y]];for(P=19;4<P&&0===ia[P-1];P--);ua=pa(ea);B.a(N-257,5,u);B.a(O-1,5,u);B.a(P-4,4,u);for(y=0;y<P;y++)B.a(ia[y],3,u);y=0;for(va=e.length;y<va;y++)if(Q=
e[y],B.a(ua[Q],ea[Q],u),16<=Q){y++;switch(Q){case 16:fa=2;break;case 17:fa=3;break;case 18:fa=7;break;default:throw"invalid code: "+Q;}B.a(e[y],fa,u)}var ya=[sa,W],za=[ta,X],I,Aa,Z,la,Ba,Ca,Da,Ea;Ba=ya[0];Ca=ya[1];Da=za[0];Ea=za[1];I=0;for(Aa=J.length;I<Aa;++I)if(Z=J[I],B.a(Ba[Z],Ca[Z],u),256<Z)B.a(J[++I],J[++I],u),la=J[++I],B.a(Da[la],Ea[la],u),B.a(J[++I],J[++I],u);else if(256===Z)break;this.b=B.finish();this.c=this.b.length;break;default:throw"invalid compression type";}return this.b};
function qa(e,d){this.length=e;this.g=d}
var Fa=function(){function e(a){switch(u){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:throw"invalid length: "+a;}}var d=[],c,f;for(c=3;258>=c;c++)f=e(c),d[c]=f[2]<<24|
f[1]<<16|f[0];return d}(),Ga=C?new Uint32Array(Fa):Fa;
function na(e,d){function c(a,c){var b=a.g,d=[],f=0,e;e=Ga[a.length];d[f++]=e&65535;d[f++]=e>>16&255;d[f++]=e>>24;var g;switch(u){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b-
65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>=
b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:throw"invalid distance";}e=g;d[f++]=e[0];d[f++]=e[1];d[f++]=e[2];var k,m;k=0;for(m=d.length;k<m;++k)l[h++]=d[k];t[d[0]]++;w[d[3]]++;q=a.length+c-1;x=null}var f,a,b,k,m,g={},p,v,x,l=C?new Uint16Array(2*d.length):[],h=0,q=0,t=new (C?Uint32Array:Array)(286),w=new (C?Uint32Array:Array)(30),da=e.f,z;if(!C){for(b=0;285>=b;)t[b++]=0;for(b=0;29>=b;)w[b++]=0}t[256]=1;f=0;for(a=d.length;f<a;++f){b=
m=0;for(k=3;b<k&&f+b!==a;++b)m=m<<8|d[f+b];g[m]===n&&(g[m]=[]);p=g[m];if(!(0<q--)){for(;0<p.length&&32768<f-p[0];)p.shift();if(f+3>=a){x&&c(x,-1);b=0;for(k=a-f;b<k;++b)z=d[f+b],l[h++]=z,++t[z];break}0<p.length?(v=Ha(d,f,p),x?x.length<v.length?(z=d[f-1],l[h++]=z,++t[z],c(v,0)):c(x,-1):v.length<da?x=v:c(v,0)):x?c(x,-1):(z=d[f],l[h++]=z,++t[z])}p.push(f)}l[h++]=256;t[256]++;e.j=t;e.i=w;return C?l.subarray(0,h):l}
function Ha(e,d,c){var f,a,b=0,k,m,g,p,v=e.length;m=0;p=c.length;a:for(;m<p;m++){f=c[p-m-1];k=3;if(3<b){for(g=b;3<g;g--)if(e[f+g-1]!==e[d+g-1])continue a;k=b}for(;258>k&&d+k<v&&e[f+k]===e[d+k];)++k;k>b&&(a=f,b=k);if(258===k)break}return new qa(b,d-a)}
function oa(e,d){var c=e.length,f=new ja(572),a=new (C?Uint8Array:Array)(c),b,k,m,g,p;if(!C)for(g=0;g<c;g++)a[g]=0;for(g=0;g<c;++g)0<e[g]&&f.push(g,e[g]);b=Array(f.length/2);k=new (C?Uint32Array:Array)(f.length/2);if(1===b.length)return a[f.pop().index]=1,a;g=0;for(p=f.length/2;g<p;++g)b[g]=f.pop(),k[g]=b[g].value;m=Ja(k,k.length,d);g=0;for(p=b.length;g<p;++g)a[b[g].index]=m[g];return a}
function Ja(e,d,c){function f(a){var b=g[a][p[a]];b===d?(f(a+1),f(a+1)):--k[b];++p[a]}var a=new (C?Uint16Array:Array)(c),b=new (C?Uint8Array:Array)(c),k=new (C?Uint8Array:Array)(d),m=Array(c),g=Array(c),p=Array(c),v=(1<<c)-d,x=1<<c-1,l,h,q,t,w;a[c-1]=d;for(h=0;h<c;++h)v<x?b[h]=0:(b[h]=1,v-=x),v<<=1,a[c-2-h]=(a[c-1-h]/2|0)+d;a[0]=b[0];m[0]=Array(a[0]);g[0]=Array(a[0]);for(h=1;h<c;++h)a[h]>2*a[h-1]+b[h]&&(a[h]=2*a[h-1]+b[h]),m[h]=Array(a[h]),g[h]=Array(a[h]);for(l=0;l<d;++l)k[l]=c;for(q=0;q<a[c-1];++q)m[c-
1][q]=e[q],g[c-1][q]=q;for(l=0;l<c;++l)p[l]=0;1===b[c-1]&&(--k[0],++p[c-1]);for(h=c-2;0<=h;--h){t=l=0;w=p[h+1];for(q=0;q<a[h];q++)t=m[h+1][w]+m[h+1][w+1],t>e[l]?(m[h][q]=t,g[h][q]=d,w+=2):(m[h][q]=e[l],g[h][q]=l,++l);p[h]=0;1===b[h]&&f(h)}return k}
function pa(e){var d=new (C?Uint16Array:Array)(e.length),c=[],f=[],a=0,b,k,m,g;b=0;for(k=e.length;b<k;b++)c[e[b]]=(c[e[b]]|0)+1;b=1;for(k=16;b<=k;b++)f[b]=a,a+=c[b]|0,a<<=1;b=0;for(k=e.length;b<k;b++){a=f[e[b]];f[e[b]]+=1;m=d[b]=0;for(g=e[b];m<g;m++)d[b]=d[b]<<1|a&1,a>>>=1}return d};ba("Zlib.RawDeflate",ka);ba("Zlib.RawDeflate.prototype.compress",ka.prototype.h);var Ka={NONE:0,FIXED:1,DYNAMIC:ma},V,La,$,Ma;if(Object.keys)V=Object.keys(Ka);else for(La in V=[],$=0,Ka)V[$++]=La;$=0;for(Ma=V.length;$<Ma;++$)La=V[$],ba("Zlib.RawDeflate.CompressionType."+La,Ka[La]);}).call(this);

View file

@ -1,14 +0,0 @@
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var k=void 0,aa=this;function r(c,d){var a=c.split("."),b=aa;!(a[0]in b)&&b.execScript&&b.execScript("var "+a[0]);for(var e;a.length&&(e=a.shift());)!a.length&&d!==k?b[e]=d:b=b[e]?b[e]:b[e]={}};var t="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function u(c){var d=c.length,a=0,b=Number.POSITIVE_INFINITY,e,f,g,h,l,n,m,p,s,x;for(p=0;p<d;++p)c[p]>a&&(a=c[p]),c[p]<b&&(b=c[p]);e=1<<a;f=new (t?Uint32Array:Array)(e);g=1;h=0;for(l=2;g<=a;){for(p=0;p<d;++p)if(c[p]===g){n=0;m=h;for(s=0;s<g;++s)n=n<<1|m&1,m>>=1;x=g<<16|p;for(s=n;s<e;s+=l)f[s]=x;++h}++g;h<<=1;l<<=1}return[f,a,b]};function w(c,d){this.g=[];this.h=32768;this.c=this.f=this.d=this.k=0;this.input=t?new Uint8Array(c):c;this.l=!1;this.i=y;this.p=!1;if(d||!(d={}))d.index&&(this.d=d.index),d.bufferSize&&(this.h=d.bufferSize),d.bufferType&&(this.i=d.bufferType),d.resize&&(this.p=d.resize);switch(this.i){case A:this.a=32768;this.b=new (t?Uint8Array:Array)(32768+this.h+258);break;case y:this.a=0;this.b=new (t?Uint8Array:Array)(this.h);this.e=this.u;this.m=this.r;this.j=this.s;break;default:throw Error("invalid inflate mode");
}}var A=0,y=1;
w.prototype.t=function(){for(;!this.l;){var c=B(this,3);c&1&&(this.l=!0);c>>>=1;switch(c){case 0:var d=this.input,a=this.d,b=this.b,e=this.a,f=d.length,g=k,h=k,l=b.length,n=k;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=d[a++]|d[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=d[a++]|d[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>d.length)throw Error("input buffer is broken");switch(this.i){case A:for(;e+g>
b.length;){n=l-e;g-=n;if(t)b.set(d.subarray(a,a+n),e),e+=n,a+=n;else for(;n--;)b[e++]=d[a++];this.a=e;b=this.e();e=this.a}break;case y:for(;e+g>b.length;)b=this.e({o:2});break;default:throw Error("invalid inflate mode");}if(t)b.set(d.subarray(a,a+g),e),e+=g,a+=g;else for(;g--;)b[e++]=d[a++];this.d=a;this.a=e;this.b=b;break;case 1:this.j(ba,ca);break;case 2:for(var m=B(this,5)+257,p=B(this,5)+1,s=B(this,4)+4,x=new (t?Uint8Array:Array)(C.length),Q=k,R=k,S=k,v=k,M=k,F=k,z=k,q=k,T=k,q=0;q<s;++q)x[C[q]]=
B(this,3);if(!t){q=s;for(s=x.length;q<s;++q)x[C[q]]=0}Q=u(x);v=new (t?Uint8Array:Array)(m+p);q=0;for(T=m+p;q<T;)switch(M=D(this,Q),M){case 16:for(z=3+B(this,2);z--;)v[q++]=F;break;case 17:for(z=3+B(this,3);z--;)v[q++]=0;F=0;break;case 18:for(z=11+B(this,7);z--;)v[q++]=0;F=0;break;default:F=v[q++]=M}R=t?u(v.subarray(0,m)):u(v.slice(0,m));S=t?u(v.subarray(m)):u(v.slice(m));this.j(R,S);break;default:throw Error("unknown BTYPE: "+c);}}return this.m()};
var E=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],C=t?new Uint16Array(E):E,G=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],H=t?new Uint16Array(G):G,I=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],J=t?new Uint8Array(I):I,K=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],L=t?new Uint16Array(K):K,N=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,
13],O=t?new Uint8Array(N):N,P=new (t?Uint8Array:Array)(288),U,da;U=0;for(da=P.length;U<da;++U)P[U]=143>=U?8:255>=U?9:279>=U?7:8;var ba=u(P),V=new (t?Uint8Array:Array)(30),W,ea;W=0;for(ea=V.length;W<ea;++W)V[W]=5;var ca=u(V);function B(c,d){for(var a=c.f,b=c.c,e=c.input,f=c.d,g=e.length,h;b<d;){if(f>=g)throw Error("input buffer is broken");a|=e[f++]<<b;b+=8}h=a&(1<<d)-1;c.f=a>>>d;c.c=b-d;c.d=f;return h}
function D(c,d){for(var a=c.f,b=c.c,e=c.input,f=c.d,g=e.length,h=d[0],l=d[1],n,m;b<l&&!(f>=g);)a|=e[f++]<<b,b+=8;n=h[a&(1<<l)-1];m=n>>>16;if(m>b)throw Error("invalid code length: "+m);c.f=a>>m;c.c=b-m;c.d=f;return n&65535}
w.prototype.j=function(c,d){var a=this.b,b=this.a;this.n=c;for(var e=a.length-258,f,g,h,l;256!==(f=D(this,c));)if(256>f)b>=e&&(this.a=b,a=this.e(),b=this.a),a[b++]=f;else{g=f-257;l=H[g];0<J[g]&&(l+=B(this,J[g]));f=D(this,d);h=L[f];0<O[f]&&(h+=B(this,O[f]));b>=e&&(this.a=b,a=this.e(),b=this.a);for(;l--;)a[b]=a[b++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=b};
w.prototype.s=function(c,d){var a=this.b,b=this.a;this.n=c;for(var e=a.length,f,g,h,l;256!==(f=D(this,c));)if(256>f)b>=e&&(a=this.e(),e=a.length),a[b++]=f;else{g=f-257;l=H[g];0<J[g]&&(l+=B(this,J[g]));f=D(this,d);h=L[f];0<O[f]&&(h+=B(this,O[f]));b+l>e&&(a=this.e(),e=a.length);for(;l--;)a[b]=a[b++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=b};
w.prototype.e=function(){var c=new (t?Uint8Array:Array)(this.a-32768),d=this.a-32768,a,b,e=this.b;if(t)c.set(e.subarray(32768,c.length));else{a=0;for(b=c.length;a<b;++a)c[a]=e[a+32768]}this.g.push(c);this.k+=c.length;if(t)e.set(e.subarray(d,d+32768));else for(a=0;32768>a;++a)e[a]=e[d+a];this.a=32768;return e};
w.prototype.u=function(c){var d,a=this.input.length/this.d+1|0,b,e,f,g=this.input,h=this.b;c&&("number"===typeof c.o&&(a=c.o),"number"===typeof c.q&&(a+=c.q));2>a?(b=(g.length-this.d)/this.n[2],f=258*(b/2)|0,e=f<h.length?h.length+f:h.length<<1):e=h.length*a;t?(d=new Uint8Array(e),d.set(h)):d=h;return this.b=d};
w.prototype.m=function(){var c=0,d=this.b,a=this.g,b,e=new (t?Uint8Array:Array)(this.k+(this.a-32768)),f,g,h,l;if(0===a.length)return t?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);f=0;for(g=a.length;f<g;++f){b=a[f];h=0;for(l=b.length;h<l;++h)e[c++]=b[h]}f=32768;for(g=this.a;f<g;++f)e[c++]=d[f];this.g=[];return this.buffer=e};
w.prototype.r=function(){var c,d=this.a;t?this.p?(c=new Uint8Array(d),c.set(this.b.subarray(0,d))):c=this.b.subarray(0,d):(this.b.length>d&&(this.b.length=d),c=this.b);return this.buffer=c};r("Zlib.RawInflate",w);r("Zlib.RawInflate.prototype.decompress",w.prototype.t);var X={ADAPTIVE:y,BLOCK:A},Y,Z,$,fa;if(Object.keys)Y=Object.keys(X);else for(Z in Y=[],$=0,X)Y[$++]=Z;$=0;for(fa=Y.length;$<fa;++$)Z=Y[$],r("Zlib.RawInflate.BufferType."+Z,X[Z]);}).call(this);

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,6 @@
* @property {Boolean} show_comment
* @property {Boolean} integrity_protect
* @property {String} keyserver
* @property {Boolean} debug If enabled, debug messages will be printed
* @module config/config
*/
@ -42,15 +41,7 @@ export default {
ignore_mdc_error: false, // fail on decrypt if message is not integrity protected
checksum_required: false, // do not throw error when armor is missing a checksum
verify_expired_keys: true, // allow signature verification with expired keys
rsa_blinding: true,
use_native: true, // use native node.js crypto and Web Crypto apis (if available)
zero_copy: false, // use transferable objects between the Web Worker and main thread
debug: false,
tolerant: true, // ignore unsupported/unrecognizable packets instead of throwing an error
show_version: true,
show_comment: true,
versionstring: "OpenPGP.js VERSION",
commentstring: "https://openpgpjs.org",
keyserver: "https://keyserver.ubuntu.com",
node_store: './openpgp.store'
keyserver: "https://keyserver.ubuntu.com"
};

View file

@ -24,7 +24,7 @@
import util from '../util.js';
import config from '../config';
import asmCrypto from '../asmcrypto.js';
import '../asmcrypto.js';
const webCrypto = util.getWebCrypto(); // no GCM support in IE11, Safari 9
export const ivLength = 12; // size of the IV in bytes
@ -43,7 +43,7 @@ export function encrypt(cipher, plaintext, key, iv) {
return Promise.reject(new Error('GCM mode supports only AES cipher'));
}
if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
return webEncrypt(plaintext, key, iv);
}
// asm.js fallback
@ -63,7 +63,7 @@ export function decrypt(cipher, ciphertext, key, iv) {
return Promise.reject(new Error('GCM mode supports only AES cipher'));
}
if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
if (webCrypto && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
return webDecrypt(ciphertext, key, iv);
}
// asm.js fallback

View file

@ -9,8 +9,8 @@
'use strict';
import sha from './sha.js';
import asmCrypto from '../../asmcrypto.js';
import Rusha from '../../rusha.js';
import '../../asmcrypto.js';
import '../../rusha.js';
import md5 from './md5.js';
import ripemd from './ripe-md.js';
import util from '../../util.js';

View file

@ -97,7 +97,6 @@ export default function DSA() {
}
return usersetting;
default:
util.print_debug("DSA select hash algorithm: returning null for an unknown length of q");
return null;
}
}
@ -110,12 +109,10 @@ export default function DSA() {
s1.compareTo(q) >= 0 ||
BigInteger.ZERO.compareTo(s2) >= 0 ||
s2.compareTo(q) >= 0) {
util.print_debug("invalid DSA Signature");
return null;
}
var w = s2.modInverse(q);
if (BigInteger.ZERO.compareTo(w) === 0) {
util.print_debug("invalid DSA Signature");
return null;
}
var u1 = hash.multiply(w).mod(q);

View file

@ -44,10 +44,6 @@ export default function Elgamal() {
}
function decrypt(c1, c2, p, x) {
util.print_debug("Elgamal Decrypt:\nc1:" + util.hexstrdump(c1.toMPI()) + "\n" +
"c2:" + util.hexstrdump(c2.toMPI()) + "\n" +
"p:" + util.hexstrdump(p.toMPI()) + "\n" +
"x:" + util.hexstrdump(x.toMPI()));
return (c1.modPow(x, p).modInverse(p)).multiply(c2).mod(p);
//var c = c1.pow(x).modInverse(p); // c0^-a mod p
//return c.multiply(c2).mod(p);

View file

@ -77,12 +77,9 @@ export default function RSA() {
* @return {BigInteger} The decrypted value of the message
*/
function decrypt(m, n, e, d, p, q, u) {
if (config.rsa_blinding) {
m = blind(m, n, e);
}
m = blind(m, n, e);
var xp = m.mod(p).modPow(d.mod(p.subtract(BigInteger.ONE)), p);
var xq = m.mod(q).modPow(d.mod(q.subtract(BigInteger.ONE)), q);
util.print_debug("rsa.js decrypt\nxpn:" + util.hexstrdump(xp.toMPI()) + "\nxqn:" + util.hexstrdump(xq.toMPI()));
var t = xq.subtract(xp);
if (t[0] === 0) {
@ -93,9 +90,7 @@ export default function RSA() {
t = t.multiply(u).mod(q);
}
t = t.multiply(p).add(xp);
if (config.rsa_blinding) {
t = unblind(t, n);
}
t = unblind(t, n);
return t;
}

View file

@ -95,27 +95,6 @@ function getType(text) {
}
}
/**
* Add additional information to the armor version of an OpenPGP binary
* packet block.
* @author Alex
* @version 2011-12-16
* @returns {String} The header information
*/
function addheader() {
var result = "";
if (config.show_version) {
result += "Version: " + config.versionstring + '\r\n';
}
if (config.show_comment) {
result += "Comment: " + config.commentstring + '\r\n';
}
result += '\r\n';
return result;
}
/**
* Calculates a checksum over the given data and returns it base64 encoded
* @param {String} data Data to create a CRC-24 checksum for
@ -227,9 +206,6 @@ function verifyHeaders(headers) {
if (!/^([^\s:]|[^\s:][^:]*[^\s:]): .+$/.test(headers[i])) {
throw new Error('Improperly formatted armor header: ' + headers[i]);
}
if (config.debug && !/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) {
console.log('Unknown header: ' + headers[i]);
}
}
}
@ -338,14 +314,12 @@ function armor(messagetype, body, partindex, parttotal) {
switch (messagetype) {
case enums.armor.multipart_section:
result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n");
result.push(addheader());
result.push(base64.encode(body));
result.push("\r\n=" + getCheckSum(body) + "\r\n");
result.push("-----END PGP MESSAGE, PART " + partindex + "/" + parttotal + "-----\r\n");
break;
case enums.armor.multipart_last:
result.push("-----BEGIN PGP MESSAGE, PART " + partindex + "-----\r\n");
result.push(addheader());
result.push(base64.encode(body));
result.push("\r\n=" + getCheckSum(body) + "\r\n");
result.push("-----END PGP MESSAGE, PART " + partindex + "-----\r\n");
@ -355,35 +329,30 @@ function armor(messagetype, body, partindex, parttotal) {
result.push("Hash: " + body.hash + "\r\n\r\n");
result.push(body.text.replace(/\n-/g, "\n- -"));
result.push("\r\n-----BEGIN PGP SIGNATURE-----\r\n");
result.push(addheader());
result.push(base64.encode(body.data));
result.push("\r\n=" + getCheckSum(body.data) + "\r\n");
result.push("-----END PGP SIGNATURE-----\r\n");
break;
case enums.armor.message:
result.push("-----BEGIN PGP MESSAGE-----\r\n");
result.push(addheader());
result.push(base64.encode(body));
result.push("\r\n=" + getCheckSum(body) + "\r\n");
result.push("-----END PGP MESSAGE-----\r\n");
break;
case enums.armor.public_key:
result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\r\n");
result.push(addheader());
result.push(base64.encode(body));
result.push("\r\n=" + getCheckSum(body) + "\r\n");
result.push("-----END PGP PUBLIC KEY BLOCK-----\r\n\r\n");
break;
case enums.armor.private_key:
result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\r\n");
result.push(addheader());
result.push(base64.encode(body));
result.push("\r\n=" + getCheckSum(body) + "\r\n");
result.push("-----END PGP PRIVATE KEY BLOCK-----\r\n");
break;
case enums.armor.signature:
result.push("-----BEGIN PGP SIGNATURE-----\r\n");
result.push(addheader());
result.push(base64.encode(body));
result.push("\r\n=" + getCheckSum(body) + "\r\n");
result.push("-----END PGP SIGNATURE-----\r\n");

View file

@ -91,7 +91,6 @@ Key.prototype.packetlist2structure = function(packetlist) {
case enums.signature.cert_casual:
case enums.signature.cert_positive:
if (!user) {
util.print_debug('Dropping certification signatures without preceding user packet');
continue;
}
if (packetlist[i].issuerKeyId.equals(primaryKeyId)) {
@ -127,7 +126,6 @@ Key.prototype.packetlist2structure = function(packetlist) {
break;
case enums.signature.subkey_binding:
if (!subKey) {
util.print_debug('Dropping subkey binding signature without preceding subkey packet');
continue;
}
subKey.bindingSignatures.push(packetlist[i]);
@ -137,7 +135,6 @@ Key.prototype.packetlist2structure = function(packetlist) {
break;
case enums.signature.subkey_revocation:
if (!subKey) {
util.print_debug('Dropping subkey revocation signature without preceding subkey packet');
continue;
}
subKey.revocationSignature = packetlist[i];

View file

@ -36,8 +36,6 @@ function loadKeys(storage, itemname) {
key = keyModule.readArmored(armoredKeys[i]);
if (!key.err) {
keys.push(key.keys[0]);
} else {
util.print_debug("Error reading armored key from keyring index: " + i);
}
}
}

View file

@ -551,9 +551,6 @@ function execute(cmd, message) {
* @param {Error} error The internal error that caused the failure
*/
function onError(message, error) {
// log the stack trace
if (config.debug) { console.error(error.stack); }
// update error message
error.message = message + ': ' + error.message;

View file

@ -33,131 +33,128 @@
import enums from '../enums.js';
import util from '../util.js';
import Zlib from '../compression/zlib.min.js';
import RawInflate from '../compression/rawinflate.min.js';
import RawDeflate from '../compression/rawdeflate.min.js';
import '../compression/zlib.min.js';
/**
* @constructor
*/
export default function Compressed() {
/**
* Packet type
* @type {module:enums.packet}
*/
this.tag = enums.packet.compressed;
/**
* List of packets
* @type {module:packet/packetlist}
*/
this.packets = null;
/**
* Compression algorithm
* @type {compression}
*/
this.algorithm = 'zip';
export default class Compressed
{
constructor()
{
/**
* Packet type
* @type {module:enums.packet}
*/
this.tag = enums.packet.compressed;
/**
* List of packets
* @type {module:packet/packetlist}
*/
this.packets = null;
/**
* Compression algorithm
* @type {compression}
*/
this.algorithm = 'zip';
/**
* Compressed packet data
* @type {String}
*/
this.compressed = null;
}
/**
* Compressed packet data
* @type {String}
* Parsing function for the packet.
* @param {String} bytes Payload of a tag 8 packet
*/
this.compressed = null;
read(bytes) {
// One octet that gives the algorithm used to compress the packet.
this.algorithm = enums.read(enums.compression, bytes[0]);
// Compressed data, which makes up the remainder of the packet.
this.compressed = bytes.subarray(1, bytes.length);
this.decompress();
}
/**
* Return the compressed packet.
* @return {String} binary compressed packet
*/
write() {
if (this.compressed === null) {
this.compress();
}
return util.concatUint8Array(new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed);
}
/**
* Decompression method for decompressing the compressed data
* read by read_packet
*/
decompress() {
var decompressed;
switch (this.algorithm) {
case 'uncompressed':
decompressed = this.compressed;
break;
case 'zip':
decompressed = (new Zlib.RawInflate(this.compressed)).decompress();
break;
case 'zlib':
decompressed = (new Zlib.Inflate(this.compressed)).decompress();
break;
case 'bzip2':
// TODO: need to implement this
throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
default:
throw new Error("Compression algorithm unknown :" + this.algorithm);
}
this.packets.read(decompressed);
}
/**
* Compress the packet data (member decompressedData)
*/
compress() {
var uncompressed = this.packets.write();
switch (this.algorithm) {
case 'uncompressed':
// - Uncompressed
this.compressed = uncompressed;
break;
case 'zip':
// - ZIP [RFC1951]
this.compressed = (new Zlib.RawDeflate(uncompressed)).compress();
break;
case 'zlib':
// - ZLIB [RFC1950]
this.compressed = (new Zlib.Deflate(uncompressed)).compress();
break;
case 'bzip2':
// - BZip2 [BZ2]
// TODO: need to implement this
throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
default:
throw new Error("Compression algorithm unknown :" + this.type);
}
}
}
/**
* Parsing function for the packet.
* @param {String} bytes Payload of a tag 8 packet
*/
Compressed.prototype.read = function (bytes) {
// One octet that gives the algorithm used to compress the packet.
this.algorithm = enums.read(enums.compression, bytes[0]);
// Compressed data, which makes up the remainder of the packet.
this.compressed = bytes.subarray(1, bytes.length);
this.decompress();
};
/**
* Return the compressed packet.
* @return {String} binary compressed packet
*/
Compressed.prototype.write = function () {
if (this.compressed === null) {
this.compress();
}
return util.concatUint8Array(new Uint8Array([enums.write(enums.compression, this.algorithm)]), this.compressed);
};
/**
* Decompression method for decompressing the compressed data
* read by read_packet
*/
Compressed.prototype.decompress = function () {
var decompressed, inflate;
switch (this.algorithm) {
case 'uncompressed':
decompressed = this.compressed;
break;
case 'zip':
inflate = new RawInflate.Zlib.RawInflate(this.compressed);
decompressed = inflate.decompress();
break;
case 'zlib':
inflate = new Zlib.Zlib.Inflate(this.compressed);
decompressed = inflate.decompress();
break;
case 'bzip2':
// TODO: need to implement this
throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
default:
throw new Error("Compression algorithm unknown :" + this.algorithm);
}
this.packets.read(decompressed);
};
/**
* Compress the packet data (member decompressedData)
*/
Compressed.prototype.compress = function () {
var uncompressed, deflate;
uncompressed = this.packets.write();
switch (this.algorithm) {
case 'uncompressed':
// - Uncompressed
this.compressed = uncompressed;
break;
case 'zip':
// - ZIP [RFC1951]
deflate = new RawDeflate.Zlib.RawDeflate(uncompressed);
this.compressed = deflate.compress();
break;
case 'zlib':
// - ZLIB [RFC1950]
deflate = new Zlib.Zlib.Deflate(uncompressed);
this.compressed = deflate.compress();
break;
case 'bzip2':
// - BZip2 [BZ2]
// TODO: need to implement this
throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
default:
throw new Error("Compression algorithm unknown :" + this.type);
}
};

View file

@ -185,15 +185,12 @@ export default {
// 4.2.2.1. One-Octet Lengths
if (input[mypos] < 192) {
packet_length = input[mypos++];
util.print_debug("1 byte length:" + packet_length);
// 4.2.2.2. Two-Octet Lengths
} else if (input[mypos] >= 192 && input[mypos] < 224) {
packet_length = ((input[mypos++] - 192) << 8) + (input[mypos++]) + 192;
util.print_debug("2 byte length:" + packet_length);
// 4.2.2.4. Partial Body Lengths
} else if (input[mypos] > 223 && input[mypos] < 255) {
packet_length = 1 << (input[mypos++] & 0x1F);
util.print_debug("4 byte length:" + packet_length);
// EEEK, we're reading the full data here...
var mypos2 = mypos + packet_length;
bodydata = [input.subarray(mypos, mypos + packet_length)];

View file

@ -100,13 +100,6 @@ Signature.prototype.read = function (bytes) {
// switch on version (3 and 4)
switch (this.version) {
case 3:
// One-octet length of following hashed material. MUST be 5.
if (bytes[i++] !== 5) {
util.print_debug("packet/signature.js\n" +
'invalid One-octet length of following hashed material.' +
'MUST be 5. @:' + (i - 1));
}
var sigpos = i;
// One-octet signature type.
this.signatureType = bytes[i++];
@ -463,8 +456,6 @@ Signature.prototype.read_sub_packet = function (bytes) {
this.notation = this.notation || {};
this.notation[name] = value;
} else {
util.print_debug("Unsupported notation flag "+bytes[mypos]);
}
break;
case 21:
@ -523,8 +514,6 @@ Signature.prototype.read_sub_packet = function (bytes) {
this.embeddedSignature = new Signature();
this.embeddedSignature.read(bytes.subarray(mypos, bytes.length));
break;
default:
util.print_debug("Unknown signature subpacket type " + type + " @:" + mypos);
}
};

View file

@ -37,7 +37,7 @@
import util from '../util.js';
import crypto from '../crypto';
import enums from '../enums.js';
import asmCrypto from '../asmcrypto.js';
import '../asmcrypto.js';
const VERSION = 1; // A one-octet version number of the data packet.

410
vendors/openpgp-2.6.2/src/rusha.js vendored Normal file
View file

@ -0,0 +1,410 @@
(w => {
'use strict';
// The low-level RushCore module provides the heart of Rusha,
// a high-speed sha1 implementation working on an Int32Array heap.
// At first glance, the implementation seems complicated, however
// with the SHA1 spec at hand, it is obvious this almost a textbook
// implementation that has a few functions hand-inlined and a few loops
// hand-unrolled.
function RushaCore(stdlib$840, foreign$841, heap$842) {
'use asm';
let H$843 = new stdlib$840.Int32Array(heap$842);
function hash$844(k$845, x$846) {
// k in bytes
k$845 = k$845 | 0;
x$846 = x$846 | 0;
let i$847 = 0, j$848 = 0, y0$849 = 0, z0$850 = 0, y1$851 = 0, z1$852 = 0, y2$853 = 0, z2$854 = 0, y3$855 = 0, z3$856 = 0, y4$857 = 0, z4$858 = 0, t0$859 = 0, t1$860 = 0;
y0$849 = H$843[x$846 + 320 >> 2] | 0;
y1$851 = H$843[x$846 + 324 >> 2] | 0;
y2$853 = H$843[x$846 + 328 >> 2] | 0;
y3$855 = H$843[x$846 + 332 >> 2] | 0;
y4$857 = H$843[x$846 + 336 >> 2] | 0;
for (i$847 = 0; (i$847 | 0) < (k$845 | 0); i$847 = i$847 + 64 | 0) {
z0$850 = y0$849;
z1$852 = y1$851;
z2$854 = y2$853;
z3$856 = y3$855;
z4$858 = y4$857;
for (j$848 = 0; (j$848 | 0) < 64; j$848 = j$848 + 4 | 0) {
t1$860 = H$843[i$847 + j$848 >> 2] | 0;
t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 & y2$853 | ~y1$851 & y3$855) | 0) + ((t1$860 + y4$857 | 0) + 1518500249 | 0) | 0;
y4$857 = y3$855;
y3$855 = y2$853;
y2$853 = y1$851 << 30 | y1$851 >>> 2;
y1$851 = y0$849;
y0$849 = t0$859;
H$843[k$845 + j$848 >> 2] = t1$860;
}
for (j$848 = k$845 + 64 | 0; (j$848 | 0) < (k$845 + 80 | 0); j$848 = j$848 + 4 | 0) {
t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31;
t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 & y2$853 | ~y1$851 & y3$855) | 0) + ((t1$860 + y4$857 | 0) + 1518500249 | 0) | 0;
y4$857 = y3$855;
y3$855 = y2$853;
y2$853 = y1$851 << 30 | y1$851 >>> 2;
y1$851 = y0$849;
y0$849 = t0$859;
H$843[j$848 >> 2] = t1$860;
}
for (j$848 = k$845 + 80 | 0; (j$848 | 0) < (k$845 + 160 | 0); j$848 = j$848 + 4 | 0) {
t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31;
t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 ^ y2$853 ^ y3$855) | 0) + ((t1$860 + y4$857 | 0) + 1859775393 | 0) | 0;
y4$857 = y3$855;
y3$855 = y2$853;
y2$853 = y1$851 << 30 | y1$851 >>> 2;
y1$851 = y0$849;
y0$849 = t0$859;
H$843[j$848 >> 2] = t1$860;
}
for (j$848 = k$845 + 160 | 0; (j$848 | 0) < (k$845 + 240 | 0); j$848 = j$848 + 4 | 0) {
t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31;
t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 & y2$853 | y1$851 & y3$855 | y2$853 & y3$855) | 0) + ((t1$860 + y4$857 | 0) - 1894007588 | 0) | 0;
y4$857 = y3$855;
y3$855 = y2$853;
y2$853 = y1$851 << 30 | y1$851 >>> 2;
y1$851 = y0$849;
y0$849 = t0$859;
H$843[j$848 >> 2] = t1$860;
}
for (j$848 = k$845 + 240 | 0; (j$848 | 0) < (k$845 + 320 | 0); j$848 = j$848 + 4 | 0) {
t1$860 = (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) << 1 | (H$843[j$848 - 12 >> 2] ^ H$843[j$848 - 32 >> 2] ^ H$843[j$848 - 56 >> 2] ^ H$843[j$848 - 64 >> 2]) >>> 31;
t0$859 = ((y0$849 << 5 | y0$849 >>> 27) + (y1$851 ^ y2$853 ^ y3$855) | 0) + ((t1$860 + y4$857 | 0) - 899497514 | 0) | 0;
y4$857 = y3$855;
y3$855 = y2$853;
y2$853 = y1$851 << 30 | y1$851 >>> 2;
y1$851 = y0$849;
y0$849 = t0$859;
H$843[j$848 >> 2] = t1$860;
}
y0$849 = y0$849 + z0$850 | 0;
y1$851 = y1$851 + z1$852 | 0;
y2$853 = y2$853 + z2$854 | 0;
y3$855 = y3$855 + z3$856 | 0;
y4$857 = y4$857 + z4$858 | 0;
}
H$843[x$846 + 320 >> 2] = y0$849;
H$843[x$846 + 324 >> 2] = y1$851;
H$843[x$846 + 328 >> 2] = y2$853;
H$843[x$846 + 332 >> 2] = y3$855;
H$843[x$846 + 336 >> 2] = y4$857;
}
return { hash: hash$844 };
}
var core = /*#__PURE__*/Object.freeze({
__proto__: null,
RushaCore: RushaCore
});
/* eslint-env commonjs, browser */
//
// toHex
//
const precomputedHex = new Array(256);
for (let i = 0; i < 256; i++) {
precomputedHex[i] = (i < 0x10 ? '0' : '') + i.toString(16);
}
var toHex = (arrayBuffer) => {
const binarray = new Uint8Array(arrayBuffer);
const res = new Array(arrayBuffer.byteLength);
for (let i = 0; i < res.length; i++) {
res[i] = precomputedHex[binarray[i]];
}
return res.join('');
};
//
// ceilHeapSize
//
var ceilHeapSize = (v) => {
// The asm.js spec says:
// The heap object's byteLength must be either
// 2^n for n in [12, 24) or 2^24 * n for n ≥ 1.
// Also, byteLengths smaller than 2^16 are deprecated.
let p = 0;
// If v is smaller than 2^16, the smallest possible solution
// is 2^16.
if (v <= 65536) return 65536;
// If v < 2^24, we round up to 2^n,
// otherwise we round up to 2^24 * n.
if (v < 16777216) {
for (p = 1; p < v; p = p << 1);
} else {
for (p = 16777216; p < v; p += 16777216);
}
return p;
};
//
// isDedicatedWorkerScope
//
var isDedicatedWorkerScope = (self) => {
const isRunningInWorker = 'WorkerGlobalScope' in self
&& self instanceof self.WorkerGlobalScope;
const isRunningInSharedWorker = 'SharedWorkerGlobalScope' in self
&& self instanceof self.SharedWorkerGlobalScope;
const isRunningInServiceWorker = 'ServiceWorkerGlobalScope' in self
&& self instanceof self.ServiceWorkerGlobalScope;
// Detects whether we run inside a dedicated worker or not.
//
// We can't just check for `DedicatedWorkerGlobalScope`, since IE11
// has a bug where it only supports `WorkerGlobalScope`.
//
// Therefore, we consider us as running inside a dedicated worker
// when we are running inside a worker, but not in a shared or service worker.
//
// When new types of workers are introduced, we will need to adjust this code.
return isRunningInWorker
&& !isRunningInSharedWorker
&& !isRunningInServiceWorker;
};
var utils = {
toHex: toHex,
ceilHeapSize: ceilHeapSize,
isDedicatedWorkerScope: isDedicatedWorkerScope
};
/* eslint-env commonjs, browser */
let reader;
if (typeof self !== 'undefined' && typeof self.FileReaderSync !== 'undefined') {
reader = new self.FileReaderSync();
}
// Convert a binary string and write it to the heap.
// A binary string is expected to only contain char codes < 256.
const convStr = (str, H8, H32, start, len, off) => {
let i, om = off % 4, lm = (len + om) % 4, j = len - lm;
switch (om) {
case 0: H8[off] = str.charCodeAt(start+3);
case 1: H8[off+1-(om<<1)|0] = str.charCodeAt(start+2);
case 2: H8[off+2-(om<<1)|0] = str.charCodeAt(start+1);
case 3: H8[off+3-(om<<1)|0] = str.charCodeAt(start);
}
if (len < lm + (4-om)) {
return;
}
for (i = 4 - om; i < j; i = i + 4 | 0) {
H32[off+i>>2] = str.charCodeAt(start+i) << 24 |
str.charCodeAt(start+i+1) << 16 |
str.charCodeAt(start+i+2) << 8 |
str.charCodeAt(start+i+3);
}
switch (lm) {
case 3: H8[off+j+1|0] = str.charCodeAt(start+j+2);
case 2: H8[off+j+2|0] = str.charCodeAt(start+j+1);
case 1: H8[off+j+3|0] = str.charCodeAt(start+j);
}
};
// Convert a buffer or array and write it to the heap.
// The buffer or array is expected to only contain elements < 256.
const convBuf = (buf, H8, H32, start, len, off) => {
let i, om = off % 4, lm = (len + om) % 4, j = len - lm;
switch (om) {
case 0: H8[off] = buf[start + 3];
case 1: H8[off+1-(om<<1)|0] = buf[start+2];
case 2: H8[off+2-(om<<1)|0] = buf[start+1];
case 3: H8[off+3-(om<<1)|0] = buf[start];
}
if (len < lm + (4-om)) {
return;
}
for (i = 4 - om; i < j; i = i + 4 | 0) {
H32[off+i>>2|0] = buf[start+i] << 24 |
buf[start+i+1] << 16 |
buf[start+i+2] << 8 |
buf[start+i+3];
}
switch (lm) {
case 3: H8[off+j+1|0] = buf[start+j+2];
case 2: H8[off+j+2|0] = buf[start+j+1];
case 1: H8[off+j+3|0] = buf[start+j];
}
};
const convBlob = (blob, H8, H32, start, len, off) => {
let i, om = off % 4, lm = (len + om) % 4, j = len - lm;
const buf = new Uint8Array(reader.readAsArrayBuffer(blob.slice(start, start + len)));
switch (om) {
case 0: H8[off] = buf[3];
case 1: H8[off+1-(om<<1)|0] = buf[2];
case 2: H8[off+2-(om<<1)|0] = buf[1];
case 3: H8[off+3-(om<<1)|0] = buf[0];
}
if (len < lm + (4-om)) {
return;
}
for (i = 4 - om; i < j; i = i + 4 | 0) {
H32[off+i>>2|0] = buf[i] << 24 |
buf[i+1] << 16 |
buf[i+2] << 8 |
buf[i+3];
}
switch (lm) {
case 3: H8[off+j+1|0] = buf[j + 2];
case 2: H8[off+j+2|0] = buf[j + 1];
case 1: H8[off+j+3|0] = buf[j];
}
};
var conv = (data, H8, H32, start, len, off) => {
if (typeof data === 'string') {
return convStr(data, H8, H32, start, len, off);
}
if (data instanceof Array) {
return convBuf(data, H8, H32, start, len, off);
}
// Safely doing a Buffer check using "this" to avoid Buffer polyfill to be included in the dist
if ((self||window).Buffer && Buffer.isBuffer(data)) {
return convBuf(data, H8, H32, start, len, off);
}
if (data instanceof ArrayBuffer) {
return convBuf(new Uint8Array(data), H8, H32, start, len, off);
}
if (data.buffer instanceof ArrayBuffer) {
return convBuf(new Uint8Array(data.buffer, data.byteOffset, data.byteLength), H8, H32, start, len, off);
}
if (data instanceof Blob) {
return convBlob(data, H8, H32, start, len, off);
}
throw new Error('Unsupported data type.');
};
function getAugmentedNamespace(n) {
if (n.__esModule) return n;
var a = Object.defineProperty({}, '__esModule', {value: true});
Object.keys(n).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(n, k);
Object.defineProperty(a, k, d.get ? d : {
enumerable: true,
get: function () {
return n[k];
}
});
});
return a;
}
var RushaCore$1 = /*@__PURE__*/getAugmentedNamespace(core);
/* eslint-env commonjs, browser */
const {toHex: toHex$1, ceilHeapSize: ceilHeapSize$1} = utils;
// Calculate the length of buffer that the sha1 routine uses
// including the padding.
const padlen = (len) => {
for (len += 9; len % 64 > 0; len += 1);
return len;
};
const padZeroes = (bin, len) => {
const h8 = new Uint8Array(bin.buffer);
const om = len % 4, align = len - om;
switch (om) {
case 0: h8[align + 3] = 0;
case 1: h8[align + 2] = 0;
case 2: h8[align + 1] = 0;
case 3: h8[align + 0] = 0;
}
for (let i = (len >> 2) + 1; i < bin.length; i++) {
bin[i] = 0;
}
};
const padData = (bin, chunkLen, msgLen) => {
bin[chunkLen>>2] |= 0x80 << (24 - (chunkLen % 4 << 3));
// To support msgLen >= 2 GiB, use a float division when computing the
// high 32-bits of the big-endian message length in bits.
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 14] = (msgLen / (1 << 29)) |0;
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 15] = msgLen << 3;
};
const getRawDigest = (heap, padMaxChunkLen) => {
const io = new Int32Array(heap, padMaxChunkLen + 320, 5);
const out = new Int32Array(5);
const arr = new DataView(out.buffer);
arr.setInt32(0, io[0], false);
arr.setInt32(4, io[1], false);
arr.setInt32(8, io[2], false);
arr.setInt32(12, io[3], false);
arr.setInt32(16, io[4], false);
return out;
};
class Rusha {
constructor(chunkSize) {
chunkSize = chunkSize || 64 * 1024;
if (chunkSize % 64 > 0) {
throw new Error('Chunk size must be a multiple of 128 bit');
}
this._offset = 0;
this._maxChunkLen = chunkSize;
this._padMaxChunkLen = padlen(chunkSize);
// The size of the heap is the sum of:
// 1. The padded input message size
// 2. The extended space the algorithm needs (320 byte)
// 3. The 160 bit state the algoritm uses
this._heap = new ArrayBuffer(ceilHeapSize$1(this._padMaxChunkLen + 320 + 20));
this._h32 = new Int32Array(this._heap);
this._h8 = new Int8Array(this._heap);
this._core = new RushaCore$1({Int32Array: Int32Array}, {}, this._heap);
}
_initState(heap, padMsgLen) {
this._offset = 0;
const io = new Int32Array(heap, padMsgLen + 320, 5);
io[0] = 1732584193;
io[1] = -271733879;
io[2] = -1732584194;
io[3] = 271733878;
io[4] = -1009589776;
}
_padChunk(chunkLen, msgLen) {
const padChunkLen = padlen(chunkLen);
const view = new Int32Array(this._heap, 0, padChunkLen >> 2);
padZeroes(view, chunkLen);
padData(view, chunkLen, msgLen);
return padChunkLen;
}
_write(data, chunkOffset, chunkLen, off) {
conv(data, this._h8, this._h32, chunkOffset, chunkLen, off || 0);
}
_coreCall(data, chunkOffset, chunkLen, msgLen, finalize) {
let padChunkLen = chunkLen;
this._write(data, chunkOffset, chunkLen);
if (finalize) {
padChunkLen = this._padChunk(chunkLen, msgLen);
}
this._core.hash(padChunkLen, this._padMaxChunkLen);
}
rawDigest(str) {
const msgLen = str.byteLength || str.length || str.size || 0;
this._initState(this._heap, this._padMaxChunkLen);
let chunkOffset = 0, chunkLen = this._maxChunkLen;
for (chunkOffset = 0; msgLen > chunkOffset + chunkLen; chunkOffset += chunkLen) {
this._coreCall(str, chunkOffset, chunkLen, msgLen, false);
}
this._coreCall(str, chunkOffset, msgLen - chunkOffset, msgLen, true);
return getRawDigest(this._heap, this._padMaxChunkLen);
}
digest(str) {
return toHex$1(this.rawDigest(str).buffer);
}
}
w.Rusha = Rusha;
})(this);

View file

@ -360,32 +360,6 @@ export default {
return checksum.s;
},
/**
* Helper function to print a debug message. Debug
* messages are only printed if
* @link module:config/config.debug is set to true.
* @param {String} str String of the debug message
*/
print_debug: function (str) {
if (config.debug) {
console.log(str);
}
},
/**
* Helper function to print a debug message. Debug
* messages are only printed if
* @link module:config/config.debug is set to true.
* Different than print_debug because will call hexstrdump iff necessary.
* @param {String} str String of the debug message
*/
print_debug_hexstr_dump: function (str, strToHex) {
if (config.debug) {
str = str + this.hexstrdump(strToHex);
console.log(str);
}
},
getLeftNBits: function (string, bitcount) {
var rest = bitcount % 8;
if (rest === 0) {
@ -444,24 +418,18 @@ export default {
/**
* Get native Web Cryptography api, only the current version of the spec.
* The default configuration is to use the api when available. But it can
* be deactivated with config.use_native
* The default configuration is to use the api when available.
* @return {Object} The SubtleCrypto api or 'undefined'
*/
getWebCrypto: () => config.use_native && browser && browser.crypto && browser.crypto.subtle,
getWebCrypto: () => browser && browser.crypto && browser.crypto.subtle,
/**
* Get native Web Cryptography api for all browsers, including legacy
* implementations of the spec e.g IE11 and Safari 8/9. The default
* configuration is to use the api when available. But it can be deactivated
* with config.use_native
* configuration is to use the api when available.
* @return {Object} The SubtleCrypto api or 'undefined'
*/
getWebCryptoAll: function() {
if (!config.use_native) {
return;
}
if (browser) {
if (browser.crypto) {
return browser.crypto.subtle || browser.crypto.webkitSubtle;