openpgp
Version:
OpenPGP.js is a Javascript implementation of the OpenPGP protocol. This is defined in RFC 4880.
4 lines (3 loc) • 10.7 kB
JavaScript
/*! OpenPGP.js v6.1.0 - 2025-01-30 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(r){if("default"!==r&&!(r in t)){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}}))})),Object.freeze(t)}var e=[0,1,3,7,15,31,63,127,255],r=function(t){this.stream=t,this.bitOffset=0,this.curByte=0,this.hasByte=!1};r.prototype._ensureByte=function(){this.hasByte||(this.curByte=this.stream.readByte(),this.hasByte=!0)},r.prototype.read=function(t){for(var r=0;t>0;){this._ensureByte();var i=8-this.bitOffset;if(t>=i)r<<=i,r|=e[i]&this.curByte,this.hasByte=!1,this.bitOffset=0,t-=i;else{r<<=t;var n=i-t;r|=(this.curByte&e[t]<<n)>>n,this.bitOffset+=t,t=0}}return r},r.prototype.seek=function(t){var e=t%8,r=(t-e)/8;this.bitOffset=e,this.stream.seek(r),this.hasByte=!1},r.prototype.pi=function(){var t,e=new Uint8Array(6);for(t=0;t<e.length;t++)e[t]=this.read(8);return function(t){return Array.prototype.map.call(t,(t=>("00"+t.toString(16)).slice(-2))).join("")}(e)};var i=r,n=function(){};n.prototype.readByte=function(){throw Error("abstract method readByte() not implemented")},n.prototype.read=function(t,e,r){for(var i=0;i<r;){var n=this.readByte();if(n<0)return 0===i?-1:i;t[e++]=n,i++}return i},n.prototype.seek=function(t){throw Error("abstract method seek() not implemented")},n.prototype.writeByte=function(t){throw Error("abstract method readByte() not implemented")},n.prototype.write=function(t,e,r){var i;for(i=0;i<r;i++)this.writeByte(t[e++]);return r},n.prototype.flush=function(){};var o,a=n,s=(o=new Uint32Array([0,79764919,159529838,222504665,319059676,398814059,445009330,507990021,638119352,583659535,797628118,726387553,890018660,835552979,1015980042,944750013,1276238704,1221641927,1167319070,1095957929,1595256236,1540665371,1452775106,1381403509,1780037320,1859660671,1671105958,1733955601,2031960084,2111593891,1889500026,1952343757,2552477408,2632100695,2443283854,2506133561,2334638140,2414271883,2191915858,2254759653,3190512472,3135915759,3081330742,3009969537,2905550212,2850959411,2762807018,2691435357,3560074640,3505614887,3719321342,3648080713,3342211916,3287746299,3467911202,3396681109,4063920168,4143685023,4223187782,4286162673,3779000052,3858754371,3904687514,3967668269,881225847,809987520,1023691545,969234094,662832811,591600412,771767749,717299826,311336399,374308984,453813921,533576470,25881363,88864420,134795389,214552010,2023205639,2086057648,1897238633,1976864222,1804852699,1867694188,1645340341,1724971778,1587496639,1516133128,1461550545,1406951526,1302016099,1230646740,1142491917,1087903418,2896545431,2825181984,2770861561,2716262478,3215044683,3143675388,3055782693,3001194130,2326604591,2389456536,2200899649,2280525302,2578013683,2640855108,2418763421,2498394922,3769900519,3832873040,3912640137,3992402750,4088425275,4151408268,4197601365,4277358050,3334271071,3263032808,3476998961,3422541446,3585640067,3514407732,3694837229,3640369242,1762451694,1842216281,1619975040,1682949687,2047383090,2127137669,1938468188,2001449195,1325665622,1271206113,1183200824,1111960463,1543535498,1489069629,1434599652,1363369299,622672798,568075817,748617968,677256519,907627842,853037301,1067152940,995781531,51762726,131386257,177728840,240578815,269590778,349224269,429104020,491947555,4046411278,4126034873,4172115296,4234965207,3794477266,3874110821,3953728444,4016571915,3609705398,3555108353,3735388376,3664026991,3290680682,3236090077,3449943556,3378572211,3174993278,3120533705,3032266256,2961025959,2923101090,2868635157,2813903052,2742672763,2604032198,2683796849,2461293480,2524268063,2284983834,2364738477,2175806836,2238787779,1569362073,1498123566,1409854455,1355396672,1317987909,1246755826,1192025387,1137557660,2072149281,2135122070,1912620623,1992383480,1753615357,1816598090,1627664531,1707420964,295390185,358241886,404320391,483945776,43990325,106832002,186451547,266083308,932423249,861060070,1041341759,986742920,613929101,542559546,756411363,701822548,3316196985,3244833742,3425377559,3370778784,3601682597,3530312978,3744426955,3689838204,3819031489,3881883254,3928223919,4007849240,4037393693,4100235434,4180117107,4259748804,2310601993,2373574846,2151335527,2231098320,2596047829,2659030626,2470359227,2550115596,2947551409,2876312838,2788305887,2733848168,3165939309,3094707162,3040238851,2985771188]),function(){var t=4294967295;this.getCRC=function(){return~t>>>0},this.updateCRC=function(e){t=t<<8^o[255&(t>>>24^e)]},this.updateCRCRun=function(e,r){for(;r-- >0;)t=t<<8^o[255&(t>>>24^e)]}}),f=i,u=a,h=s,p=function(t,e){var r,i=t[e];for(r=e;r>0;r--)t[r]=t[r-1];return t[0]=i,i},d={OK:0,LAST_BLOCK:-1,NOT_BZIP_DATA:-2,UNEXPECTED_INPUT_EOF:-3,UNEXPECTED_OUTPUT_EOF:-4,DATA_ERROR:-5,OUT_OF_MEMORY:-6,OBSOLETE_INPUT:-7,END_OF_BLOCK:-8},c={};c[d.LAST_BLOCK]="Bad file checksum",c[d.NOT_BZIP_DATA]="Not bzip data",c[d.UNEXPECTED_INPUT_EOF]="Unexpected input EOF",c[d.UNEXPECTED_OUTPUT_EOF]="Unexpected output EOF",c[d.DATA_ERROR]="Data error",c[d.OUT_OF_MEMORY]="Out of memory",c[d.OBSOLETE_INPUT]="Obsolete (pre 0.9.5) bzip format not supported.";var _=function(t,e){var r=c[t]||"unknown error";e&&(r+=": "+e);var i=new TypeError(r);throw i.errorCode=t,i},b=function(t,e){this.writePos=this.writeCurrent=this.writeCount=0,this._start_bunzip(t,e)};b.prototype._init_block=function(){return this._get_next_block()?(this.blockCRC=new h,!0):(this.writeCount=-1,!1)},b.prototype._start_bunzip=function(t,e){var r=new Uint8Array(4);4===t.read(r,0,4)&&"BZh"===String.fromCharCode(r[0],r[1],r[2])||_(d.NOT_BZIP_DATA,"bad magic");var i=r[3]-48;(i<1||i>9)&&_(d.NOT_BZIP_DATA,"level out of range"),this.reader=new f(t),this.dbufSize=1e5*i,this.nextoutput=0,this.outputStream=e,this.streamCRC=0},b.prototype._get_next_block=function(){var t,e,r,i=this.reader,n=i.pi();if("177245385090"===n)return!1;"314159265359"!==n&&_(d.NOT_BZIP_DATA),this.targetBlockCRC=i.read(32)>>>0,this.streamCRC=(this.targetBlockCRC^(this.streamCRC<<1|this.streamCRC>>>31))>>>0,i.read(1)&&_(d.OBSOLETE_INPUT);var o=i.read(24);o>this.dbufSize&&_(d.DATA_ERROR,"initial position out of bounds");var a=i.read(16),s=new Uint8Array(256),f=0;for(t=0;t<16;t++)if(a&1<<15-t){var u=16*t;for(r=i.read(16),e=0;e<16;e++)r&1<<15-e&&(s[f++]=u+e)}var h=i.read(3);(h<2||h>6)&&_(d.DATA_ERROR);var c=i.read(15);0===c&&_(d.DATA_ERROR);var b=new Uint8Array(256);for(t=0;t<h;t++)b[t]=t;var y=new Uint8Array(c);for(t=0;t<c;t++){for(e=0;i.read(1);e++)e>=h&&_(d.DATA_ERROR);y[t]=p(b,e)}var R,l=f+2,C=[];for(e=0;e<h;e++){var A,w,O=new Uint8Array(l),B=new Uint16Array(21);for(a=i.read(5),t=0;t<l;t++){for(;(a<1||a>20)&&_(d.DATA_ERROR),i.read(1);)i.read(1)?a--:a++;O[t]=a}for(A=w=O[0],t=1;t<l;t++)O[t]>w?w=O[t]:O[t]<A&&(A=O[t]);R={},C.push(R),R.permute=new Uint16Array(258),R.limit=new Uint32Array(22),R.base=new Uint32Array(21),R.minLen=A,R.maxLen=w;var v=0;for(t=A;t<=w;t++)for(B[t]=R.limit[t]=0,a=0;a<l;a++)O[a]===t&&(R.permute[v++]=a);for(t=0;t<l;t++)B[O[t]]++;for(v=a=0,t=A;t<w;t++)v+=B[t],R.limit[t]=v-1,v<<=1,a+=B[t],R.base[t+1]=v-a;R.limit[w+1]=Number.MAX_VALUE,R.limit[w]=v+B[w]-1,R.base[A]=0}var E=new Uint32Array(256);for(t=0;t<256;t++)b[t]=t;var m,T=0,g=0,U=0,k=this.dbuf=new Uint32Array(this.dbufSize);for(l=0;;){for(l--||(l=49,U>=c&&_(d.DATA_ERROR),R=C[y[U++]]),t=R.minLen,e=i.read(t);t>R.maxLen&&_(d.DATA_ERROR),!(e<=R.limit[t]);t++)e=e<<1|i.read(1);((e-=R.base[t])<0||e>=258)&&_(d.DATA_ERROR);var D=R.permute[e];if(0!==D&&1!==D){if(T)for(T=0,g+a>this.dbufSize&&_(d.DATA_ERROR),E[m=s[b[0]]]+=a;a--;)k[g++]=m;if(D>f)break;g>=this.dbufSize&&_(d.DATA_ERROR),E[m=s[m=p(b,t=D-1)]]++,k[g++]=m}else T||(T=1,a=0),a+=0===D?T:2*T,T<<=1}for((o<0||o>=g)&&_(d.DATA_ERROR),e=0,t=0;t<256;t++)r=e+E[t],E[t]=e,e=r;for(t=0;t<g;t++)k[E[m=255&k[t]]]|=t<<8,E[m]++;var z=0,P=0,S=0;return g&&(P=255&(z=k[o]),z>>=8,S=-1),this.writePos=z,this.writeCurrent=P,this.writeCount=g,this.writeRun=S,!0},b.prototype._read_bunzip=function(t,e){var r,i,n;if(this.writeCount<0)return 0;var o=this.dbuf,a=this.writePos,s=this.writeCurrent,f=this.writeCount;this.outputsize;for(var u=this.writeRun;f;){for(f--,i=s,s=255&(a=o[a]),a>>=8,3==u++?(r=s,n=i,s=-1):(r=1,n=s),this.blockCRC.updateCRCRun(n,r);r--;)this.outputStream.writeByte(n),this.nextoutput++;s!=i&&(u=0)}return this.writeCount=f,this.blockCRC.getCRC()!==this.targetBlockCRC&&_(d.DATA_ERROR,"Bad block CRC (got "+this.blockCRC.getCRC().toString(16)+" expected "+this.targetBlockCRC.toString(16)+")"),this.nextoutput};var y=function(t){if("readByte"in t)return t;var e=new u;return e.pos=0,e.readByte=function(){return t[this.pos++]},e.seek=function(t){this.pos=t},e.eof=function(){return this.pos>=t.length},e},R=function(t){var e=new u,r=!0;if(t)if("number"==typeof t)e.buffer=new Uint8Array(t),r=!1;else{if("writeByte"in t)return t;e.buffer=t,r=!1}else e.buffer=new Uint8Array(16384);return e.pos=0,e.writeByte=function(t){if(r&&this.pos>=this.buffer.length){var e=new Uint8Array(2*this.buffer.length);e.set(this.buffer),this.buffer=e}this.buffer[this.pos++]=t},e.getBuffer=function(){if(this.pos!==this.buffer.length){if(!r)throw new TypeError("outputsize does not match decoded input");var t=new Uint8Array(this.pos);t.set(this.buffer.subarray(0,this.pos)),this.buffer=t}return this.buffer},e._coerced=!0,e};var l=/*#__PURE__*/t({__proto__:null},[{Bunzip:b,Stream:u,Err:d,decode:function(t,e,r){for(var i=y(t),n=R(e),o=new b(i,n);!("eof"in i)||!i.eof();)if(o._init_block())o._read_bunzip();else{var a=o.reader.read(32)>>>0;if(a!==o.streamCRC&&_(d.DATA_ERROR,"Bad stream CRC (got "+o.streamCRC.toString(16)+" expected "+a.toString(16)+")"),!r||!("eof"in i)||i.eof())break;o._start_bunzip(i,n)}if("getBuffer"in n)return n.getBuffer()},decodeBlock:function(t,e,r){var i=y(t),n=R(r),o=new b(i,n);if(o.reader.seek(e),o._get_next_block()&&(o.blockCRC=new h,o.writeCopies=0,o._read_bunzip()),"getBuffer"in n)return n.getBuffer()},table:function(t,e,r){var i=new u;i.delegate=y(t),i.pos=0,i.readByte=function(){return this.pos++,this.delegate.readByte()},i.delegate.eof&&(i.eof=i.delegate.eof.bind(i.delegate));var n=new u;n.pos=0,n.writeByte=function(){this.pos++};for(var o=new b(i,n),a=o.dbufSize;!("eof"in i)||!i.eof();){var s=8*i.pos+o.reader.bitOffset;if(o.reader.hasByte&&(s-=8),o._init_block()){var f=n.pos;o._read_bunzip(),e(s,n.pos-f)}else{if(o.reader.read(32),!r||!("eof"in i)||i.eof())break;o._start_bunzip(i,n),console.assert(o.dbufSize===a,"shouldn't change block size within multistream file")}}}}]);export{l as i};
//# sourceMappingURL=seek-bzip.min.mjs.map