(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function t(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(n){if(n.ep)return;n.ep=!0;const i=t(n);fetch(n.href,i)}})();const ug="ABCDEFGHJKLMNPQRSTUVWXYZ23456789",th=8,$f="DEV",Mf="angioassist-enroll:v1:";function Cd(r){let e=r.trim().toUpperCase().replace(/[\s-]/g,"");if(e.startsWith($f)&&e.length>th&&(e=e.slice($f.length)),e.length!==th)throw new Error(`Code must have ${th} characters`);for(const t of e)if(!ug.includes(t))throw new Error(`Invalid character "${t}"`);return e}function hg(r){const e=r.trim();if(!e.startsWith(Mf))throw new Error("Not an AngioAssist enrollment QR");return Cd(e.slice(Mf.length))}function Bd(){return globalThis.Capacitor?.Plugins?.DeviceKey??null}function fg(){return Bd()!==null}class su extends Error{constructor(e,t,s){super(e),this.status=t,this.code=s,this.name="EnrollApiError"}status;code}async function Id(r,e){let t;try{t=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(n){throw new su(`network error: ${n instanceof Error?n.message:"unknown"}`,0)}if(t.status===429)throw new su("rate limited",429,"rate_limited");let s=null;try{s=await t.json()}catch{}if(!t.ok){const n=s?.error;throw new su(`enrollment failed (${t.status})`,t.status,n)}return s}function dg(r){return Id("/enroll/begin",{code:r})}function mg(r){return Id("/enroll/complete",r)}const gg="[object ArrayBuffer]";class L{static isArrayBuffer(e){return Object.prototype.toString.call(e)===gg}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){const s=L.toUint8Array(e),n=L.toUint8Array(t);if(s.length!==n.byteLength)return!1;for(let i=0;i=0;s--)t+=r[r.length-1-s]*Math.pow(2,e*s);return t}function Ss(r,e,t=-1){const s=t;let n=r,i=0,o=Math.pow(2,e);for(let l=1;l<8;l++){if(r=0;m--){const g=Math.pow(2,m*e);h[i-m-1]=Math.floor(n/g),n-=h[i-m-1]*g}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Ua(...r){let e=0,t=0;for(const i of r)e+=i.byteLength;const s=new ArrayBuffer(e),n=new Uint8Array(s);for(const i of r)n.set(new Uint8Array(i),t),t+=i.byteLength;return s}function Lh(...r){let e=0,t=0;for(const i of r)e+=i.length;const s=new ArrayBuffer(e),n=new Uint8Array(s);for(const i of r)n.set(i,t),t+=i.length;return n}function Vd(){const r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const l=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(l||c)&&this.warnings.push("Needlessly long format")}const e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let l=0;l=r.length&&(i=1);const m=r.charCodeAt(n++);n>=r.length&&(o=1);const g=r.charCodeAt(n++),d=h>>2,b=(h&3)<<4|m>>4;let A=(m&15)<<2|g>>6,E=g&63;i===1?A=E=64:o===1&&(E=64),t?A===64?l+=`${c.charAt(d)}${c.charAt(b)}`:E===64?l+=`${c.charAt(d)}${c.charAt(b)}${c.charAt(A)}`:l+=`${c.charAt(d)}${c.charAt(b)}${c.charAt(A)}${c.charAt(E)}`:l+=`${c.charAt(d)}${c.charAt(b)}${c.charAt(A)}${c.charAt(E)}`}return l}function wc(r,e=!1,t=!1){const s=e?Od:xd;function n(c){for(let h=0;h<64;h++)if(s.charAt(h)===c)return h;return 64}function i(c){return c===64?0:c}let o=0,l="";for(;o=r.length?0:n(r.charAt(o++)),m=o>=r.length?0:n(r.charAt(o++)),g=o>=r.length?0:n(r.charAt(o++)),d=i(c)<<2|i(h)>>4,b=(i(h)&15)<<4|i(m)>>2,A=(i(m)&3)<<6|i(g);l+=String.fromCharCode(d),m!==64&&(l+=String.fromCharCode(b)),g!==64&&(l+=String.fromCharCode(A))}if(t){const c=l.length;let h=-1;for(let m=c-1;m>=0;m--)if(l.charCodeAt(m)!==0){h=m;break}h!==-1?l=l.slice(0,h+1):l=""}return l}function Du(r){let e="";const t=new Uint8Array(r);for(const s of t)e+=String.fromCharCode(s);return e}function Fa(r){const e=r.length,t=new ArrayBuffer(e),s=new Uint8Array(t);for(let n=0;n"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function hf(r){let e=0,t=0;for(let n=0;n=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c++,(i[m]&128)===0)break}this.blockLength=c+1;const h=this.valueHexView=new Uint8Array(c);for(let m=0;m8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;const l=t+1,c=n.subarray(l,l+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=tr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,s;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(s=new Uint8Array(t),s[0]=128),t;if(this.longFormUsed){const n=Ss(this.length,8);if(n.byteLength>127)return this.error="Too big length",qt;if(t=new ArrayBuffer(n.byteLength+1),e)return t;const i=new Uint8Array(n);s=new Uint8Array(t),s[0]=n.byteLength|128;for(let o=0;or.maxNodes)return Dg}function Hg(r,e){if(r>e.maxContentLength)return Pg}function df(r,e,t,s){const n=s.depth+1;if(n>s.maxDepth)return Lg(Tg);s.depth=n;try{return mf(r,e,t,s)}finally{s.depth-=1}}function _g(r,e){if(r instanceof e)return r;const t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function mf(r,e=0,t=r.length,s=Bc()){const n=e;let i=new Fe({},Ze);const o=new nr;if(!As(o,r,e,t))return i.error=o.error,{offset:-1,result:i};if(!r.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};const c=Ug(s);if(c)return i.error=c,{offset:-1,result:i};let h=i.idBlock.fromBER(r,e,t);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),h===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=h,t-=i.idBlock.blockLength,h=i.lenBlock.fromBER(r,e,t),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),h===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};e=h,t-=i.lenBlock.blockLength;const m=i.lenBlock.isIndefiniteForm?t:i.lenBlock.length,g=Hg(m,s);if(g)return i.error=g,{offset:-1,result:i};if(!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let d=Fe;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};d=D.EndOfContent;break;case 1:d=D.Boolean;break;case 2:d=D.Integer;break;case 3:d=D.BitString;break;case 4:d=D.OctetString;break;case 5:d=D.Null;break;case 6:d=D.ObjectIdentifier;break;case 10:d=D.Enumerated;break;case 12:d=D.Utf8String;break;case 13:d=D.RelativeObjectIdentifier;break;case 14:d=D.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:d=D.Sequence;break;case 17:d=D.Set;break;case 18:d=D.NumericString;break;case 19:d=D.PrintableString;break;case 20:d=D.TeletexString;break;case 21:d=D.VideotexString;break;case 22:d=D.IA5String;break;case 23:d=D.UTCTime;break;case 24:d=D.GeneralizedTime;break;case 25:d=D.GraphicString;break;case 26:d=D.VisibleString;break;case 27:d=D.GeneralString;break;case 28:d=D.UniversalString;break;case 29:d=D.CharacterString;break;case 30:d=D.BmpString;break;case 31:d=D.DATE;break;case 32:d=D.TimeOfDay;break;case 33:d=D.DateTime;break;case 34:d=D.Duration;break;default:{const b=i.idBlock.isConstructed?new D.Constructed:new D.Primitive;b.idBlock=i.idBlock,b.lenBlock=i.lenBlock,b.warnings=i.warnings,i=b}}break;default:d=i.idBlock.isConstructed?D.Constructed:D.Primitive}return i=_g(i,d),h=i.fromBER(r,e,m,s),i.valueBeforeDecodeView=r.subarray(n,n+i.blockLength),{offset:h,result:i}}function Oe(r,e={}){if(!r.byteLength){const t=new Fe({},Ze);return t.error="Input buffer has zero length",{offset:-1,result:t}}return mf(L.toUint8Array(r).slice(),0,r.byteLength,Bc(e))}function $g(r,e){return r?1:e}class Bn extends Ze{constructor({value:e=[],isIndefiniteForm:t=!1,...s}={}){super(s),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,s,n){const i=L.toUint8Array(e),o=n??Bc();if(!As(this,i,t,s))return-1;if(this.valueBeforeDecodeView=i.subarray(t,t+s),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let l=t;for(;$g(this.isIndefiniteForm,s)>0;){const c=df(i,l,s,o);if(c.offset===-1)return this.error=c.result.error,this.warnings.concat(c.result.warnings),-1;if(l=c.offset,this.blockLength+=c.result.blockLength,s-=c.result.blockLength,this.value.push(c.result),this.isIndefiniteForm&&c.result.constructor.NAME===yc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===yc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),l}toBER(e,t){const s=t||new ff;for(let n=0;n` ${n}`).join(` `));const t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} : ${e.join(` `)}`:`${t} :`}}$d=w;D.Constructed=$d;w.NAME="CONSTRUCTED";class Md extends Ze{fromBER(e,t,s){return t}toBER(e){return qt}}Md.override="EndOfContentValueBlock";var Kd;class Jd extends Fe{constructor(e={}){super(e,Md),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Kd=Jd;D.EndOfContent=Kd;Jd.NAME=yc;var jd;class Ae extends Fe{constructor(e={}){super(e,Ze),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,s){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=s,t+s>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+s}toBER(e,t){const s=new ArrayBuffer(2);if(!e){const n=new Uint8Array(s);n[0]=5,n[1]=0}return t&&t.write(s),s}onAsciiEncoding(){return`${this.constructor.NAME}`}}jd=Ae;D.Null=jd;Ae.NAME="NULL";class Fd extends ps(Ze){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=L.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,s){const n=L.toUint8Array(e);return As(this,n,t,s)?(this.valueHexView=n.subarray(t,t+s),s>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Vd.call(this),this.blockLength=s,t+s):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}Fd.NAME="BooleanValueBlock";var qd;class Ft extends Fe{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Fd),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}qd=Ft;D.Boolean=qd;Ft.NAME="BOOLEAN";class Wd extends ps(Bn){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,s,n){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=Bn.prototype.fromBER.call(this,e,t,s,n),i===-1)return i;for(let o=0;o0&&m.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=m.unusedBits}return i}const o=L.toUint8Array(e);if(!As(this,o,t,s))return-1;const l=o.subarray(t,t+s);if(this.unusedBits=l[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const c=l.subarray(1);try{if(c.byteLength){const h=n??Bc(),m=df(c,0,c.byteLength,h);m.offset!==-1&&m.offset===s-1&&(this.value=[m.result])}}catch{}}return this.valueHexView=l.subarray(1),this.blockLength=l.length,t+s}toBER(e,t){if(this.isConstructed)return Bn.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){const n=new Uint8Array(1);return n[0]=0,n.buffer}const s=new Uint8Array(this.valueHexView.length+1);return s[0]=this.unusedBits,s.set(this.valueHexView,1),s.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}Gd.NAME="BitStringValueBlock";var Yd;class W extends Fe{constructor({idBlock:e={},lenBlock:t={},...s}={}){var n,i;(n=s.isConstructed)!==null&&n!==void 0||(s.isConstructed=!!(!((i=s.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:s.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!s.isIndefiniteForm},...s},Gd),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,s,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,s,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return w.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const o of t)e.push(o.toString(2).padStart(8,"0"));const s=e.join(""),n=this.constructor.NAME,i=s.substring(0,s.length-this.valueBlock.unusedBits);return`${n} : ${i}`}}}Yd=W;D.BitString=Yd;W.NAME=Td;var Qd;function Mg(r,e){const t=new Uint8Array([0]),s=new Uint8Array(r),n=new Uint8Array(e);let i=s.slice(0);const o=i.length-1,l=n.slice(0),c=l.length-1;let h=0;const m=c=0;d--,g++)!0===g=i.length?i=Lh(new Uint8Array([h%10]),i):i[o-g]=h%10;return t[0]>0&&(i=Lh(t,i)),i}function Ff(r){if(r>=za.length)for(let e=za.length;e<=r;e++){const t=new Uint8Array([0]);let s=za[e-1].slice(0);for(let n=s.length-1;n>=0;n--){const i=new Uint8Array([(s[n]<<1)+t[0]]);t[0]=i[0]/10,s[n]=i[0]%10}t[0]>0&&(s=Lh(t,s)),za.push(s)}return za[r]}function Kg(r,e){let t=0;const s=new Uint8Array(r),n=new Uint8Array(e),i=s.slice(0),o=i.length-1,l=n.slice(0),c=l.length-1;let h,m=0;for(let g=c;g>=0;g--,m++)h=i[o-m]-l[c-m]-t,!0===h<0?(t=1,i[o-m]=h+10):(t=0,i[o-m]=h);if(t>0)for(let g=o-c+1;g>=0;g--,m++)if(h=i[o-m]-t,h<0)t=1,i[o-m]=h+10;else{t=0,i[o-m]=h;break}return i.slice()}class wf extends ps(Ze){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Vd.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Sg(e))}get valueDec(){return this._valueDec}fromDER(e,t,s,n=0){const i=this.fromBER(e,t,s);if(i===-1)return i;const o=this.valueHexView;return o[0]===0&&(o[1]&128)!==0?this.valueHexView=o.subarray(1):n!==0&&o.length1&&(n=o.length+1),this.valueHexView=o.subarray(n-o.length)),i}toDER(e=!1){const t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{const s=new Uint8Array(this.valueHexView.length+1);s[0]=0,s.set(t,1),this.valueHexView=s}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,s){const n=super.fromBER(e,t,s);return n===-1||this.setValueHex(),n}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=this.valueHexView.length*8-1;let t=new Uint8Array(this.valueHexView.length*8/3),s=0,n;const i=this.valueHexView;let o="",l=!1;for(let c=i.byteLength-1;c>=0;c--){n=i[c];for(let h=0;h<8;h++)(n&1)===1&&(s===e?(t=Kg(Ff(s),t),o="-"):t=Mg(t,Ff(s))),s++,n>>=1}for(let c=0;c0;){const i=new Hh;if(n=i.fromBER(e,n,s),n===-1)return this.blockLength=0,this.error=i.error,n;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,s-=i.blockLength,this.value.push(i)}return n}toBER(e){const t=[];for(let s=0;sNumber.MAX_SAFE_INTEGER){Pu();const l=BigInt(n);o.valueBigInt=l}else if(o.valueDec=parseInt(n,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(s!==-1)}toString(){let e="",t=!1;for(let s=0;s0;){const i=new _h;if(n=i.fromBER(e,n,s),n===-1)return this.blockLength=0,this.error=i.error,n;this.blockLength+=i.blockLength,s-=i.blockLength,this.value.push(i)}return n}toBER(e,t){const s=[];for(let n=0;n4)continue;const l=4-o.length;for(let c=o.length-1;c>=0;c--)s[n*4+c+l]=o[c]}this.valueBlock.value=e}}hm.NAME="UniversalStringValueBlock";var fm;class Sc extends hm{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}fm=Sc;D.UniversalString=fm;Sc.NAME="UniversalString";var dm;class Ha extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}dm=Ha;D.NumericString=dm;Ha.NAME="NumericString";var mm;class Ot extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}mm=Ot;D.PrintableString=mm;Ot.NAME="PrintableString";var gm;class Ac extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}gm=Ac;D.TeletexString=gm;Ac.NAME="TeletexString";var wm;class yf extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}wm=yf;D.VideotexString=wm;yf.NAME="VideotexString";var ym;class Qu extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}ym=Qu;D.IA5String=ym;Qu.NAME="IA5String";var vm;class vf extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}vm=vf;D.GraphicString=vm;vf.NAME="GraphicString";var Sm;class Xu extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}Sm=Xu;D.VisibleString=Sm;Xu.NAME="VisibleString";var Am;class Sf extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Am=Sf;D.GeneralString=Am;Sf.NAME="GeneralString";var pm;class Af extends ft{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}pm=Af;D.CharacterString=pm;Af.NAME="CharacterString";var bm;class qa extends Xu{constructor({value:e,valueDate:t,...s}={}){if(super(s),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let n=0;n=50?this.year=1900+n:this.year=2e3+n,this.month=parseInt(s[2],10),this.day=parseInt(s[3],10),this.hour=parseInt(s[4],10),this.minute=parseInt(s[5],10),this.second=parseInt(s[6],10)}toString(e="iso"){if(e==="iso"){const t=new Array(7);return t[0]=ot(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=ot(this.month,2),t[2]=ot(this.day,2),t[3]=ot(this.hour,2),t[4]=ot(this.minute,2),t[5]=ot(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}bm=qa;D.UTCTime=bm;qa.NAME="UTCTime";var km;class ue extends qa{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,s="",n="",i=0,o,l=0,c=0;if(e[e.length-1]==="Z")s=e.substring(0,e.length-1),t=!0;else{const g=new Number(e[e.length-1]);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");s=e}if(t){if(s.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(s.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let g=1,d=s.indexOf("+"),b="";if(d===-1&&(d=s.indexOf("-"),g=-1),d!==-1){if(b=s.substring(d+1),s=s.substring(0,d),b.length!==2&&b.length!==4)throw new Error("Wrong input string for conversion");let A=parseInt(b.substring(0,2),10);if(isNaN(A.valueOf()))throw new Error("Wrong input string for conversion");if(l=g*A,b.length===4){if(A=parseInt(b.substring(2,4),10),isNaN(A.valueOf()))throw new Error("Wrong input string for conversion");c=g*A}}}let h=s.indexOf(".");if(h===-1&&(h=s.indexOf(",")),h!==-1){const g=new Number(`0${s.substring(h)}`);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");i=g.valueOf(),n=s.substring(0,h)}else n=s;switch(!0){case n.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,h!==-1)throw new Error("Wrong input string for conversion");break;case n.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,h!==-1){let g=60*i;this.minute=Math.floor(g),g=60*(g-this.minute),this.second=Math.floor(g),g=1e3*(g-this.second),this.millisecond=Math.floor(g)}break;case n.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,h!==-1){let g=60*i;this.second=Math.floor(g),g=1e3*(g-this.second),this.millisecond=Math.floor(g)}break;case n.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,h!==-1){const g=1e3*i;this.millisecond=Math.floor(g)}break;default:throw new Error("Wrong input string for conversion")}const m=o.exec(n);if(m===null)throw new Error("Wrong input string for conversion");for(let g=1;g0&&t.valueBlock.value[0]instanceof J&&(l=e.valueBlock.value.length),l===0)return{verified:!0,result:r};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let c=!0;for(let h=0;h=e.valueBlock.value.length){if(t.valueBlock.value[c].optional===!1){const h={verified:!1,result:r};return r.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&(delete r[t.name],h.name=t.name)),h}}else if(t.valueBlock.value[0]instanceof J){if(o=N(r,e.valueBlock.value[c],t.valueBlock.value[0].value),o.verified===!1)if(t.valueBlock.value[0].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&delete r[t.name]),o;if(ih in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let h={};Vg in t.valueBlock.value[0]&&t.valueBlock.value[0].local?h=e:h=r,typeof h[t.valueBlock.value[0].name]>"u"&&(h[t.valueBlock.value[0].name]=[]),h[t.valueBlock.value[0].name].push(e.valueBlock.value[c])}}else if(o=N(r,e.valueBlock.value[c-i],t.valueBlock.value[c]),o.verified===!1)if(t.valueBlock.value[c].optional)i++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&delete r[t.name]),o;if(o.verified===!1){const c={verified:!1,result:r};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&(delete r[t.name],c.name=t.name)),c}return{verified:!0,result:r}}if(t.primitiveSchema&&jf in e.valueBlock){const i=mf(e.valueBlock.valueHexView);if(i.offset===-1){const o={verified:!1,result:i.result};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&(delete r[t.name],o.name=t.name)),o}return N(r,i.result,t.primitiveSchema)}return{verified:!0,result:r}}class ge{constructor(e={}){if("view"in e)this.fromUint8Array(e.view);else if("buffer"in e)this.fromArrayBuffer(e.buffer);else if("string"in e)this.fromString(e.string);else if("hexstring"in e)this.fromHexString(e.hexstring);else if("length"in e&&e.length>0){if(this.length=e.length,e.stub)for(let t=0;t=this.view.length||e<0)&&(e=0),(t>=this.view.length||t<0)&&(t=this.view.length-e);for(let n=e;n>1),this.view=new Uint8Array(this.buffer);const s=new Map;s.set("0",0),s.set("1",1),s.set("2",2),s.set("3",3),s.set("4",4),s.set("5",5),s.set("6",6),s.set("7",7),s.set("8",8),s.set("9",9),s.set("A",10),s.set("a",10),s.set("B",11),s.set("b",11),s.set("C",12),s.set("c",12),s.set("D",13),s.set("d",13),s.set("E",14),s.set("e",14),s.set("F",15),s.set("f",15);let n=0,i=0;for(let o=0;o=this.view.length||e<0)&&(e=0),(t>=this.view.length||t<0)&&(t=this.view.length-e);for(let n=e;nthis.length-1)throw new Error(`Wrong start position: ${e}`);return new ge({buffer:this._buffer.slice(e,e+t)})}slice(e=0,t=this.length){if(!e&&!this.length)return new ge;if(e<0||e>this.length-1)throw new Error(`Wrong start position: ${e}`);return new ge({buffer:this._buffer.slice(e,t)})}realloc(e){const t=new ArrayBuffer(e),s=new Uint8Array(t);e>this._view.length?s.set(this._view):s.set(new Uint8Array(this._buffer,0,e)),this._buffer=t,this._view=new Uint8Array(this._buffer)}append(e){const t=this.length,s=e.length,n=e._view.subarray();this.realloc(t+s),this._view.set(n,t)}insert(e,t=0,s=this.length-t){return t>this.length-1?!1:(s>this.length-t&&(s=this.length-t),s>e.length&&(s=e.length),s==e.length?this._view.set(e._view,t):this._view.set(e._view.subarray(0,s),t),!0)}isEqual(e){if(this.length!=e.length)return!1;for(let t=0;to)return-1;const h=[];for(let m=0;m=c.position-c.length&&(g=!0):m-d<=c.position-c.length&&(g=!0),g&&(c.position=m,c.id=h,c.length=d)}}return c}findAllIn(e,t,s){let{start:n,length:i}=this.prepareFindParameters(t,s);const o=[];let l={id:-1,position:n};do{const c=l.position;if(l=this.findFirstIn(e,l.position,i),l.id==-1)break;i-=l.position-c,o.push({id:l.id,position:l.position})}while(!0);return o}findAllPatternIn(e,t,s){const{start:n,length:i}=this.prepareFindParameters(t,s),o=[],l=e.length;if(l>i)return-1;const c=Array.from(e.view);for(let h=0;h<=i-l;h++){let m=!0;const g=n+h;for(let d=0;d0;){if(c.right=this.findFirstIn(e,l?i-o+h:i+o-h,h,l),c.right.id==-1){o=h,l?i-=o:i=c.left.position,c.value=new ge({buffer:this._buffer.slice(i,i+o)});break}if(c.right.position!=(l?c.left.position-e[c.right.id].length:c.left.position+e[c.right.id].length)){l?(i=c.right.position+e[c.right.id].length,o=c.left.position-c.right.position-e[c.right.id].length):(i=c.left.position,o=c.right.position-c.left.position-e[c.right.id].length),c.value=new ge({buffer:this._buffer.slice(i,i+o)});break}c.left=c.right,h-=e[c.right.id].length}if(l){const m=c.right;c.right=c.left,c.left=m}return c}findAllNotIn(e,t,s){let{start:n,length:i}=this.prepareFindParameters(t,s);const o=[];let l={left:{id:-1,position:n},right:{id:-1,position:n},value:new ge};do{const c=l.right.position;l=this.findFirstNotIn(e,l.right.position,i),i-=l.right.position-c,o.push({left:{id:l.left.id,position:l.left.position},right:{id:l.right.id,position:l.right.position},value:l.value})}while(l.right.id!=-1);return o}findFirstSequence(e,t,s,n){let{start:i,length:o,backward:l}=this.prepareFindParameters(t,s,n);const c=this.skipNotPatterns(e,i,o,l);if(c==-1)return{position:-1,value:new ge};const h=this.skipPatterns(e,c,o-(l?i-c:c-i),l);l?(i=h,o=c-h):(i=c,o=h-c);const m=new ge({buffer:this._buffer.slice(i,i+o)});return{position:h,value:m}}findAllSequences(e,t,s){let{start:n,length:i}=this.prepareFindParameters(t,s);const o=[];let l={position:n,value:new ge};do{const c=l.position;l=this.findFirstSequence(e,l.position,i),l.position!=-1&&(i-=l.position-c,o.push({position:l.position,value:l.value}))}while(l.position!=-1);return o}findPairedPatterns(e,t,s,n){const i=[];if(e.isEqual(t))return i;const{start:o,length:l}=this.prepareFindParameters(s,n);let c=0;const h=this.findAllPatternIn(e,o,l);if(!Array.isArray(h)||h.length==0)return i;const m=this.findAllPatternIn(t,o,l);if(!Array.isArray(m)||m.length==0)return i;for(;cm[0])break;for(;h[c]=h.length)););i.push({left:h[c-1],right:m[0]}),h.splice(c-1,1),m.splice(0,1),c=0}return i.sort((g,d)=>g.left-d.left),i}findPairedArrays(e,t,s,n){const{start:i,length:o}=this.prepareFindParameters(s,n),l=[];let c=0;const h=this.findAllIn(e,i,o);if(h.length==0)return l;const m=this.findAllIn(t,i,o);if(m.length==0)return l;for(;cm[0].position)break;for(;h[c].position=h.length)););l.push({left:h[c-1],right:m[0]}),h.splice(c-1,1),m.splice(0,1),c=0}return l.sort((g,d)=>g.left.position-d.left.position),l}replacePattern(e,t,s,n,i=null){let o=[],l;const c={status:-1,searchPatternPositions:[],replacePatternPositions:[]},{start:h,length:m}=this.prepareFindParameters(s,n);if(i==null){if(o=this.findAllIn([e],h,m),o.length==0)return c}else o=i;c.searchPatternPositions.push(...Array.from(o,A=>A.position));const g=e.length-t.length,d=new ArrayBuffer(this.view.length-o.length*g),b=new Uint8Array(d);for(b.set(new Uint8Array(this.buffer,0,h)),l=0;l=i+o)return c}}return c}skipNotPatterns(e,t,s,n){const{start:i,length:o,backward:l}=this.prepareFindParameters(t,s,n);let c=-1;for(let h=0;hthis.length&&(e=this.length),s?(t===null&&(t=e),t>e&&(t=e)):(t===null&&(t=this.length-e),t>this.length-e&&(t=this.length-e)),{start:e,length:t,backward:s}}}const Jg=16777216;class In{constructor(e={}){this._stream=new ge,this._length=0,this._start=0,this.backward=!1,this.appendBlock=0,this.prevLength=0,this.prevStart=0,"view"in e?this.stream=new ge({view:e.view}):"buffer"in e?this.stream=new ge({buffer:e.buffer}):"string"in e?this.stream=new ge({string:e.string}):"hexstring"in e?this.stream=new ge({hexstring:e.hexstring}):"stream"in e?this.stream=e.stream.slice():this.stream=new ge,"backward"in e&&e.backward&&(this.backward=e.backward,this._start=this.stream.length),"length"in e&&e.length>0&&(this._length=e.length),"start"in e&&e.start&&e.start>0&&(this._start=e.start),"appendBlock"in e&&e.appendBlock&&e.appendBlock>0&&(this.appendBlock=e.appendBlock)}set stream(e){this._stream=e,this.prevLength=this._length,this._length=e.length,this.prevStart=this._start,this._start=0}get stream(){return this._stream}set length(e){this.prevLength=this._length,this._length=e}get length(){return this.appendBlock?this.start:this._length}set start(e){e>this.stream.length||(this.prevStart=this._start,this.prevLength=this._length,this._length-=this.backward?this._start-e:e-this._start,this._start=e)}get start(){return this._start}get buffer(){return this._stream.buffer.slice(0,this._length)}resetPosition(){this._start=this.prevStart,this._length=this.prevLength}findPattern(e,t=null){(t==null||t>this.length)&&(t=this.length);const s=this.stream.findPattern(e,this.start,this.length,this.backward);if(s==-1)return s;if(this.backward){if(sthis.start+e.length+t)return-1;return this.start=s,s}findFirstIn(e,t=null){(t==null||t>this.length)&&(t=this.length);const s=this.stream.findFirstIn(e,this.start,this.length,this.backward);if(s.id==-1)return s;if(this.backward){if(s.positionthis.start+e[s.id].length+t)return{id:-1,position:this.backward?0:this.start+this.length};return this.start=s.position,s}findAllIn(e){const t=this.backward?this.start-this.length:this.start;return this.stream.findAllIn(e,t,this.length)}findFirstNotIn(e,t=null){(t==null||t>this._length)&&(t=this._length);const s=this._stream.findFirstNotIn(e,this._start,this._length,this.backward);if(s.left.id==-1&&s.right.id==-1)return s;if(this.backward){if(s.right.id!=-1&&s.right.positionthis._start+e[s.left.id].length+t)return{left:{id:-1,position:this._start},right:{id:-1,position:0},value:new ge};return this.backward?s.left.id==-1?this.start=0:this.start=s.left.position:s.right.id==-1?this.start=this._start+this._length:this.start=s.right.position,s}findAllNotIn(e){const t=this.backward?this._start-this._length:this._start;return this._stream.findAllNotIn(e,t,this._length)}findFirstSequence(e,t=null,s=null){(t==null||t>this._length)&&(t=this._length),(s==null||s>t)&&(s=t);const n=this._stream.findFirstSequence(e,this._start,t,this.backward);if(n.value.length==0)return n;if(this.backward){if(n.positionthis._start+n.value.length+s)return{position:-1,value:new ge};return this.start=n.position,n}findAllSequences(e){const t=this.backward?this.start-this.length:this.start;return this.stream.findAllSequences(e,t,this.length)}findPairedPatterns(e,t,s=null){(s==null||s>this.length)&&(s=this.length);const n=this.backward?this.start-this.length:this.start,i=this.stream.findPairedPatterns(e,t,n,this.length);if(i.length){if(this.backward){if(i[0].rightthis.start+e.length+s)return[]}return i}findPairedArrays(e,t,s=null){(s==null||s>this.length)&&(s=this.length);const n=this.backward?this.start-this.length:this.start,i=this.stream.findPairedArrays(e,t,n,this.length);if(i.length){if(this.backward){if(i[0].right.positionthis.start+e[i[0].left.id].length+s)return[]}return i}replacePattern(e,t){const s=this.backward?this.start-this.length:this.start;return this.stream.replacePattern(e,t,s,this.length)}skipPatterns(e){const t=this.stream.skipPatterns(e,this.start,this.length,this.backward);return this.start=t,t}skipNotPatterns(e){const t=this.stream.skipNotPatterns(e,this.start,this.length,this.backward);return t==-1?-1:(this.start=t,t)}append(e){this.beforeAppend(e.length),this._stream.view.set(e.view,this._start),this._length+=e.length*2,this.start=this._start+e.length,this.prevLength-=e.length*2}appendView(e){this.beforeAppend(e.length),this._stream.view.set(e,this._start),this._length+=e.length*2,this.start=this._start+e.length,this.prevLength-=e.length*2}appendChar(e){this.beforeAppend(1),this._stream.view[this._start]=e,this._length+=2,this.start=this._start+1,this.prevLength-=2}appendUint16(e){this.beforeAppend(2);const t=new Uint16Array([e]),s=new Uint8Array(t.buffer);this.stream.view[this._start]=s[1],this._stream.view[this._start+1]=s[0],this._length+=4,this.start=this._start+2,this.prevLength-=4}appendUint24(e){this.beforeAppend(3);const t=new Uint32Array([e]),s=new Uint8Array(t.buffer);this._stream.view[this._start]=s[2],this._stream.view[this._start+1]=s[1],this._stream.view[this._start+2]=s[0],this._length+=6,this.start=this._start+3,this.prevLength-=6}appendUint32(e){this.beforeAppend(4);const t=new Uint32Array([e]),s=new Uint8Array(t.buffer);this._stream.view[this._start]=s[3],this._stream.view[this._start+1]=s[2],this._stream.view[this._start+2]=s[1],this._stream.view[this._start+3]=s[0],this._length+=8,this.start=this._start+4,this.prevLength-=8}appendInt16(e){this.beforeAppend(2);const t=new Int16Array([e]),s=new Uint8Array(t.buffer);this._stream.view[this._start]=s[1],this._stream.view[this._start+1]=s[0],this._length+=4,this.start=this._start+2,this.prevLength-=4}appendInt32(e){this.beforeAppend(4);const t=new Int32Array([e]),s=new Uint8Array(t.buffer);this._stream.view[this._start]=s[3],this._stream.view[this._start+1]=s[2],this._stream.view[this._start+2]=s[1],this._stream.view[this._start+3]=s[0],this._length+=8,this.start=this._start+4,this.prevLength-=8}getBlock(e,t=!0){if(this._length<=0)return new Uint8Array(0);this._lengththis._stream.length&&(e>this.appendBlock&&(this.appendBlock=e+In.APPEND_BLOCK),this._stream.realloc(this._stream.length+this.appendBlock))}}In.APPEND_BLOCK=1e3;function jg(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Dm(r,...e){if(!jg(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function qf(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function Fg(r,e){Dm(r);const t=e.outputLen;if(r.lengthnew DataView(r.buffer,r.byteOffset,r.byteLength),Ut=(r,e)=>r<<32-e|r>>>e,ah=(r,e)=>r<>>32-e>>>0;new Uint8Array(new Uint32Array([287454020]).buffer)[0];function qg(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Pm(r){return typeof r=="string"&&(r=qg(r)),Dm(r),r}class Wg{clone(){return this._cloneInto()}}function Zu(r){const e=s=>r().update(Pm(s)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Gg(r,e,t,s){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,s);const n=BigInt(32),i=BigInt(4294967295),o=Number(t>>n&i),l=Number(t&i),c=s?4:0,h=s?0:4;r.setUint32(e+c,o,s),r.setUint32(e+h,l,s)}const Lm=(r,e,t)=>r&e^~r&t,Um=(r,e,t)=>r&e^r&t^e&t;class pf extends Wg{constructor(e,t,s,n){super(),this.blockLen=e,this.outputLen=t,this.padOffset=s,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=rh(this.buffer)}update(e){qf(this);const{view:t,buffer:s,blockLen:n}=this;e=Pm(e);const i=e.length;for(let o=0;on-o&&(this.process(s,0),o=0);for(let g=o;gm.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;gnew Yg),Xg=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Cs=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Bs=new Uint32Array(64);let Zg=class extends pf{constructor(){super(64,32,8,!1),this.A=Cs[0]|0,this.B=Cs[1]|0,this.C=Cs[2]|0,this.D=Cs[3]|0,this.E=Cs[4]|0,this.F=Cs[5]|0,this.G=Cs[6]|0,this.H=Cs[7]|0}get(){const{A:e,B:t,C:s,D:n,E:i,F:o,G:l,H:c}=this;return[e,t,s,n,i,o,l,c]}set(e,t,s,n,i,o,l,c){this.A=e|0,this.B=t|0,this.C=s|0,this.D=n|0,this.E=i|0,this.F=o|0,this.G=l|0,this.H=c|0}process(e,t){for(let g=0;g<16;g++,t+=4)Bs[g]=e.getUint32(t,!1);for(let g=16;g<64;g++){const d=Bs[g-15],b=Bs[g-2],A=Ut(d,7)^Ut(d,18)^d>>>3,E=Ut(b,17)^Ut(b,19)^b>>>10;Bs[g]=E+Bs[g-7]+A+Bs[g-16]|0}let{A:s,B:n,C:i,D:o,E:l,F:c,G:h,H:m}=this;for(let g=0;g<64;g++){const d=Ut(l,6)^Ut(l,11)^Ut(l,25),b=m+d+Lm(l,c,h)+Xg[g]+Bs[g]|0,E=(Ut(s,2)^Ut(s,13)^Ut(s,22))+Um(s,n,i)|0;m=h,h=c,c=l,l=o+b|0,o=i,i=n,n=s,s=b+E|0}s=s+this.A|0,n=n+this.B|0,i=i+this.C|0,o=o+this.D|0,l=l+this.E|0,c=c+this.F|0,h=h+this.G|0,m=m+this.H|0,this.set(s,n,i,o,l,c,h,m)}roundClean(){Bs.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const zg=Zu(()=>new Zg),Vc=BigInt(2**32-1),$h=BigInt(32);function Hm(r,e=!1){return e?{h:Number(r&Vc),l:Number(r>>$h&Vc)}:{h:Number(r>>$h&Vc)|0,l:Number(r&Vc)|0}}function ew(r,e=!1){let t=new Uint32Array(r.length),s=new Uint32Array(r.length);for(let n=0;nBigInt(r>>>0)<<$h|BigInt(e>>>0),sw=(r,e,t)=>r>>>t,nw=(r,e,t)=>r<<32-t|e>>>t,iw=(r,e,t)=>r>>>t|e<<32-t,rw=(r,e,t)=>r<<32-t|e>>>t,aw=(r,e,t)=>r<<64-t|e>>>t-32,ow=(r,e,t)=>r>>>t-32|e<<64-t,lw=(r,e)=>e,cw=(r,e)=>r,uw=(r,e,t)=>r<>>32-t,hw=(r,e,t)=>e<>>32-t,fw=(r,e,t)=>e<>>64-t,dw=(r,e,t)=>r<>>64-t;function mw(r,e,t,s){const n=(e>>>0)+(s>>>0);return{h:r+t+(n/2**32|0)|0,l:n|0}}const gw=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),ww=(r,e,t,s)=>e+t+s+(r/2**32|0)|0,yw=(r,e,t,s)=>(r>>>0)+(e>>>0)+(t>>>0)+(s>>>0),vw=(r,e,t,s,n)=>e+t+s+n+(r/2**32|0)|0,Sw=(r,e,t,s,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(s>>>0)+(n>>>0),Aw=(r,e,t,s,n,i)=>e+t+s+n+i+(r/2**32|0)|0,G={fromBig:Hm,split:ew,toBig:tw,shrSH:sw,shrSL:nw,rotrSH:iw,rotrSL:rw,rotrBH:aw,rotrBL:ow,rotr32H:lw,rotr32L:cw,rotlSH:uw,rotlSL:hw,rotlBH:fw,rotlBL:dw,add:mw,add3L:gw,add3H:ww,add4L:yw,add4H:vw,add5H:Aw,add5L:Sw},[pw,bw]=G.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Is=new Uint32Array(80),Vs=new Uint32Array(80);let _m=class extends pf{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:t,Bh:s,Bl:n,Ch:i,Cl:o,Dh:l,Dl:c,Eh:h,El:m,Fh:g,Fl:d,Gh:b,Gl:A,Hh:E,Hl:y}=this;return[e,t,s,n,i,o,l,c,h,m,g,d,b,A,E,y]}set(e,t,s,n,i,o,l,c,h,m,g,d,b,A,E,y){this.Ah=e|0,this.Al=t|0,this.Bh=s|0,this.Bl=n|0,this.Ch=i|0,this.Cl=o|0,this.Dh=l|0,this.Dl=c|0,this.Eh=h|0,this.El=m|0,this.Fh=g|0,this.Fl=d|0,this.Gh=b|0,this.Gl=A|0,this.Hh=E|0,this.Hl=y|0}process(e,t){for(let B=0;B<16;B++,t+=4)Is[B]=e.getUint32(t),Vs[B]=e.getUint32(t+=4);for(let B=16;B<80;B++){const V=Is[B-15]|0,R=Vs[B-15]|0,$=G.rotrSH(V,R,1)^G.rotrSH(V,R,8)^G.shrSH(V,R,7),te=G.rotrSL(V,R,1)^G.rotrSL(V,R,8)^G.shrSL(V,R,7),j=Is[B-2]|0,Z=Vs[B-2]|0,ye=G.rotrSH(j,Z,19)^G.rotrBH(j,Z,61)^G.shrSH(j,Z,6),se=G.rotrSL(j,Z,19)^G.rotrBL(j,Z,61)^G.shrSL(j,Z,6),ae=G.add4L(te,se,Vs[B-7],Vs[B-16]),Wt=G.add4H(ae,$,ye,Is[B-7],Is[B-16]);Is[B]=Wt|0,Vs[B]=ae|0}let{Ah:s,Al:n,Bh:i,Bl:o,Ch:l,Cl:c,Dh:h,Dl:m,Eh:g,El:d,Fh:b,Fl:A,Gh:E,Gl:y,Hh:O,Hl:x}=this;for(let B=0;B<80;B++){const V=G.rotrSH(g,d,14)^G.rotrSH(g,d,18)^G.rotrBH(g,d,41),R=G.rotrSL(g,d,14)^G.rotrSL(g,d,18)^G.rotrBL(g,d,41),$=g&b^~g&E,te=d&A^~d&y,j=G.add5L(x,R,te,bw[B],Vs[B]),Z=G.add5H(j,O,V,$,pw[B],Is[B]),ye=j|0,se=G.rotrSH(s,n,28)^G.rotrBH(s,n,34)^G.rotrBH(s,n,39),ae=G.rotrSL(s,n,28)^G.rotrBL(s,n,34)^G.rotrBL(s,n,39),Wt=s&i^s&l^i&l,_e=n&o^n&c^o&c;O=E|0,x=y|0,E=b|0,y=A|0,b=g|0,A=d|0,{h:g,l:d}=G.add(h|0,m|0,Z|0,ye|0),h=l|0,m=c|0,l=i|0,c=o|0,i=s|0,o=n|0;const fe=G.add3L(ye,ae,_e);s=G.add3H(fe,Z,se,Wt),n=fe|0}({h:s,l:n}=G.add(this.Ah|0,this.Al|0,s|0,n|0)),{h:i,l:o}=G.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:l,l:c}=G.add(this.Ch|0,this.Cl|0,l|0,c|0),{h,l:m}=G.add(this.Dh|0,this.Dl|0,h|0,m|0),{h:g,l:d}=G.add(this.Eh|0,this.El|0,g|0,d|0),{h:b,l:A}=G.add(this.Fh|0,this.Fl|0,b|0,A|0),{h:E,l:y}=G.add(this.Gh|0,this.Gl|0,E|0,y|0),{h:O,l:x}=G.add(this.Hh|0,this.Hl|0,O|0,x|0),this.set(s,n,i,o,l,c,h,m,g,d,b,A,E,y,O,x)}roundClean(){Is.fill(0),Vs.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},kw=class extends _m{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}};const Ew=Zu(()=>new _m),Nw=Zu(()=>new kw);const be=new ArrayBuffer(0),u="";class ie extends TypeError{constructor(){super(...arguments),this.name=ie.NAME}static isType(e,t){if(typeof t=="string"){if(t==="Array"&&Array.isArray(e))return!0;if(t==="ArrayBuffer"&&e instanceof ArrayBuffer)return!0;if(t==="ArrayBufferView"&&ArrayBuffer.isView(e))return!0;if(typeof e===t)return!0}else if(e instanceof t)return!0;return!1}static assert(e,t,...s){for(const i of s)if(this.isType(e,i))return;const n=s.map(i=>i instanceof Function&&"name"in i?i.name:`${i}`);throw new ie(`Parameter '${t}' is not of type ${n.length>1?`(${n.join(" or ")})`:n[0]}`)}}ie.NAME="ArgumentError";class Q extends TypeError{static assert(...e){let t=null,s,n;typeof e[0]=="string"?(t=e[0],s=e[1],n=e.slice(2)):(s=e[0],n=e.slice(1)),ie.assert(s,"parameters","object");for(const i of n){const o=s[i];if(o==null)throw new Q(i,t)}}static assertEmpty(e,t,s){if(e==null)throw new Q(t,s)}constructor(e,t=null,s){super(),this.name=Q.NAME,this.field=e,t&&(this.target=t),s?this.message=s:this.message=`Absent mandatory parameter '${e}' ${t?` in '${t}'`:u}`}}Q.NAME="ParameterError";class p extends Error{static assertSchema(e,t){if(!e.verified)throw new Error(`Object's schema was not verified against input data for ${t}`)}static assert(e,t){if(e.offset===-1)throw new p(`Error during parsing of ASN.1 data. Data is not correct for '${t}'.`)}constructor(e){super(e),this.name="AsnError"}}class k{static blockName(){return this.CLASS_NAME}static fromBER(e){const t=Oe(e);p.assert(t,this.name);try{return new this({schema:t.result})}catch{throw new p(`Cannot create '${this.CLASS_NAME}' from ASN.1 object`)}}static defaultValues(e){throw new Error(`Invalid member name for ${this.CLASS_NAME} class: ${e}`)}static schema(e={}){throw new Error(`Method '${this.CLASS_NAME}.schema' should be overridden`)}get className(){return this.constructor.CLASS_NAME}toString(e="hex"){let t;try{t=this.toSchema()}catch{t=this.toSchema(!0)}return H.ToString(t.toBER(),e)}}k.CLASS_NAME="PkiObject";function wn(r){let e=!1,t=u;const s=r.trim();for(let n=0;nnew pn({schema:s}))),this.valueBeforeDecode=t.result.RDN.valueBeforeDecodeView.slice().buffer}toSchema(){if(this.valueBeforeDecode.byteLength===0)return new f({value:[new pe({value:Array.from(this.typesAndValues,t=>t.toSchema())})]});const e=Oe(this.valueBeforeDecode);if(p.assert(e,"RelativeDistinguishedNames"),!(e.result instanceof f))throw new Error("ASN.1 result should be SEQUENCE");return e.result}toJSON(){return{typesAndValues:Array.from(this.typesAndValues,e=>e.toJSON())}}isEqual(e){if(e instanceof re){if(this.typesAndValues.length!==e.typesAndValues.length)return!1;for(const[t,s]of this.typesAndValues.entries())if(s.isEqual(e.typesAndValues[t])===!1)return!1;return!0}return e instanceof ArrayBuffer?ja(this.valueBeforeDecode,e):!1}}re.CLASS_NAME="RelativeDistinguishedNames";const wo="type",yo="value";function Cw(r={},e=!1){const t=a(r,"names",{});return new f({optional:e,value:[new w({optional:!0,idBlock:{tagClass:2,tagNumber:1},name:t.country_name||u,value:[new he({value:[new Ha,new Ot]})]}),new w({optional:!0,idBlock:{tagClass:2,tagNumber:2},name:t.administration_domain_name||u,value:[new he({value:[new Ha,new Ot]})]}),new _({optional:!0,idBlock:{tagClass:3,tagNumber:0},name:t.network_address||u,isHexOnly:!0}),new _({optional:!0,idBlock:{tagClass:3,tagNumber:1},name:t.terminal_identifier||u,isHexOnly:!0}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:2},name:t.private_domain_name||u,value:[new he({value:[new Ha,new Ot]})]}),new _({optional:!0,idBlock:{tagClass:3,tagNumber:3},name:t.organization_name||u,isHexOnly:!0}),new _({optional:!0,name:t.numeric_user_identifier||u,idBlock:{tagClass:3,tagNumber:4},isHexOnly:!0}),new w({optional:!0,name:t.personal_name||u,idBlock:{tagClass:3,tagNumber:5},value:[new _({idBlock:{tagClass:3,tagNumber:0},isHexOnly:!0}),new _({optional:!0,idBlock:{tagClass:3,tagNumber:1},isHexOnly:!0}),new _({optional:!0,idBlock:{tagClass:3,tagNumber:2},isHexOnly:!0}),new _({optional:!0,idBlock:{tagClass:3,tagNumber:3},isHexOnly:!0})]}),new w({optional:!0,name:t.organizational_unit_names||u,idBlock:{tagClass:3,tagNumber:6},value:[new J({value:new Ot})]})]})}function Bw(r=!1){return new f({optional:r,value:[new Ot,new Ot]})}function Iw(r=!1){return new pe({optional:r,value:[new _({optional:!0,idBlock:{tagClass:3,tagNumber:0},isHexOnly:!0}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new K]})]})}class X extends k{constructor(e={}){super(),this.type=a(e,wo,X.defaultValues(wo)),this.value=a(e,yo,X.defaultValues(yo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case wo:return 9;case yo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case wo:return t===X.defaultValues(e);case yo:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new he({value:[new w({idBlock:{tagClass:3,tagNumber:0},name:t.blockName||u,value:[new T,new w({idBlock:{tagClass:3,tagNumber:0},value:[new K]})]}),new _({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:1}}),new _({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:2}}),new w({idBlock:{tagClass:3,tagNumber:3},name:t.blockName||u,value:[Cw(t.builtInStandardAttributes||{},!1),Bw(!0),Iw(!0)]}),new w({idBlock:{tagClass:3,tagNumber:4},name:t.blockName||u,value:[re.schema(t.directoryName||{})]}),new w({idBlock:{tagClass:3,tagNumber:5},name:t.blockName||u,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new he({value:[new Ac,new Ot,new Sc,new Dt,new vc]})]}),new w({idBlock:{tagClass:3,tagNumber:1},value:[new he({value:[new Ac,new Ot,new Sc,new Dt,new vc]})]})]}),new _({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:6}}),new _({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:7}}),new _({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:8}})]})}fromSchema(e){C(e,["blockName","otherName","rfc822Name","dNSName","x400Address","directoryName","ediPartyName","uniformResourceIdentifier","iPAddress","registeredID"]);const t=N(e,e,X.schema({names:{blockName:"blockName",otherName:"otherName",rfc822Name:"rfc822Name",dNSName:"dNSName",x400Address:"x400Address",directoryName:{names:{blockName:"directoryName"}},ediPartyName:"ediPartyName",uniformResourceIdentifier:"uniformResourceIdentifier",iPAddress:"iPAddress",registeredID:"registeredID"}}));switch(p.assertSchema(t,this.className),this.type=t.result.blockName.idBlock.tagNumber,this.type){case 0:this.value=t.result.blockName;break;case 1:case 2:case 6:{const s=t.result.blockName;s.idBlock.tagClass=1,s.idBlock.tagNumber=22;const n=s.toBER(!1),i=Oe(n);p.assert(i,"GeneralName value"),this.value=i.result.valueBlock.value}break;case 3:this.value=t.result.blockName;break;case 4:this.value=new re({schema:t.result.directoryName});break;case 5:this.value=t.result.ediPartyName;break;case 7:this.value=new I({valueHex:t.result.blockName.valueBlock.valueHex});break;case 8:{const s=t.result.blockName;s.idBlock.tagClass=1,s.idBlock.tagNumber=6;const n=s.toBER(!1),i=Oe(n);p.assert(i,"GeneralName registeredID"),this.value=i.result.valueBlock.toString()}break}}toSchema(){switch(this.type){case 0:case 3:case 5:return new w({idBlock:{tagClass:3,tagNumber:this.type},value:[this.value]});case 1:case 2:case 6:{const e=new Qu({value:this.value});return e.idBlock.tagClass=3,e.idBlock.tagNumber=this.type,e}case 4:return new w({idBlock:{tagClass:3,tagNumber:4},value:[this.value.toSchema()]});case 7:{const e=this.value;return e.idBlock.tagClass=3,e.idBlock.tagNumber=this.type,e}case 8:{const e=new T({value:this.value});return e.idBlock.tagClass=3,e.idBlock.tagNumber=this.type,e}default:return X.schema()}}toJSON(){const e={type:this.type,value:u};if(typeof this.value=="string")e.value=this.value;else try{e.value=this.value.toJSON()}catch{}return e}}X.CLASS_NAME="GeneralName";const vo="accessMethod",So="accessLocation",Vw=[vo,So];class Fi extends k{constructor(e={}){super(),this.accessMethod=a(e,vo,Fi.defaultValues(vo)),this.accessLocation=a(e,So,Fi.defaultValues(So)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case vo:return u;case So:return new X;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.accessMethod||u}),X.schema(t.accessLocation||{})]})}fromSchema(e){C(e,Vw);const t=N(e,e,Fi.schema({names:{accessMethod:vo,accessLocation:{names:{blockName:So}}}}));p.assertSchema(t,this.className),this.accessMethod=t.result.accessMethod.valueBlock.toString(),this.accessLocation=new X({schema:t.result.accessLocation})}toSchema(){return new f({value:[new T({value:this.accessMethod}),this.accessLocation.toSchema()]})}toJSON(){return{accessMethod:this.accessMethod,accessLocation:this.accessLocation.toJSON()}}}Fi.CLASS_NAME="AccessDescription";const Os="seconds",Rs="millis",Ts="micros";class lt extends k{constructor(e={}){super(),Os in e&&(this.seconds=a(e,Os,lt.defaultValues(Os))),Rs in e&&(this.millis=a(e,Rs,lt.defaultValues(Rs))),Ts in e&&(this.micros=a(e,Ts,lt.defaultValues(Ts))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Os:case Rs:case Ts:return 0;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Os:case Rs:case Ts:return t===lt.defaultValues(e);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,optional:!0,value:[new S({optional:!0,name:t.seconds||u}),new _({name:t.millis||u,optional:!0,idBlock:{tagClass:3,tagNumber:0}}),new _({name:t.micros||u,optional:!0,idBlock:{tagClass:3,tagNumber:1}})]})}fromSchema(e){C(e,[Os,Rs,Ts]);const t=N(e,e,lt.schema({names:{seconds:Os,millis:Rs,micros:Ts}}));if(p.assertSchema(t,this.className),"seconds"in t.result&&(this.seconds=t.result.seconds.valueBlock.valueDec),"millis"in t.result){const s=new S({valueHex:t.result.millis.valueBlock.valueHex});this.millis=s.valueBlock.valueDec}if("micros"in t.result){const s=new S({valueHex:t.result.micros.valueBlock.valueHex});this.micros=s.valueBlock.valueDec}}toSchema(){const e=[];if(this.seconds!==void 0&&e.push(new S({value:this.seconds})),this.millis!==void 0){const t=new S({value:this.millis});e.push(new _({idBlock:{tagClass:3,tagNumber:0},valueHex:t.valueBlock.valueHexView}))}if(this.micros!==void 0){const t=new S({value:this.micros});e.push(new _({idBlock:{tagClass:3,tagNumber:1},valueHex:t.valueBlock.valueHexView}))}return new f({value:e})}toJSON(){const e={};return this.seconds!==void 0&&(e.seconds=this.seconds),this.millis!==void 0&&(e.millis=this.millis),this.micros!==void 0&&(e.micros=this.micros),e}}lt.CLASS_NAME="Accuracy";const Oc="algorithmId",so="algorithmParams",$m="algorithm",Mh="params",xw=[$m,Mh];class v extends k{constructor(e={}){super(),this.algorithmId=a(e,Oc,v.defaultValues(Oc)),so in e&&(this.algorithmParams=a(e,so,v.defaultValues(so))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Oc:return u;case so:return new K;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Oc:return t===u;case so:return t instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,optional:t.optional||!1,value:[new T({name:t.algorithmIdentifier||u}),new K({name:t.algorithmParams||u,optional:!0})]})}fromSchema(e){C(e,xw);const t=N(e,e,v.schema({names:{algorithmIdentifier:$m,algorithmParams:Mh}}));p.assertSchema(t,this.className),this.algorithmId=t.result.algorithm.valueBlock.toString(),Mh in t.result&&(this.algorithmParams=t.result.params)}toSchema(){const e=[];return e.push(new T({value:this.algorithmId})),this.algorithmParams&&!(this.algorithmParams instanceof K)&&e.push(this.algorithmParams),new f({value:e})}toJSON(){const e={algorithmId:this.algorithmId};return this.algorithmParams&&!(this.algorithmParams instanceof K)&&(e.algorithmParams=this.algorithmParams.toJSON()),e}isEqual(e){return!(e instanceof v)||this.algorithmId!==e.algorithmId?!1:this.algorithmParams?e.algorithmParams?JSON.stringify(this.algorithmParams)===JSON.stringify(e.algorithmParams):!1:!e.algorithmParams}}v.CLASS_NAME="AlgorithmIdentifier";const gr="altNames",Ow=[gr];class Wa extends k{constructor(e={}){super(),this.altNames=a(e,gr,Wa.defaultValues(gr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===gr?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.altNames||u,value:X.schema()})]})}fromSchema(e){C(e,Ow);const t=N(e,e,Wa.schema({names:{altNames:gr}}));p.assertSchema(t,this.className),gr in t.result&&(this.altNames=Array.from(t.result.altNames,s=>new X({schema:s})))}toSchema(){return new f({value:Array.from(this.altNames,e=>e.toSchema())})}toJSON(){return{altNames:Array.from(this.altNames,e=>e.toJSON())}}}Wa.CLASS_NAME="AltName";const wr="type",yr="values",Rw=[wr,yr];class le extends k{constructor(e={}){super(),this.type=a(e,wr,le.defaultValues(wr)),this.values=a(e,yr,le.defaultValues(yr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case wr:return u;case yr:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case wr:return t===u;case yr:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.type||u}),new pe({name:t.setName||u,value:[new J({name:t.values||u,value:new K})]})]})}fromSchema(e){C(e,Rw);const t=N(e,e,le.schema({names:{type:wr,values:yr}}));p.assertSchema(t,this.className),this.type=t.result.type.valueBlock.toString(),this.values=t.result.values}toSchema(){return new f({value:[new T({value:this.type}),new pe({value:this.values})]})}toJSON(){return{type:this.type,values:Array.from(this.values,e=>e.toJSON())}}}le.CLASS_NAME="Attribute";const Ao="notBeforeTime",po="notAfterTime",Tw=[Ao,po];class Rt extends k{constructor(e={}){super(),this.notBeforeTime=a(e,Ao,Rt.defaultValues(Ao)),this.notAfterTime=a(e,po,Rt.defaultValues(po)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ao:case po:return new Date(0,0,0);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new ue({name:t.notBeforeTime||u}),new ue({name:t.notAfterTime||u})]})}fromSchema(e){C(e,Tw);const t=N(e,e,Rt.schema({names:{notBeforeTime:Ao,notAfterTime:po}}));p.assertSchema(t,this.className),this.notBeforeTime=t.result.notBeforeTime.toDate(),this.notAfterTime=t.result.notAfterTime.toDate()}toSchema(){return new f({value:[new ue({valueDate:this.notBeforeTime}),new ue({valueDate:this.notAfterTime})]})}toJSON(){return{notBeforeTime:this.notBeforeTime,notAfterTime:this.notAfterTime}}}Rt.CLASS_NAME="AttCertValidityPeriod";const no="names",Gf="generalNames";class xe extends k{constructor(e={}){super(),this.names=a(e,no,xe.defaultValues(no)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e==="names"?[]:super.defaultValues(e)}static schema(e={},t=!1){const s=a(e,no,{});return new f({optional:t,name:s.blockName||u,value:[new J({name:s.generalNames||u,value:X.schema()})]})}fromSchema(e){C(e,[no,Gf]);const t=N(e,e,xe.schema({names:{blockName:no,generalNames:Gf}}));p.assertSchema(t,this.className),this.names=Array.from(t.result.generalNames,s=>new X({schema:s}))}toSchema(){return new f({value:Array.from(this.names,e=>e.toSchema())})}toJSON(){return{names:Array.from(this.names,e=>e.toJSON())}}}xe.CLASS_NAME="GeneralNames";const Dw="2.5.29.9",Pw="2.5.29.14",Lw="2.5.29.15",Uw="2.5.29.16",Mm="2.5.29.17",Km="2.5.29.18",bf="2.5.29.19",Hw="2.5.29.20",_w="2.5.29.27",$w="2.5.29.21",Mw="2.5.29.24",Jm="2.5.29.28",jm="2.5.29.29",Fm="2.5.29.30",qm="2.5.29.31",kf="2.5.29.46",Wm="2.5.29.32",gt="2.5.29.32.0",Kw="1.3.6.1.4.1.311.21.10",Gm="2.5.29.33",Ef="2.5.29.35",Ym="2.5.29.36",Jw="2.5.29.37",jw="2.5.29.54",Nf="1.3.6.1.5.5.7.1.1",Fw="1.3.6.1.5.5.7.1.11",qw="1.3.6.1.4.1.11129.2.4.2",Ww="1.3.6.1.4.1.311.21.7",Gw="1.3.6.1.4.1.311.21.1",Yw="1.3.6.1.5.5.7.1.3",Cf="1.2.840.113549.1.7.1",Qm="1.2.840.113549.1.7.2",Xm="1.2.840.113549.1.7.3",Zm="1.2.840.113549.1.7.6",Qw="1.2.840.113549.1.9.16.1.4",Yf="1.2.840.113549.1.9.22.1",Xw="1.2.840.113549.1.9.22.2",Qf="1.2.840.113549.1.9.22.3",Xf="1.2.840.113549.1.9.23.1",Zw="1.3.6.1.5.5.7",zw=`${Zw}.48`,nu=`${zw}.1.1`,Hn="keyIdentifier",_n="authorityCertIssuer",$n="authorityCertSerialNumber",ey=[Hn,_n,$n];class bn extends k{constructor(e={}){super(),Hn in e&&(this.keyIdentifier=a(e,Hn,bn.defaultValues(Hn))),_n in e&&(this.authorityCertIssuer=a(e,_n,bn.defaultValues(_n))),$n in e&&(this.authorityCertSerialNumber=a(e,$n,bn.defaultValues($n))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Hn:return new I;case _n:return[];case $n:return new S;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new _({name:t.keyIdentifier||u,optional:!0,idBlock:{tagClass:3,tagNumber:0}}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.authorityCertIssuer||u,value:X.schema()})]}),new _({name:t.authorityCertSerialNumber||u,optional:!0,idBlock:{tagClass:3,tagNumber:2}})]})}fromSchema(e){C(e,ey);const t=N(e,e,bn.schema({names:{keyIdentifier:Hn,authorityCertIssuer:_n,authorityCertSerialNumber:$n}}));p.assertSchema(t,this.className),Hn in t.result&&(this.keyIdentifier=new I({valueHex:t.result.keyIdentifier.valueBlock.valueHex})),_n in t.result&&(this.authorityCertIssuer=Array.from(t.result.authorityCertIssuer,s=>new X({schema:s}))),$n in t.result&&(this.authorityCertSerialNumber=new S({valueHex:t.result.authorityCertSerialNumber.valueBlock.valueHex}))}toSchema(){const e=[];return this.keyIdentifier&&e.push(new _({idBlock:{tagClass:3,tagNumber:0},valueHex:this.keyIdentifier.valueBlock.valueHexView})),this.authorityCertIssuer&&e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:Array.from(this.authorityCertIssuer,t=>t.toSchema())})),this.authorityCertSerialNumber&&e.push(new _({idBlock:{tagClass:3,tagNumber:2},valueHex:this.authorityCertSerialNumber.valueBlock.valueHexView})),new f({value:e})}toJSON(){const e={};return this.keyIdentifier&&(e.keyIdentifier=this.keyIdentifier.toJSON()),this.authorityCertIssuer&&(e.authorityCertIssuer=Array.from(this.authorityCertIssuer,t=>t.toJSON())),this.authorityCertSerialNumber&&(e.authorityCertSerialNumber=this.authorityCertSerialNumber.toJSON()),e}}bn.CLASS_NAME="AuthorityKeyIdentifier";const Pn="pathLenConstraint",Ln="cA";class qi extends k{constructor(e={}){super(),this.cA=a(e,Ln,!1),Pn in e&&(this.pathLenConstraint=a(e,Pn,0)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Ln?!1:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new Ft({optional:!0,name:t.cA||u}),new S({optional:!0,name:t.pathLenConstraint||u})]})}fromSchema(e){C(e,[Ln,Pn]);const t=N(e,e,qi.schema({names:{cA:Ln,pathLenConstraint:Pn}}));p.assertSchema(t,this.className),Ln in t.result&&(this.cA=t.result.cA.valueBlock.value),Pn in t.result&&(t.result.pathLenConstraint.valueBlock.isHexOnly?this.pathLenConstraint=t.result.pathLenConstraint:this.pathLenConstraint=t.result.pathLenConstraint.valueBlock.valueDec)}toSchema(){const e=[];return this.cA!==qi.defaultValues(Ln)&&e.push(new Ft({value:this.cA})),Pn in this&&(this.pathLenConstraint instanceof S?e.push(this.pathLenConstraint):e.push(new S({value:this.pathLenConstraint}))),new f({value:e})}toJSON(){const e={};return this.cA!==qi.defaultValues(Ln)&&(e.cA=this.cA),Pn in this&&(this.pathLenConstraint instanceof S?e.pathLenConstraint=this.pathLenConstraint.toJSON():e.pathLenConstraint=this.pathLenConstraint),e}}qi.CLASS_NAME="BasicConstraints";const lh="certificateIndex",ch="keyIndex";class pc extends k{constructor(e={}){super(),this.certificateIndex=a(e,lh,pc.defaultValues(lh)),this.keyIndex=a(e,ch,pc.defaultValues(ch)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case lh:case ch:return 0;default:return super.defaultValues(e)}}static schema(){return new S}fromSchema(e){if(e.constructor.blockName()!==S.blockName())throw new Error("Object's schema was not verified against input data for CAVersion");let t=e.valueBlock.valueHex.slice(0);const s=new Uint8Array(t);switch(!0){case t.byteLength<4:{const g=new ArrayBuffer(4);new Uint8Array(g).set(s,4-t.byteLength),t=g.slice(0)}break;case t.byteLength>4:{const g=new ArrayBuffer(4);new Uint8Array(g).set(s.slice(0,4)),t=g.slice(0)}break}const n=t.slice(0,2),i=new Uint8Array(n);let o=i[0];i[0]=i[1],i[1]=o;const l=new Uint16Array(n);this.keyIndex=l[0];const c=t.slice(2),h=new Uint8Array(c);o=h[0],h[0]=h[1],h[1]=o;const m=new Uint16Array(c);this.certificateIndex=m[0]}toSchema(){const e=new ArrayBuffer(2),t=new Uint16Array(e);t[0]=this.certificateIndex;const s=new Uint8Array(e);let n=s[0];s[0]=s[1],s[1]=n;const i=new ArrayBuffer(2),o=new Uint16Array(i);o[0]=this.keyIndex;const l=new Uint8Array(i);return n=l[0],l[0]=l[1],l[1]=n,new S({valueHex:Ua(i,e)})}toJSON(){return{certificateIndex:this.certificateIndex,keyIndex:this.keyIndex}}}pc.CLASS_NAME="CAVersion";const bo="policyQualifierId",ko="qualifier",ty=[bo,ko];class Wi extends k{constructor(e={}){super(),this.policyQualifierId=a(e,bo,Wi.defaultValues(bo)),this.qualifier=a(e,ko,Wi.defaultValues(ko)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case bo:return u;case ko:return new K;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.policyQualifierId||u}),new K({name:t.qualifier||u})]})}fromSchema(e){C(e,ty);const t=N(e,e,Wi.schema({names:{policyQualifierId:bo,qualifier:ko}}));p.assertSchema(t,this.className),this.policyQualifierId=t.result.policyQualifierId.valueBlock.toString(),this.qualifier=t.result.qualifier}toSchema(){return new f({value:[new T({value:this.policyQualifierId}),this.qualifier]})}toJSON(){return{policyQualifierId:this.policyQualifierId,qualifier:this.qualifier.toJSON()}}}Wi.CLASS_NAME="PolicyQualifierInfo";const Eo="policyIdentifier",Mn="policyQualifiers",sy=[Eo,Mn];class Gi extends k{constructor(e={}){super(),this.policyIdentifier=a(e,Eo,Gi.defaultValues(Eo)),Mn in e&&(this.policyQualifiers=a(e,Mn,Gi.defaultValues(Mn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Eo:return u;case Mn:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.policyIdentifier||u}),new f({optional:!0,value:[new J({name:t.policyQualifiers||u,value:Wi.schema()})]})]})}fromSchema(e){C(e,sy);const t=N(e,e,Gi.schema({names:{policyIdentifier:Eo,policyQualifiers:Mn}}));p.assertSchema(t,this.className),this.policyIdentifier=t.result.policyIdentifier.valueBlock.toString(),Mn in t.result&&(this.policyQualifiers=Array.from(t.result.policyQualifiers,s=>new Wi({schema:s})))}toSchema(){const e=[];return e.push(new T({value:this.policyIdentifier})),this.policyQualifiers&&e.push(new f({value:Array.from(this.policyQualifiers,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={policyIdentifier:this.policyIdentifier};return this.policyQualifiers&&(e.policyQualifiers=Array.from(this.policyQualifiers,t=>t.toJSON())),e}}Gi.CLASS_NAME="PolicyInformation";const No="certificatePolicies",ny=[No];class Ga extends k{constructor(e={}){super(),this.certificatePolicies=a(e,No,Ga.defaultValues(No)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===No?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.certificatePolicies||u,value:Gi.schema()})]})}fromSchema(e){C(e,ny);const t=N(e,e,Ga.schema({names:{certificatePolicies:No}}));p.assertSchema(t,this.className),this.certificatePolicies=Array.from(t.result.certificatePolicies,s=>new Gi({schema:s}))}toSchema(){return new f({value:Array.from(this.certificatePolicies,e=>e.toSchema())})}toJSON(){return{certificatePolicies:Array.from(this.certificatePolicies,e=>e.toJSON())}}}Ga.CLASS_NAME="CertificatePolicies";const Co="templateID",Qt="templateMajorVersion",Xt="templateMinorVersion",iy=[Co,Qt,Xt];class Pa extends k{constructor(e={}){super(),this.templateID=a(e,Co,Pa.defaultValues(Co)),Qt in e&&(this.templateMajorVersion=a(e,Qt,Pa.defaultValues(Qt))),Xt in e&&(this.templateMinorVersion=a(e,Xt,Pa.defaultValues(Xt))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Co:return u;case Qt:case Xt:return 0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.templateID||u}),new S({name:t.templateMajorVersion||u,optional:!0}),new S({name:t.templateMinorVersion||u,optional:!0})]})}fromSchema(e){C(e,iy);const t=N(e,e,Pa.schema({names:{templateID:Co,templateMajorVersion:Qt,templateMinorVersion:Xt}}));p.assertSchema(t,this.className),this.templateID=t.result.templateID.valueBlock.toString(),Qt in t.result&&(this.templateMajorVersion=t.result.templateMajorVersion.valueBlock.valueDec),Xt in t.result&&(this.templateMinorVersion=t.result.templateMinorVersion.valueBlock.valueDec)}toSchema(){const e=[];return e.push(new T({value:this.templateID})),Qt in this&&e.push(new S({value:this.templateMajorVersion})),Xt in this&&e.push(new S({value:this.templateMinorVersion})),new f({value:e})}toJSON(){const e={templateID:this.templateID};return Qt in this&&(e.templateMajorVersion=this.templateMajorVersion),Xt in this&&(e.templateMinorVersion=this.templateMinorVersion),e}}const Kn="distributionPoint",zm="distributionPointNames",Jn="reasons",jn="cRLIssuer",eg="cRLIssuerNames",ry=[Kn,zm,Jn,jn,eg];class kn extends k{constructor(e={}){super(),Kn in e&&(this.distributionPoint=a(e,Kn,kn.defaultValues(Kn))),Jn in e&&(this.reasons=a(e,Jn,kn.defaultValues(Jn))),jn in e&&(this.cRLIssuer=a(e,jn,kn.defaultValues(jn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Kn:return[];case Jn:return new W;case jn:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new he({value:[new w({name:t.distributionPoint||u,optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.distributionPointNames||u,value:X.schema()})]}),new w({name:t.distributionPoint||u,optional:!0,idBlock:{tagClass:3,tagNumber:1},value:re.schema().valueBlock.value})]})]}),new _({name:t.reasons||u,optional:!0,idBlock:{tagClass:3,tagNumber:1}}),new w({name:t.cRLIssuer||u,optional:!0,idBlock:{tagClass:3,tagNumber:2},value:[new J({name:t.cRLIssuerNames||u,value:X.schema()})]})]})}fromSchema(e){C(e,ry);const t=N(e,e,kn.schema({names:{distributionPoint:Kn,distributionPointNames:zm,reasons:Jn,cRLIssuer:jn,cRLIssuerNames:eg}}));p.assertSchema(t,this.className),Kn in t.result&&(t.result.distributionPoint.idBlock.tagNumber===0&&(this.distributionPoint=Array.from(t.result.distributionPointNames,s=>new X({schema:s}))),t.result.distributionPoint.idBlock.tagNumber===1&&(this.distributionPoint=new re({schema:new f({value:t.result.distributionPoint.valueBlock.value})}))),Jn in t.result&&(this.reasons=new W({valueHex:t.result.reasons.valueBlock.valueHex})),jn in t.result&&(this.cRLIssuer=Array.from(t.result.cRLIssuerNames,s=>new X({schema:s})))}toSchema(){const e=[];if(this.distributionPoint){let t;this.distributionPoint instanceof Array?t=new w({idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.distributionPoint,s=>s.toSchema())}):t=new w({idBlock:{tagClass:3,tagNumber:1},value:[this.distributionPoint.toSchema()]}),e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[t]}))}return this.reasons&&e.push(new _({idBlock:{tagClass:3,tagNumber:1},valueHex:this.reasons.valueBlock.valueHexView})),this.cRLIssuer&&e.push(new w({idBlock:{tagClass:3,tagNumber:2},value:Array.from(this.cRLIssuer,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={};return this.distributionPoint&&(this.distributionPoint instanceof Array?e.distributionPoint=Array.from(this.distributionPoint,t=>t.toJSON()):e.distributionPoint=this.distributionPoint.toJSON()),this.reasons&&(e.reasons=this.reasons.toJSON()),this.cRLIssuer&&(e.cRLIssuer=Array.from(this.cRLIssuer,t=>t.toJSON())),e}}kn.CLASS_NAME="DistributionPoint";const Bo="distributionPoints",ay=[Bo];class Ya extends k{constructor(e={}){super(),this.distributionPoints=a(e,Bo,Ya.defaultValues(Bo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Bo?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.distributionPoints||u,value:kn.schema()})]})}fromSchema(e){C(e,ay);const t=N(e,e,Ya.schema({names:{distributionPoints:Bo}}));p.assertSchema(t,this.className),this.distributionPoints=Array.from(t.result.distributionPoints,s=>new kn({schema:s}))}toSchema(){return new f({value:Array.from(this.distributionPoints,e=>e.toSchema())})}toJSON(){return{distributionPoints:Array.from(this.distributionPoints,e=>e.toJSON())}}}Ya.CLASS_NAME="CRLDistributionPoints";const Io="keyPurposes",oy=[Io];class bc extends k{constructor(e={}){super(),this.keyPurposes=a(e,Io,bc.defaultValues(Io)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Io?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.keyPurposes||u,value:new T})]})}fromSchema(e){C(e,oy);const t=N(e,e,bc.schema({names:{keyPurposes:Io}}));p.assertSchema(t,this.className),this.keyPurposes=Array.from(t.result.keyPurposes,s=>s.valueBlock.toString())}toSchema(){return new f({value:Array.from(this.keyPurposes,e=>new T({value:e}))})}toJSON(){return{keyPurposes:Array.from(this.keyPurposes)}}}bc.CLASS_NAME="ExtKeyUsage";const io="accessDescriptions";class Qa extends k{constructor(e={}){super(),this.accessDescriptions=a(e,io,Qa.defaultValues(io)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===io?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.accessDescriptions||u,value:Fi.schema()})]})}fromSchema(e){C(e,[io]);const t=N(e,e,Qa.schema({names:{accessDescriptions:io}}));p.assertSchema(t,this.className),this.accessDescriptions=Array.from(t.result.accessDescriptions,s=>new Fi({schema:s}))}toSchema(){return new f({value:Array.from(this.accessDescriptions,e=>e.toSchema())})}toJSON(){return{accessDescriptions:Array.from(this.accessDescriptions,e=>e.toJSON())}}}Qa.CLASS_NAME="InfoAccess";const Fn="distributionPoint",tg="distributionPointNames",Ds="onlyContainsUserCerts",Ps="onlyContainsCACerts",Ls="onlySomeReasons",Us="indirectCRL",Hs="onlyContainsAttributeCerts",ly=[Fn,tg,Ds,Ps,Ls,Us,Hs];class De extends k{constructor(e={}){super(),Fn in e&&(this.distributionPoint=a(e,Fn,De.defaultValues(Fn))),this.onlyContainsUserCerts=a(e,Ds,De.defaultValues(Ds)),this.onlyContainsCACerts=a(e,Ps,De.defaultValues(Ps)),Ls in e&&(this.onlySomeReasons=a(e,Ls,De.defaultValues(Ls))),this.indirectCRL=a(e,Us,De.defaultValues(Us)),this.onlyContainsAttributeCerts=a(e,Hs,De.defaultValues(Hs)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Fn:return[];case Ds:return!1;case Ps:return!1;case Ls:return 0;case Us:return!1;case Hs:return!1;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new he({value:[new w({name:t.distributionPoint||u,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.distributionPointNames||u,value:X.schema()})]}),new w({name:t.distributionPoint||u,idBlock:{tagClass:3,tagNumber:1},value:re.schema().valueBlock.value})]})]}),new _({name:t.onlyContainsUserCerts||u,optional:!0,idBlock:{tagClass:3,tagNumber:1}}),new _({name:t.onlyContainsCACerts||u,optional:!0,idBlock:{tagClass:3,tagNumber:2}}),new _({name:t.onlySomeReasons||u,optional:!0,idBlock:{tagClass:3,tagNumber:3}}),new _({name:t.indirectCRL||u,optional:!0,idBlock:{tagClass:3,tagNumber:4}}),new _({name:t.onlyContainsAttributeCerts||u,optional:!0,idBlock:{tagClass:3,tagNumber:5}})]})}fromSchema(e){C(e,ly);const t=N(e,e,De.schema({names:{distributionPoint:Fn,distributionPointNames:tg,onlyContainsUserCerts:Ds,onlyContainsCACerts:Ps,onlySomeReasons:Ls,indirectCRL:Us,onlyContainsAttributeCerts:Hs}}));if(p.assertSchema(t,this.className),Fn in t.result)switch(!0){case t.result.distributionPoint.idBlock.tagNumber===0:this.distributionPoint=Array.from(t.result.distributionPointNames,s=>new X({schema:s}));break;case t.result.distributionPoint.idBlock.tagNumber===1:this.distributionPoint=new re({schema:new f({value:t.result.distributionPoint.valueBlock.value})});break;default:throw new Error("Unknown tagNumber for distributionPoint: {$asn1.result.distributionPoint.idBlock.tagNumber}")}if(Ds in t.result){const s=new Uint8Array(t.result.onlyContainsUserCerts.valueBlock.valueHex);this.onlyContainsUserCerts=s[0]!==0}if(Ps in t.result){const s=new Uint8Array(t.result.onlyContainsCACerts.valueBlock.valueHex);this.onlyContainsCACerts=s[0]!==0}if(Ls in t.result){const s=new Uint8Array(t.result.onlySomeReasons.valueBlock.valueHex);this.onlySomeReasons=s[0]}if(Us in t.result){const s=new Uint8Array(t.result.indirectCRL.valueBlock.valueHex);this.indirectCRL=s[0]!==0}if(Hs in t.result){const s=new Uint8Array(t.result.onlyContainsAttributeCerts.valueBlock.valueHex);this.onlyContainsAttributeCerts=s[0]!==0}}toSchema(){const e=[];if(this.distributionPoint){let t;this.distributionPoint instanceof Array?t=new w({idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.distributionPoint,s=>s.toSchema())}):(t=this.distributionPoint.toSchema(),t.idBlock.tagClass=3,t.idBlock.tagNumber=1),e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[t]}))}if(this.onlyContainsUserCerts!==De.defaultValues(Ds)&&e.push(new _({idBlock:{tagClass:3,tagNumber:1},valueHex:new Uint8Array([255]).buffer})),this.onlyContainsCACerts!==De.defaultValues(Ps)&&e.push(new _({idBlock:{tagClass:3,tagNumber:2},valueHex:new Uint8Array([255]).buffer})),this.onlySomeReasons!==void 0){const t=new ArrayBuffer(1),s=new Uint8Array(t);s[0]=this.onlySomeReasons,e.push(new _({idBlock:{tagClass:3,tagNumber:3},valueHex:t}))}return this.indirectCRL!==De.defaultValues(Us)&&e.push(new _({idBlock:{tagClass:3,tagNumber:4},valueHex:new Uint8Array([255]).buffer})),this.onlyContainsAttributeCerts!==De.defaultValues(Hs)&&e.push(new _({idBlock:{tagClass:3,tagNumber:5},valueHex:new Uint8Array([255]).buffer})),new f({value:e})}toJSON(){const e={};return this.distributionPoint&&(this.distributionPoint instanceof Array?e.distributionPoint=Array.from(this.distributionPoint,t=>t.toJSON()):e.distributionPoint=this.distributionPoint.toJSON()),this.onlyContainsUserCerts!==De.defaultValues(Ds)&&(e.onlyContainsUserCerts=this.onlyContainsUserCerts),this.onlyContainsCACerts!==De.defaultValues(Ps)&&(e.onlyContainsCACerts=this.onlyContainsCACerts),Ls in this&&(e.onlySomeReasons=this.onlySomeReasons),this.indirectCRL!==De.defaultValues(Us)&&(e.indirectCRL=this.indirectCRL),this.onlyContainsAttributeCerts!==De.defaultValues(Hs)&&(e.onlyContainsAttributeCerts=this.onlyContainsAttributeCerts),e}}De.CLASS_NAME="IssuingDistributionPoint";const Vo="base",vr="minimum",_s="maximum",cy=[Vo,vr,_s];class Mt extends k{constructor(e={}){super(),this.base=a(e,Vo,Mt.defaultValues(Vo)),this.minimum=a(e,vr,Mt.defaultValues(vr)),_s in e&&(this.maximum=a(e,_s,Mt.defaultValues(_s))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Vo:return new X;case vr:return 0;case _s:return 0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[X.schema(t.base||{}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({name:t.minimum||u})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new S({name:t.maximum||u})]})]})}fromSchema(e){C(e,cy);const t=N(e,e,Mt.schema({names:{base:{names:{blockName:Vo}},minimum:vr,maximum:_s}}));p.assertSchema(t,this.className),this.base=new X({schema:t.result.base}),vr in t.result&&(t.result.minimum.valueBlock.isHexOnly?this.minimum=t.result.minimum:this.minimum=t.result.minimum.valueBlock.valueDec),_s in t.result&&(t.result.maximum.valueBlock.isHexOnly?this.maximum=t.result.maximum:this.maximum=t.result.maximum.valueBlock.valueDec)}toSchema(){const e=[];if(e.push(this.base.toSchema()),this.minimum!==0){let t=0;this.minimum instanceof S?t=this.minimum:t=new S({value:this.minimum}),e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[t]}))}if(_s in this){let t=0;this.maximum instanceof S?t=this.maximum:t=new S({value:this.maximum}),e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[t]}))}return new f({value:e})}toJSON(){const e={base:this.base.toJSON()};return this.minimum!==0&&(typeof this.minimum=="number"?e.minimum=this.minimum:e.minimum=this.minimum.toJSON()),this.maximum!==void 0&&(typeof this.maximum=="number"?e.maximum=this.maximum:e.maximum=this.maximum.toJSON()),e}}Mt.CLASS_NAME="GeneralSubtree";const qn="permittedSubtrees",Wn="excludedSubtrees",uy=[qn,Wn];class _a extends k{constructor(e={}){super(),qn in e&&(this.permittedSubtrees=a(e,qn,_a.defaultValues(qn))),Wn in e&&(this.excludedSubtrees=a(e,Wn,_a.defaultValues(Wn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case qn:case Wn:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.permittedSubtrees||u,value:Mt.schema()})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.excludedSubtrees||u,value:Mt.schema()})]})]})}fromSchema(e){C(e,uy);const t=N(e,e,_a.schema({names:{permittedSubtrees:qn,excludedSubtrees:Wn}}));p.assertSchema(t,this.className),qn in t.result&&(this.permittedSubtrees=Array.from(t.result.permittedSubtrees,s=>new Mt({schema:s}))),Wn in t.result&&(this.excludedSubtrees=Array.from(t.result.excludedSubtrees,s=>new Mt({schema:s})))}toSchema(){const e=[];return this.permittedSubtrees&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.permittedSubtrees,t=>t.toSchema())})),this.excludedSubtrees&&e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:Array.from(this.excludedSubtrees,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={};return this.permittedSubtrees&&(e.permittedSubtrees=Array.from(this.permittedSubtrees,t=>t.toJSON())),this.excludedSubtrees&&(e.excludedSubtrees=Array.from(this.excludedSubtrees,t=>t.toJSON())),e}}_a.CLASS_NAME="NameConstraints";const Zt="requireExplicitPolicy",zt="inhibitPolicyMapping",hy=[Zt,zt];class $a extends k{constructor(e={}){super(),Zt in e&&(this.requireExplicitPolicy=a(e,Zt,$a.defaultValues(Zt))),zt in e&&(this.inhibitPolicyMapping=a(e,zt,$a.defaultValues(zt))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Zt:return 0;case zt:return 0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new _({name:t.requireExplicitPolicy||u,optional:!0,idBlock:{tagClass:3,tagNumber:0}}),new _({name:t.inhibitPolicyMapping||u,optional:!0,idBlock:{tagClass:3,tagNumber:1}})]})}fromSchema(e){C(e,hy);const t=N(e,e,$a.schema({names:{requireExplicitPolicy:Zt,inhibitPolicyMapping:zt}}));if(p.assertSchema(t,this.className),Zt in t.result){const s=t.result.requireExplicitPolicy;s.idBlock.tagClass=1,s.idBlock.tagNumber=2;const n=s.toBER(!1),i=Oe(n);p.assert(i,"Integer"),this.requireExplicitPolicy=i.result.valueBlock.valueDec}if(zt in t.result){const s=t.result.inhibitPolicyMapping;s.idBlock.tagClass=1,s.idBlock.tagNumber=2;const n=s.toBER(!1),i=Oe(n);p.assert(i,"Integer"),this.inhibitPolicyMapping=i.result.valueBlock.valueDec}}toSchema(){const e=[];if(Zt in this){const t=new S({value:this.requireExplicitPolicy});t.idBlock.tagClass=3,t.idBlock.tagNumber=0,e.push(t)}if(zt in this){const t=new S({value:this.inhibitPolicyMapping});t.idBlock.tagClass=3,t.idBlock.tagNumber=1,e.push(t)}return new f({value:e})}toJSON(){const e={};return Zt in this&&(e.requireExplicitPolicy=this.requireExplicitPolicy),zt in this&&(e.inhibitPolicyMapping=this.inhibitPolicyMapping),e}}$a.CLASS_NAME="PolicyConstraints";const xo="issuerDomainPolicy",Oo="subjectDomainPolicy",fy=[xo,Oo];class Yi extends k{constructor(e={}){super(),this.issuerDomainPolicy=a(e,xo,Yi.defaultValues(xo)),this.subjectDomainPolicy=a(e,Oo,Yi.defaultValues(Oo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case xo:return u;case Oo:return u;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.issuerDomainPolicy||u}),new T({name:t.subjectDomainPolicy||u})]})}fromSchema(e){C(e,fy);const t=N(e,e,Yi.schema({names:{issuerDomainPolicy:xo,subjectDomainPolicy:Oo}}));p.assertSchema(t,this.className),this.issuerDomainPolicy=t.result.issuerDomainPolicy.valueBlock.toString(),this.subjectDomainPolicy=t.result.subjectDomainPolicy.valueBlock.toString()}toSchema(){return new f({value:[new T({value:this.issuerDomainPolicy}),new T({value:this.subjectDomainPolicy})]})}toJSON(){return{issuerDomainPolicy:this.issuerDomainPolicy,subjectDomainPolicy:this.subjectDomainPolicy}}}Yi.CLASS_NAME="PolicyMapping";const Ro="mappings",dy=[Ro];class kc extends k{constructor(e={}){super(),this.mappings=a(e,Ro,kc.defaultValues(Ro)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Ro?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.mappings||u,value:Yi.schema()})]})}fromSchema(e){C(e,dy);const t=N(e,e,kc.schema({names:{mappings:Ro}}));p.assertSchema(t,this.className),this.mappings=Array.from(t.result.mappings,s=>new Yi({schema:s}))}toSchema(){return new f({value:Array.from(this.mappings,e=>e.toSchema())})}toJSON(){return{mappings:Array.from(this.mappings,e=>e.toJSON())}}}kc.CLASS_NAME="PolicyMappings";const $s="notBefore",Ms="notAfter",my=[$s,Ms];class Ma extends k{constructor(e={}){super(),$s in e&&(this.notBefore=a(e,$s,Ma.defaultValues($s))),Ms in e&&(this.notAfter=a(e,Ms,Ma.defaultValues(Ms))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case $s:return new Date;case Ms:return new Date;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new _({name:t.notBefore||u,optional:!0,idBlock:{tagClass:3,tagNumber:0}}),new _({name:t.notAfter||u,optional:!0,idBlock:{tagClass:3,tagNumber:1}})]})}fromSchema(e){C(e,my);const t=N(e,e,Ma.schema({names:{notBefore:$s,notAfter:Ms}}));if(p.assertSchema(t,this.className),$s in t.result){const s=new ue;s.fromBuffer(t.result.notBefore.valueBlock.valueHex),this.notBefore=s.toDate()}if(Ms in t.result){const s=new ue({valueHex:t.result.notAfter.valueBlock.valueHex});s.fromBuffer(t.result.notAfter.valueBlock.valueHex),this.notAfter=s.toDate()}}toSchema(){const e=[];return $s in this&&e.push(new _({idBlock:{tagClass:3,tagNumber:0},valueHex:new ue({valueDate:this.notBefore}).valueBlock.valueHexView})),Ms in this&&e.push(new _({idBlock:{tagClass:3,tagNumber:1},valueHex:new ue({valueDate:this.notAfter}).valueBlock.valueHexView})),new f({value:e})}toJSON(){const e={};return this.notBefore&&(e.notBefore=this.notBefore),this.notAfter&&(e.notAfter=this.notAfter),e}}Ma.CLASS_NAME="PrivateKeyUsagePeriod";const Sr="id",es="type",Ar="values",gy=[Sr,es],wy=[Ar];class Qi extends k{constructor(e={}){super(),this.id=a(e,Sr,Qi.defaultValues(Sr)),es in e&&(this.type=a(e,es,Qi.defaultValues(es))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Sr:return u;case es:return new Ae;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Sr:return t===u;case es:return t instanceof Ae;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.id||u}),new K({name:t.type||u,optional:!0})]})}fromSchema(e){C(e,gy);const t=N(e,e,Qi.schema({names:{id:Sr,type:es}}));p.assertSchema(t,this.className),this.id=t.result.id.valueBlock.toString(),es in t.result&&(this.type=t.result.type)}toSchema(){const e=[new T({value:this.id})];return es in this&&e.push(this.type),new f({value:e})}toJSON(){const e={id:this.id};return this.type&&(e.type=this.type.toJSON()),e}}Qi.CLASS_NAME="QCStatement";class Ec extends k{constructor(e={}){super(),this.values=a(e,Ar,Ec.defaultValues(Ar)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Ar?[]:super.defaultValues(e)}static compareWithDefault(e,t){return e===Ar?t.length===0:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.values||u,value:Qi.schema(t.value||{})})]})}fromSchema(e){C(e,wy);const t=N(e,e,Ec.schema({names:{values:Ar}}));p.assertSchema(t,this.className),this.values=Array.from(t.result.values,s=>new Qi({schema:s}))}toSchema(){return new f({value:Array.from(this.values,e=>e.toSchema())})}toJSON(){return{values:Array.from(this.values,e=>e.toJSON())}}}Ec.CLASS_NAME="QCStatements";var Gn;class Vn{static register(e,t,s){this.namedCurves[e.toLowerCase()]=this.namedCurves[t]={name:e,id:t,size:s}}static find(e){return this.namedCurves[e.toLowerCase()]||null}}Gn=Vn;Vn.namedCurves={};Gn.register("P-256","1.2.840.10045.3.1.7",32),Gn.register("P-384","1.3.132.0.34",48),Gn.register("P-521","1.3.132.0.35",66),Gn.register("brainpoolP256r1","1.3.36.3.3.2.8.1.1.7",32),Gn.register("brainpoolP384r1","1.3.36.3.3.2.8.1.1.11",48),Gn.register("brainpoolP512r1","1.3.36.3.3.2.8.1.1.13",64);const Rc="x",Tc="y",Dc="namedCurve";class Qe extends k{constructor(e={}){super(),this.x=a(e,Rc,Qe.defaultValues(Rc)),this.y=a(e,Tc,Qe.defaultValues(Tc)),this.namedCurve=a(e,Dc,Qe.defaultValues(Dc)),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Rc:case Tc:return be;case Dc:return u;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Rc:case Tc:return t instanceof ArrayBuffer&&ja(t,Qe.defaultValues(e));case Dc:return typeof t=="string"&&t===Qe.defaultValues(e);default:return super.defaultValues(e)}}static schema(){return new Lu}fromSchema(e){const t=L.toUint8Array(e);if(t[0]!==4)throw new Error("Object's schema was not verified against input data for ECPublicKey");const s=Vn.find(this.namedCurve);if(!s)throw new Error(`Incorrect curve OID: ${this.namedCurve}`);const n=s.size;if(t.byteLength!==n*2+1)throw new Error("Object's schema was not verified against input data for ECPublicKey");this.namedCurve=s.name,this.x=t.slice(1,n+1).buffer,this.y=t.slice(1+n,n*2+1).buffer}toSchema(){return new Lu({data:Ua(new Uint8Array([4]).buffer,this.x,this.y)})}toJSON(){const e=Vn.find(this.namedCurve);return{crv:e?e.name:this.namedCurve,x:Uh(Du(this.x),!0,!0,!1),y:Uh(Du(this.y),!0,!0,!1)}}fromJSON(e){Q.assert("json",e,"crv","x","y");let t=0;const s=Vn.find(e.crv);s&&(this.namedCurve=s.id,t=s.size);const n=Fa(wc(e.x,!0));if(n.byteLengthnew cs({schema:s})))}toSchema(){const e=[];return e.push(new S({value:this.version})),e.push(this.modulus.convertToDER()),e.push(this.publicExponent),e.push(this.privateExponent.convertToDER()),e.push(this.prime1.convertToDER()),e.push(this.prime2.convertToDER()),e.push(this.exponent1.convertToDER()),e.push(this.exponent2.convertToDER()),e.push(this.coefficient.convertToDER()),this.otherPrimeInfos&&e.push(new f({value:Array.from(this.otherPrimeInfos,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={n:H.ToBase64Url(this.modulus.valueBlock.valueHexView),e:H.ToBase64Url(this.publicExponent.valueBlock.valueHexView),d:H.ToBase64Url(this.privateExponent.valueBlock.valueHexView),p:H.ToBase64Url(this.prime1.valueBlock.valueHexView),q:H.ToBase64Url(this.prime2.valueBlock.valueHexView),dp:H.ToBase64Url(this.exponent1.valueBlock.valueHexView),dq:H.ToBase64Url(this.exponent2.valueBlock.valueHexView),qi:H.ToBase64Url(this.coefficient.valueBlock.valueHexView)};return this.otherPrimeInfos&&(e.oth=Array.from(this.otherPrimeInfos,t=>t.toJSON())),e}fromJSON(e){Q.assert("json",e,"n","e","d","p","q","dp","dq","qi"),this.modulus=new S({valueHex:H.FromBase64Url(e.n)}),this.publicExponent=new S({valueHex:H.FromBase64Url(e.e)}),this.privateExponent=new S({valueHex:H.FromBase64Url(e.d)}),this.prime1=new S({valueHex:H.FromBase64Url(e.p)}),this.prime2=new S({valueHex:H.FromBase64Url(e.q)}),this.exponent1=new S({valueHex:H.FromBase64Url(e.dp)}),this.exponent2=new S({valueHex:H.FromBase64Url(e.dq)}),this.coefficient=new S({valueHex:H.FromBase64Url(e.qi)}),e.oth&&(this.otherPrimeInfos=Array.from(e.oth,t=>new cs({json:t})))}}qe.CLASS_NAME="RSAPrivateKey";const Yo="version",Qo="privateKeyAlgorithm",Xo="privateKey",Qn="attributes",Pc="parsedKey",by=[Yo,Qo,Xo,Qn];class St extends k{constructor(e={}){super(),this.version=a(e,Yo,St.defaultValues(Yo)),this.privateKeyAlgorithm=a(e,Qo,St.defaultValues(Qo)),this.privateKey=a(e,Xo,St.defaultValues(Xo)),Qn in e&&(this.attributes=a(e,Qn,St.defaultValues(Qn))),Pc in e&&(this.parsedKey=a(e,Pc,St.defaultValues(Pc))),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Yo:return 0;case Qo:return new v;case Xo:return new I;case Qn:return[];case Pc:return{};default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),v.schema(t.privateKeyAlgorithm||{}),new I({name:t.privateKey||u}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.attributes||u,value:le.schema()})]})]})}fromSchema(e){C(e,by);const t=N(e,e,St.schema({names:{version:Yo,privateKeyAlgorithm:{names:{blockName:Qo}},privateKey:Xo,attributes:Qn}}));switch(p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.privateKeyAlgorithm=new v({schema:t.result.privateKeyAlgorithm}),this.privateKey=t.result.privateKey,Qn in t.result&&(this.attributes=Array.from(t.result.attributes,s=>new le({schema:s}))),this.privateKeyAlgorithm.algorithmId){case"1.2.840.113549.1.1.1":{const s=Oe(this.privateKey.valueBlock.valueHexView);s.offset!==-1&&(this.parsedKey=new qe({schema:s.result}))}break;case"1.2.840.10045.2.1":if("algorithmParams"in this.privateKeyAlgorithm&&this.privateKeyAlgorithm.algorithmParams instanceof T){const s=Oe(this.privateKey.valueBlock.valueHexView);s.offset!==-1&&(this.parsedKey=new yt({namedCurve:this.privateKeyAlgorithm.algorithmParams.valueBlock.toString(),schema:s.result}))}break}}toSchema(){const e=[new S({value:this.version}),this.privateKeyAlgorithm.toSchema(),this.privateKey];return this.attributes&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.attributes,t=>t.toSchema())})),new f({value:e})}toJSON(){if(!this.parsedKey){const s={version:this.version,privateKeyAlgorithm:this.privateKeyAlgorithm.toJSON(),privateKey:this.privateKey.toJSON()};return this.attributes&&(s.attributes=Array.from(this.attributes,n=>n.toJSON())),s}const e={};switch(this.privateKeyAlgorithm.algorithmId){case"1.2.840.10045.2.1":e.kty="EC";break;case"1.2.840.113549.1.1.1":e.kty="RSA";break}const t=this.parsedKey.toJSON();return Object.assign(e,t),e}fromJSON(e){if("kty"in e){switch(e.kty.toUpperCase()){case"EC":this.parsedKey=new yt({json:e}),this.privateKeyAlgorithm=new v({algorithmId:"1.2.840.10045.2.1",algorithmParams:new T({value:this.parsedKey.namedCurve})});break;case"RSA":this.parsedKey=new qe({json:e}),this.privateKeyAlgorithm=new v({algorithmId:"1.2.840.113549.1.1.1",algorithmParams:new Ae});break;default:throw new Error(`Invalid value for "kty" parameter: ${e.kty}`)}this.privateKey=new I({valueHex:this.parsedKey.toSchema().toBER(!1)})}}}St.CLASS_NAME="PrivateKeyInfo";const kr="contentType",Er="contentEncryptionAlgorithm",Xn="encryptedContent",ky=[kr,Er,Xn],Zf=1024;class Ee extends k{constructor(e={}){if(super(),this.contentType=a(e,kr,Ee.defaultValues(kr)),this.contentEncryptionAlgorithm=a(e,Er,Ee.defaultValues(Er)),Xn in e&&e.encryptedContent&&(this.encryptedContent=e.encryptedContent,this.encryptedContent.idBlock.tagClass===1&&this.encryptedContent.idBlock.tagNumber===4&&this.encryptedContent.idBlock.isConstructed===!1&&!e.disableSplit)){const t=new I({idBlock:{isConstructed:!0},isConstructed:!0});let s=0;const n=this.encryptedContent.valueBlock.valueHexView.slice().buffer;let i=n.byteLength;for(;i>0;){const o=new Uint8Array(n,s,s+Zf>n.byteLength?n.byteLength-s:Zf),l=new ArrayBuffer(o.length),c=new Uint8Array(l);for(let h=0;hV!==c[R])&&(h=String.fromCharCode(...c));const g=new Uint8Array(h.length*2+2),d=new DataView(g.buffer);for(let V=0;VA[R%A.length]),y=new Uint8Array(o*Math.ceil(g.length/o)).map((V,R)=>g[R%g.length]);let O=new Uint8Array(E.length+y.length);O.set(E),O.set(y,E.length);const x=Math.ceil((e>>3)/i),B=[];for(let V=0;VR[ye%R.length]),te=Math.ceil(A.length/o)+Math.ceil(g.length/o),j=[];for(let Z=0;Z=0;ae--)se>>=8,se+=$[ae]+(ye[ae]||0),ye[ae]=se&255;j.push(...ye)}O=new Uint8Array(j),B.push(...R)}return new Uint8Array(B.slice(0,e>>3)).buffer}function sg(r){const e=typeof r=="string"?{name:r}:r;return"hash"in e?{...e,hash:sg(e.hash)}:e}class Uu extends By{async importKey(e,t,s,n,i){var o,l,c,h,m,g;let d={};const b=sg(s);switch(e.toLowerCase()){case"raw":return this.subtle.importKey("raw",t,s,n,i);case"spki":{const A=Oe(L.toArrayBuffer(t));p.assert(A,"keyData");const E=new je;try{E.fromSchema(A.result)}catch{throw new ie("Incorrect keyData")}switch(b.name.toUpperCase()){case"RSA-PSS":{if(i=["verify"],d.kty="RSA",d.ext=n,d.key_ops=i,!["1.2.840.113549.1.1.1","1.2.840.113549.1.1.10"].includes(E.algorithm.algorithmId))throw new Error(`Incorrect public key algorithm: ${E.algorithm.algorithmId}`);if(!b.hash)throw new Q("hash","algorithm.hash","Incorrect hash algorithm: Hash algorithm is missed");switch(b.hash.name.toUpperCase()){case"SHA-1":d.alg="PS1";break;case"SHA-256":d.alg="PS256";break;case"SHA-384":d.alg="PS384";break;case"SHA-512":d.alg="PS512";break;default:throw new Error(`Incorrect hash algorithm: ${b.hash.name.toUpperCase()}`)}const y=E.toJSON();Object.assign(d,y)}break;case"RSASSA-PKCS1-V1_5":{if(i=["verify"],d.kty="RSA",d.ext=n,d.key_ops=i,E.algorithm.algorithmId!=="1.2.840.113549.1.1.1")throw new Error(`Incorrect public key algorithm: ${E.algorithm.algorithmId}`);if(!b.hash)throw new Q("hash","algorithm.hash","Incorrect hash algorithm: Hash algorithm is missed");switch(b.hash.name.toUpperCase()){case"SHA-1":d.alg="RS1";break;case"SHA-256":d.alg="RS256";break;case"SHA-384":d.alg="RS384";break;case"SHA-512":d.alg="RS512";break;default:throw new Error(`Incorrect hash algorithm: ${b.hash.name.toUpperCase()}`)}const y=E.toJSON();Object.assign(d,y)}break;case"ECDSA":i=["verify"];case"ECDH":{if(d={kty:"EC",ext:n,key_ops:i},E.algorithm.algorithmId!=="1.2.840.10045.2.1")throw new Error(`Incorrect public key algorithm: ${E.algorithm.algorithmId}`);const y=E.toJSON();Object.assign(d,y)}break;case"RSA-OAEP":{if(d.kty="RSA",d.ext=n,d.key_ops=i,this.name.toLowerCase()==="safari")d.alg="RSA-OAEP";else{if(!b.hash)throw new Q("hash","algorithm.hash","Incorrect hash algorithm: Hash algorithm is missed");switch(b.hash.name.toUpperCase()){case"SHA-1":d.alg="RSA-OAEP";break;case"SHA-256":d.alg="RSA-OAEP-256";break;case"SHA-384":d.alg="RSA-OAEP-384";break;case"SHA-512":d.alg="RSA-OAEP-512";break;default:throw new Error(`Incorrect hash algorithm: ${b.hash.name.toUpperCase()}`)}}const y=E.toJSON();Object.assign(d,y)}break;case"RSAES-PKCS1-V1_5":{d.kty="RSA",d.ext=n,d.key_ops=i,d.alg="PS1";const y=E.toJSON();Object.assign(d,y)}break;default:throw new Error(`Incorrect algorithm name: ${b.name.toUpperCase()}`)}}break;case"pkcs8":{const A=new St,E=Oe(L.toArrayBuffer(t));p.assert(E,"keyData");try{A.fromSchema(E.result)}catch{throw new Error("Incorrect keyData")}if(!A.parsedKey)throw new Error("Incorrect keyData");switch(b.name.toUpperCase()){case"RSA-PSS":switch((o=b.hash)===null||o===void 0?void 0:o.name.toUpperCase()){case"SHA-1":d.alg="PS1";break;case"SHA-256":d.alg="PS256";break;case"SHA-384":d.alg="PS384";break;case"SHA-512":d.alg="PS512";break;default:throw new Error(`Incorrect hash algorithm: ${(l=b.hash)===null||l===void 0?void 0:l.name.toUpperCase()}`)}case"RSASSA-PKCS1-V1_5":{if(i=["sign"],d.kty="RSA",d.ext=n,d.key_ops=i,A.privateKeyAlgorithm.algorithmId!=="1.2.840.113549.1.1.1")throw new Error(`Incorrect private key algorithm: ${A.privateKeyAlgorithm.algorithmId}`);if(!("alg"in d))switch((c=b.hash)===null||c===void 0?void 0:c.name.toUpperCase()){case"SHA-1":d.alg="RS1";break;case"SHA-256":d.alg="RS256";break;case"SHA-384":d.alg="RS384";break;case"SHA-512":d.alg="RS512";break;default:throw new Error(`Incorrect hash algorithm: ${(h=b.hash)===null||h===void 0?void 0:h.name.toUpperCase()}`)}const y=A.toJSON();Object.assign(d,y)}break;case"ECDSA":i=["sign"];case"ECDH":{if(d={kty:"EC",ext:n,key_ops:i},A.privateKeyAlgorithm.algorithmId!=="1.2.840.10045.2.1")throw new Error(`Incorrect algorithm: ${A.privateKeyAlgorithm.algorithmId}`);const y=A.toJSON();Object.assign(d,y)}break;case"RSA-OAEP":{if(d.kty="RSA",d.ext=n,d.key_ops=i,this.name.toLowerCase()==="safari")d.alg="RSA-OAEP";else switch((m=b.hash)===null||m===void 0?void 0:m.name.toUpperCase()){case"SHA-1":d.alg="RSA-OAEP";break;case"SHA-256":d.alg="RSA-OAEP-256";break;case"SHA-384":d.alg="RSA-OAEP-384";break;case"SHA-512":d.alg="RSA-OAEP-512";break;default:throw new Error(`Incorrect hash algorithm: ${(g=b.hash)===null||g===void 0?void 0:g.name.toUpperCase()}`)}const y=A.toJSON();Object.assign(d,y)}break;case"RSAES-PKCS1-V1_5":{i=["decrypt"],d.kty="RSA",d.ext=n,d.key_ops=i,d.alg="PS1";const y=A.toJSON();Object.assign(d,y)}break;default:throw new Error(`Incorrect algorithm name: ${b.name.toUpperCase()}`)}}break;case"jwk":d=t;break;default:throw new Error(`Incorrect format: ${e}`)}if(this.name.toLowerCase()==="safari")try{return this.subtle.importKey("jwk",Fa(JSON.stringify(d)),s,n,i)}catch{return this.subtle.importKey("jwk",d,s,n,i)}return this.subtle.importKey("jwk",d,s,n,i)}async exportKey(e,t){let s=await this.subtle.exportKey("jwk",t);switch(this.name.toLowerCase()==="safari"&&s instanceof ArrayBuffer&&(s=JSON.parse(Du(s))),e.toLowerCase()){case"raw":return this.subtle.exportKey("raw",t);case"spki":{const n=new je;try{n.fromJSON(s)}catch{throw new Error("Incorrect key data")}return n.toSchema().toBER(!1)}case"pkcs8":{const n=new St;try{n.fromJSON(s)}catch{throw new Error("Incorrect key data")}return n.toSchema().toBER(!1)}case"jwk":return s;default:throw new Error(`Incorrect format: ${e}`)}}async convert(e,t,s,n,i,o){if(e.toLowerCase()===t.toLowerCase())return s;const l=await this.importKey(e,s,n,i,o);return this.exportKey(t,l)}getAlgorithmByOID(e,t=!1,s){switch(e){case"1.2.840.113549.1.1.1":return{name:"RSAES-PKCS1-v1_5"};case"1.2.840.113549.1.1.5":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-1"}};case"1.2.840.113549.1.1.11":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}};case"1.2.840.113549.1.1.12":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-384"}};case"1.2.840.113549.1.1.13":return{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-512"}};case"1.2.840.113549.1.1.10":return{name:"RSA-PSS"};case"1.2.840.113549.1.1.7":return{name:"RSA-OAEP"};case"1.2.840.10045.2.1":case"1.2.840.10045.4.1":return{name:"ECDSA",hash:{name:"SHA-1"}};case"1.2.840.10045.4.3.2":return{name:"ECDSA",hash:{name:"SHA-256"}};case"1.2.840.10045.4.3.3":return{name:"ECDSA",hash:{name:"SHA-384"}};case"1.2.840.10045.4.3.4":return{name:"ECDSA",hash:{name:"SHA-512"}};case"1.3.133.16.840.63.0.2":return{name:"ECDH",kdf:"SHA-1"};case"1.3.132.1.11.1":return{name:"ECDH",kdf:"SHA-256"};case"1.3.132.1.11.2":return{name:"ECDH",kdf:"SHA-384"};case"1.3.132.1.11.3":return{name:"ECDH",kdf:"SHA-512"};case"2.16.840.1.101.3.4.1.2":return{name:"AES-CBC",length:128};case"2.16.840.1.101.3.4.1.22":return{name:"AES-CBC",length:192};case"2.16.840.1.101.3.4.1.42":return{name:"AES-CBC",length:256};case"2.16.840.1.101.3.4.1.6":return{name:"AES-GCM",length:128};case"2.16.840.1.101.3.4.1.26":return{name:"AES-GCM",length:192};case"2.16.840.1.101.3.4.1.46":return{name:"AES-GCM",length:256};case"2.16.840.1.101.3.4.1.4":return{name:"AES-CFB",length:128};case"2.16.840.1.101.3.4.1.24":return{name:"AES-CFB",length:192};case"2.16.840.1.101.3.4.1.44":return{name:"AES-CFB",length:256};case"2.16.840.1.101.3.4.1.5":return{name:"AES-KW",length:128};case"2.16.840.1.101.3.4.1.25":return{name:"AES-KW",length:192};case"2.16.840.1.101.3.4.1.45":return{name:"AES-KW",length:256};case"1.2.840.113549.2.7":return{name:"HMAC",hash:{name:"SHA-1"}};case"1.2.840.113549.2.9":return{name:"HMAC",hash:{name:"SHA-256"}};case"1.2.840.113549.2.10":return{name:"HMAC",hash:{name:"SHA-384"}};case"1.2.840.113549.2.11":return{name:"HMAC",hash:{name:"SHA-512"}};case"1.2.840.113549.1.9.16.3.5":return{name:"DH"};case"1.3.14.3.2.26":return{name:"SHA-1"};case"2.16.840.1.101.3.4.2.1":return{name:"SHA-256"};case"2.16.840.1.101.3.4.2.2":return{name:"SHA-384"};case"2.16.840.1.101.3.4.2.3":return{name:"SHA-512"};case"1.2.840.113549.1.5.12":return{name:"PBKDF2"};case"1.2.840.10045.3.1.7":return{name:"P-256"};case"1.3.132.0.34":return{name:"P-384"};case"1.3.132.0.35":return{name:"P-521"}}if(t)throw new Error(`Unsupported algorithm identifier ${s?`for ${s} `:u}: ${e}`);return{}}getOIDByAlgorithm(e,t=!1,s){let n=u;switch(e.name.toUpperCase()){case"RSAES-PKCS1-V1_5":n="1.2.840.113549.1.1.1";break;case"RSASSA-PKCS1-V1_5":switch(e.hash.name.toUpperCase()){case"SHA-1":n="1.2.840.113549.1.1.5";break;case"SHA-256":n="1.2.840.113549.1.1.11";break;case"SHA-384":n="1.2.840.113549.1.1.12";break;case"SHA-512":n="1.2.840.113549.1.1.13";break}break;case"RSA-PSS":n="1.2.840.113549.1.1.10";break;case"RSA-OAEP":n="1.2.840.113549.1.1.7";break;case"ECDSA":switch(e.hash.name.toUpperCase()){case"SHA-1":n="1.2.840.10045.4.1";break;case"SHA-256":n="1.2.840.10045.4.3.2";break;case"SHA-384":n="1.2.840.10045.4.3.3";break;case"SHA-512":n="1.2.840.10045.4.3.4";break}break;case"ECDH":switch(e.kdf.toUpperCase()){case"SHA-1":n="1.3.133.16.840.63.0.2";break;case"SHA-256":n="1.3.132.1.11.1";break;case"SHA-384":n="1.3.132.1.11.2";break;case"SHA-512":n="1.3.132.1.11.3";break}break;case"AES-CTR":break;case"AES-CBC":switch(e.length){case 128:n="2.16.840.1.101.3.4.1.2";break;case 192:n="2.16.840.1.101.3.4.1.22";break;case 256:n="2.16.840.1.101.3.4.1.42";break}break;case"AES-CMAC":break;case"AES-GCM":switch(e.length){case 128:n="2.16.840.1.101.3.4.1.6";break;case 192:n="2.16.840.1.101.3.4.1.26";break;case 256:n="2.16.840.1.101.3.4.1.46";break}break;case"AES-CFB":switch(e.length){case 128:n="2.16.840.1.101.3.4.1.4";break;case 192:n="2.16.840.1.101.3.4.1.24";break;case 256:n="2.16.840.1.101.3.4.1.44";break}break;case"AES-KW":switch(e.length){case 128:n="2.16.840.1.101.3.4.1.5";break;case 192:n="2.16.840.1.101.3.4.1.25";break;case 256:n="2.16.840.1.101.3.4.1.45";break}break;case"HMAC":switch(e.hash.name.toUpperCase()){case"SHA-1":n="1.2.840.113549.2.7";break;case"SHA-256":n="1.2.840.113549.2.9";break;case"SHA-384":n="1.2.840.113549.2.10";break;case"SHA-512":n="1.2.840.113549.2.11";break}break;case"DH":n="1.2.840.113549.1.9.16.3.5";break;case"SHA-1":n="1.3.14.3.2.26";break;case"SHA-256":n="2.16.840.1.101.3.4.2.1";break;case"SHA-384":n="2.16.840.1.101.3.4.2.2";break;case"SHA-512":n="2.16.840.1.101.3.4.2.3";break;case"CONCAT":break;case"HKDF":break;case"PBKDF2":n="1.2.840.113549.1.5.12";break;case"P-256":n="1.2.840.10045.3.1.7";break;case"P-384":n="1.3.132.0.34";break;case"P-521":n="1.3.132.0.35";break}if(!n&&t)throw new Error(`Unsupported algorithm ${s?`for ${s} `:u}: ${e.name}`);return n}getAlgorithmParameters(e,t){let s={algorithm:{},usages:[]};switch(e.toUpperCase()){case"RSAES-PKCS1-V1_5":case"RSASSA-PKCS1-V1_5":switch(t.toLowerCase()){case"generatekey":s={algorithm:{name:"RSASSA-PKCS1-v1_5",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},usages:["sign","verify"]};break;case"verify":case"sign":case"importkey":s={algorithm:{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},usages:["verify"]};break;default:return{algorithm:{name:"RSASSA-PKCS1-v1_5"},usages:[]}}break;case"RSA-PSS":switch(t.toLowerCase()){case"sign":case"verify":s={algorithm:{name:"RSA-PSS",hash:{name:"SHA-1"},saltLength:20},usages:["sign","verify"]};break;case"generatekey":s={algorithm:{name:"RSA-PSS",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-1"}},usages:["sign","verify"]};break;case"importkey":s={algorithm:{name:"RSA-PSS",hash:{name:"SHA-1"}},usages:["verify"]};break;default:return{algorithm:{name:"RSA-PSS"},usages:[]}}break;case"RSA-OAEP":switch(t.toLowerCase()){case"encrypt":case"decrypt":s={algorithm:{name:"RSA-OAEP"},usages:["encrypt","decrypt"]};break;case"generatekey":s={algorithm:{name:"RSA-OAEP",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},usages:["encrypt","decrypt","wrapKey","unwrapKey"]};break;case"importkey":s={algorithm:{name:"RSA-OAEP",hash:{name:"SHA-256"}},usages:["encrypt"]};break;default:return{algorithm:{name:"RSA-OAEP"},usages:[]}}break;case"ECDSA":switch(t.toLowerCase()){case"generatekey":s={algorithm:{name:"ECDSA",namedCurve:"P-256"},usages:["sign","verify"]};break;case"importkey":s={algorithm:{name:"ECDSA",namedCurve:"P-256"},usages:["verify"]};break;case"verify":case"sign":s={algorithm:{name:"ECDSA",hash:{name:"SHA-256"}},usages:["sign"]};break;default:return{algorithm:{name:"ECDSA"},usages:[]}}break;case"ECDH":switch(t.toLowerCase()){case"exportkey":case"importkey":case"generatekey":s={algorithm:{name:"ECDH",namedCurve:"P-256"},usages:["deriveKey","deriveBits"]};break;case"derivekey":case"derivebits":s={algorithm:{name:"ECDH",namedCurve:"P-256",public:[]},usages:["encrypt","decrypt"]};break;default:return{algorithm:{name:"ECDH"},usages:[]}}break;case"AES-CTR":switch(t.toLowerCase()){case"importkey":case"exportkey":case"generatekey":s={algorithm:{name:"AES-CTR",length:256},usages:["encrypt","decrypt","wrapKey","unwrapKey"]};break;case"decrypt":case"encrypt":s={algorithm:{name:"AES-CTR",counter:new Uint8Array(16),length:10},usages:["encrypt","decrypt","wrapKey","unwrapKey"]};break;default:return{algorithm:{name:"AES-CTR"},usages:[]}}break;case"AES-CBC":switch(t.toLowerCase()){case"importkey":case"exportkey":case"generatekey":s={algorithm:{name:"AES-CBC",length:256},usages:["encrypt","decrypt","wrapKey","unwrapKey"]};break;case"decrypt":case"encrypt":s={algorithm:{name:"AES-CBC",iv:this.getRandomValues(new Uint8Array(16))},usages:["encrypt","decrypt","wrapKey","unwrapKey"]};break;default:return{algorithm:{name:"AES-CBC"},usages:[]}}break;case"AES-GCM":switch(t.toLowerCase()){case"importkey":case"exportkey":case"generatekey":s={algorithm:{name:"AES-GCM",length:256},usages:["encrypt","decrypt","wrapKey","unwrapKey"]};break;case"decrypt":case"encrypt":s={algorithm:{name:"AES-GCM",iv:this.getRandomValues(new Uint8Array(16))},usages:["encrypt","decrypt","wrapKey","unwrapKey"]};break;default:return{algorithm:{name:"AES-GCM"},usages:[]}}break;case"AES-KW":switch(t.toLowerCase()){case"importkey":case"exportkey":case"generatekey":case"wrapkey":case"unwrapkey":s={algorithm:{name:"AES-KW",length:256},usages:["wrapKey","unwrapKey"]};break;default:return{algorithm:{name:"AES-KW"},usages:[]}}break;case"HMAC":switch(t.toLowerCase()){case"sign":case"verify":s={algorithm:{name:"HMAC"},usages:["sign","verify"]};break;case"importkey":case"exportkey":case"generatekey":s={algorithm:{name:"HMAC",length:32,hash:{name:"SHA-256"}},usages:["sign","verify"]};break;default:return{algorithm:{name:"HMAC"},usages:[]}}break;case"HKDF":if(t.toLowerCase()==="derivekey")s={algorithm:{name:"HKDF",hash:"SHA-256",salt:new Uint8Array([]),info:new Uint8Array([])},usages:["encrypt","decrypt"]};else return{algorithm:{name:"HKDF"},usages:[]};break;case"PBKDF2":if(t.toLowerCase()==="derivekey")s={algorithm:{name:"PBKDF2",hash:{name:"SHA-256"},salt:new Uint8Array([]),iterations:1e4},usages:["encrypt","decrypt"]};else return{algorithm:{name:"PBKDF2"},usages:[]};break}return s}getHashAlgorithm(e){let t=u;switch(e.algorithmId){case"1.2.840.10045.4.1":case"1.2.840.113549.1.1.5":t="SHA-1";break;case"1.2.840.10045.4.3.2":case"1.2.840.113549.1.1.11":t="SHA-256";break;case"1.2.840.10045.4.3.3":case"1.2.840.113549.1.1.12":t="SHA-384";break;case"1.2.840.10045.4.3.4":case"1.2.840.113549.1.1.13":t="SHA-512";break;case"1.2.840.113549.1.1.10":try{const s=new Pe({schema:e.algorithmParams});if(s.hashAlgorithm){const n=this.getAlgorithmByOID(s.hashAlgorithm.algorithmId);if("name"in n)t=n.name;else return u}else t="SHA-1"}catch{}break}return t}async encryptEncryptedContentInfo(e){Q.assert(e,"password","contentEncryptionAlgorithm","hmacHashAlgorithm","iterationCount","contentToEncrypt","contentToEncrypt","contentType");const t=this.getOIDByAlgorithm(e.contentEncryptionAlgorithm,!0,"contentEncryptionAlgorithm"),s=this.getOIDByAlgorithm({name:"PBKDF2"},!0,"PBKDF2"),n=this.getOIDByAlgorithm({name:"HMAC",hash:{name:e.hmacHashAlgorithm}},!0,"hmacHashAlgorithm"),i=new ArrayBuffer(16),o=new Uint8Array(i);this.getRandomValues(o);const l=new ArrayBuffer(64),c=new Uint8Array(l);this.getRandomValues(c);const h=new Uint8Array(e.contentToEncrypt),m=new Je({salt:new I({valueHex:l}),iterationCount:e.iterationCount,prf:new v({algorithmId:n,algorithmParams:new Ae})}),g=new Uint8Array(e.password),d=await this.importKey("raw",g,"PBKDF2",!1,["deriveKey"]),b=await this.deriveKey({name:"PBKDF2",hash:{name:e.hmacHashAlgorithm},salt:c,iterations:e.iterationCount},d,e.contentEncryptionAlgorithm,!1,["encrypt"]),A=await this.encrypt({name:e.contentEncryptionAlgorithm.name,iv:o},b,h),E=new Zi({keyDerivationFunc:new v({algorithmId:s,algorithmParams:m.toSchema()}),encryptionScheme:new v({algorithmId:t,algorithmParams:new I({valueHex:i})})});return new Ee({contentType:e.contentType,contentEncryptionAlgorithm:new v({algorithmId:"1.2.840.113549.1.5.13",algorithmParams:E.toSchema()}),encryptedContent:new I({valueHex:A})})}async decryptEncryptedContentInfo(e){if(Q.assert(e,"password","encryptedContentInfo"),e.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId!=="1.2.840.113549.1.5.13")throw new Error(`Unknown "contentEncryptionAlgorithm": ${e.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId}`);let t;try{t=new Zi({schema:e.encryptedContentInfo.contentEncryptionAlgorithm.algorithmParams})}catch{throw new Error('Incorrectly encoded "pbes2Parameters"')}let s;try{s=new Je({schema:t.keyDerivationFunc.algorithmParams})}catch{throw new Error('Incorrectly encoded "pbkdf2Params"')}const n=this.getAlgorithmByOID(t.encryptionScheme.algorithmId,!0),i=t.encryptionScheme.algorithmParams.valueBlock.valueHex,o=new Uint8Array(i),l=s.salt.valueBlock.valueHex,c=new Uint8Array(l),h=s.iterationCount;let m="SHA-1";s.prf&&(m=this.getAlgorithmByOID(s.prf.algorithmId,!0).hash.name);const g=await this.importKey("raw",e.password,"PBKDF2",!1,["deriveKey"]),d=await this.deriveKey({name:"PBKDF2",hash:{name:m},salt:c,iterations:h},g,n,!1,["decrypt"]),b=e.encryptedContentInfo.getEncryptedContent();return this.decrypt({name:n.name,iv:o},d,b)}async stampDataWithPassword(e){if(!(e instanceof Object))throw new Error('Parameters must have type "Object"');Q.assert(e,"password","hashAlgorithm","iterationCount","salt","contentToStamp");let t;switch(e.hashAlgorithm.toLowerCase()){case"sha-1":t=160;break;case"sha-256":t=256;break;case"sha-384":t=384;break;case"sha-512":t=512;break;default:throw new Error(`Incorrect "parameters.hashAlgorithm" parameter: ${e.hashAlgorithm}`)}const s={name:"HMAC",length:t,hash:{name:e.hashAlgorithm}},n=await zf(e.hashAlgorithm,t,e.password,e.salt,e.iterationCount),i=await this.importKey("raw",new Uint8Array(n),s,!1,["sign"]);return this.sign(s,i,new Uint8Array(e.contentToStamp))}async verifyDataStampedWithPassword(e){Q.assert(e,"password","hashAlgorithm","salt","iterationCount","contentToVerify","signatureToVerify");let t=0;switch(e.hashAlgorithm.toLowerCase()){case"sha-1":t=160;break;case"sha-256":t=256;break;case"sha-384":t=384;break;case"sha-512":t=512;break;default:throw new Error(`Incorrect "parameters.hashAlgorithm" parameter: ${e.hashAlgorithm}`)}const s={name:"HMAC",length:t,hash:{name:e.hashAlgorithm}},n=await zf(e.hashAlgorithm,t,e.password,e.salt,e.iterationCount),i=await this.importKey("raw",new Uint8Array(n),s,!1,["verify"]);return this.verify(s,i,new Uint8Array(e.signatureToVerify),new Uint8Array(e.contentToVerify))}async getSignatureParameters(e,t="SHA-1"){this.getOIDByAlgorithm({name:t},!0,"hashAlgorithm");const s=new v,n=this.getAlgorithmParameters(e.algorithm.name,"sign");if(!Object.keys(n.algorithm).length)throw new Error("Parameter 'algorithm' is empty");const i=n.algorithm;switch("hash"in e.algorithm&&e.algorithm.hash&&e.algorithm.hash.name?i.hash.name=e.algorithm.hash.name:i.hash.name=t,e.algorithm.name.toUpperCase()){case"RSASSA-PKCS1-V1_5":case"ECDSA":s.algorithmId=this.getOIDByAlgorithm(i,!0);break;case"RSA-PSS":{switch(i.hash.name.toUpperCase()){case"SHA-256":i.saltLength=32;break;case"SHA-384":i.saltLength=48;break;case"SHA-512":i.saltLength=64;break}const o={};if(i.hash.name.toUpperCase()!=="SHA-1"){const c=this.getOIDByAlgorithm({name:i.hash.name},!0,"hashAlgorithm");o.hashAlgorithm=new v({algorithmId:c,algorithmParams:new Ae}),o.maskGenAlgorithm=new v({algorithmId:"1.2.840.113549.1.1.8",algorithmParams:o.hashAlgorithm.toSchema()})}i.saltLength!==20&&(o.saltLength=i.saltLength);const l=new Pe(o);s.algorithmId="1.2.840.113549.1.1.10",s.algorithmParams=l.toSchema()}break;default:throw new Error(`Unsupported signature algorithm: ${e.algorithm.name}`)}return{signatureAlgorithm:s,parameters:n}}async signWithPrivateKey(e,t,s){const n=await this.sign(s.algorithm,t,e);return s.algorithm.name==="ECDSA"?Vy(n):n}fillPublicKeyParameters(e,t){const s={},n=this.getHashAlgorithm(t);if(n===u)throw new Error(`Unsupported signature algorithm: ${t.algorithmId}`);let i;t.algorithmId==="1.2.840.113549.1.1.10"?i=t.algorithmId:i=e.algorithm.algorithmId;const o=this.getAlgorithmByOID(i,!0);if(s.algorithm=this.getAlgorithmParameters(o.name,"importKey"),"hash"in s.algorithm.algorithm&&(s.algorithm.algorithm.hash.name=n),o.name==="ECDSA"){const l=e.algorithm;if(!l.algorithmParams)throw new Error("Algorithm parameters for ECDSA public key are missed");const c=l.algorithmParams;if("idBlock"in l.algorithmParams&&!(c.idBlock.tagClass===1&&c.idBlock.tagNumber===6))throw new Error("Incorrect type for ECDSA public key parameters");const h=this.getAlgorithmByOID(c.valueBlock.toString(),!0);s.algorithm.algorithm.namedCurve=h.name}return s}async getPublicKey(e,t,s){s||(s=this.fillPublicKeyParameters(e,t));const n=e.toSchema().toBER(!1);return this.importKey("spki",n,s.algorithm.algorithm,!0,s.algorithm.usages)}async verifyWithPublicKey(e,t,s,n,i){let o;if(i){const h={};let m;n.algorithmId==="1.2.840.113549.1.1.10"?m=n.algorithmId:m=s.algorithm.algorithmId;const g=this.getAlgorithmByOID(m,!0);if(h.algorithm=this.getAlgorithmParameters(g.name,"importKey"),"hash"in h.algorithm.algorithm&&(h.algorithm.algorithm.hash.name=i),g.name==="ECDSA"){let d=!1;if("algorithmParams"in s.algorithm&&"idBlock"in s.algorithm.algorithmParams&&s.algorithm.algorithmParams.idBlock.tagClass===1&&s.algorithm.algorithmParams.idBlock.tagNumber===6&&(d=!0),d===!1)throw new Error("Incorrect type for ECDSA public key parameters");const b=this.getAlgorithmByOID(s.algorithm.algorithmParams.valueBlock.toString(),!0);h.algorithm.algorithm.namedCurve=b.name}o=await this.getPublicKey(s,null,h)}else{if(i=this.getHashAlgorithm(n),!i)throw new Error(`Unsupported signature algorithm: ${n.algorithmId}`);o=await this.getPublicKey(s,n)}const l=this.getAlgorithmParameters(o.algorithm.name,"verify");"hash"in l.algorithm&&(l.algorithm.hash.name=i);let c=t.valueBlock.valueHexView;if(o.algorithm.name==="ECDSA"){const h=Vn.find(o.algorithm.namedCurve);if(!h)throw new Error("Unsupported named curve in use");const m=Oe(c);p.assert(m,"Signature value"),c=xy(m.result,h.size)}if(o.algorithm.name==="RSA-PSS"){const h=new Pe({schema:n.algorithmParams});"saltLength"in h?l.algorithm.saltLength=h.saltLength:l.algorithm.saltLength=20;let m="SHA-1";"hashAlgorithm"in h&&(m=this.getAlgorithmByOID(h.hashAlgorithm.algorithmId,!0).name),l.algorithm.hash.name=m}return this.verify(l.algorithm,o,c,e)}}let ng={name:"none",crypto:null};function ed(r){return!!(r&&typeof r=="object"&&"crypto"in r)}function td(r,...e){let t=null;if(e.length<2)e.length?t=e[0]:t=typeof self<"u"&&self.crypto?new Uu({name:"browser",crypto:self.crypto}):null;else{const s=e[0],n=e[1];ed(n)?t=n:ed(s)?t=s:"subtle"in s&&"getRandomValues"in s&&(t=new Uu({crypto:s}))}if(typeof process<"u"&&"pid"in process&&typeof global<"u"&&typeof window>"u"){if(typeof global[process.pid]>"u")global[process.pid]={};else if(typeof global[process.pid]!="object")throw new Error(`Name global.${process.pid} already exists and it is not an object`);if(typeof global[process.pid].pkijs>"u")global[process.pid].pkijs={};else if(typeof global[process.pid].pkijs!="object")throw new Error(`Name global.${process.pid}.pkijs already exists and it is not an object`);global[process.pid].pkijs.engine={name:r,crypto:t}}else ng={name:r,crypto:t}}function Iy(){if(typeof process<"u"&&"pid"in process&&typeof global<"u"&&typeof window>"u"){let r;try{r=global[process.pid].pkijs.engine}catch{throw new Error("Please call 'setEngine' before call to 'getEngine'")}return r}return ng}function q(r=!1){const e=Iy();if(!e.crypto&&r)throw new Error("Unable to create WebCrypto object");return e.crypto}function Vy(r){if(r.byteLength%2!==0)return be;const e=r.byteLength/2,t=new ArrayBuffer(e);new Uint8Array(t).set(new Uint8Array(r,0,e));const n=new S({valueHex:t}),i=new ArrayBuffer(e);new Uint8Array(i).set(new Uint8Array(r,e,e));const l=new S({valueHex:i});return new f({value:[n.convertToDER(),l.convertToDER()]}).toBER(!1)}function xy(r,e){if(!(r instanceof f&&r.valueBlock.value.length===2&&r.valueBlock.value[0]instanceof S&&r.valueBlock.value[1]instanceof S))return be;const t=r.valueBlock.value[0].convertFromDER().valueBlock.valueHexView,s=r.valueBlock.value[1].convertFromDER().valueBlock.valueHexView,n=new Uint8Array(e*2);return n.set(t,e-t.byteLength),n.set(s,2*e-s.byteLength),n.buffer}async function Oy(r,e,t,s,n){switch(r.toUpperCase()){case"SHA-1":case"SHA-256":case"SHA-384":case"SHA-512":break;default:throw new ie(`Unknown hash function: ${r}`)}if(ie.assert(e,"zBuffer","ArrayBuffer"),e.byteLength===0)throw new ie("'zBuffer' has zero length, error");if(ie.assert(s,"SharedInfo","ArrayBuffer"),t>255)throw new ie("Please set 'Counter' argument to value less or equal to 255");const i=new ArrayBuffer(4),o=new Uint8Array(i);o[0]=0,o[1]=0,o[2]=0,o[3]=t;let l=be;l=Ua(l,e),l=Ua(l,i),l=Ua(l,s);const c=await n.digest({name:r},l);return{counter:t,result:c}}async function sd(r,e,t,s,n=q(!0)){let i=0,o=1;switch(r.toUpperCase()){case"SHA-1":i=160;break;case"SHA-256":i=256;break;case"SHA-384":i=384;break;case"SHA-512":i=512;break;default:throw new ie(`Unknown hash function: ${r}`)}if(ie.assert(e,"Zbuffer","ArrayBuffer"),e.byteLength===0)throw new ie("'Zbuffer' has zero length, error");ie.assert(s,"SharedInfo","ArrayBuffer");const l=t/i;Math.floor(l)>0&&(o=Math.floor(l),l-o>0&&o++);const c=[];for(let d=1;d<=o;d++)c.push(await Oy(r,e,d,s,n));let h=be,m=1,g=!0;for(;g;){g=!1;for(const d of c)if(d.counter===m){h=Ua(h,d.result),g=!0;break}m++}if(t>>=3,h.byteLength>t){const d=new ArrayBuffer(t),b=new Uint8Array(d),A=new Uint8Array(h);for(let E=0;Ee.toJSON())}}}zu.CLASS_NAME="SignedCertificateTimestampList";const tl="attributes",Ry=[tl];class Nc extends k{constructor(e={}){super(),this.attributes=a(e,tl,Nc.defaultValues(tl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===tl?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.attributes||u,value:le.schema()})]})}fromSchema(e){C(e,Ry);const t=N(e,e,Nc.schema({names:{attributes:tl}}));p.assertSchema(t,this.className),this.attributes=Array.from(t.result.attributes,s=>new le({schema:s}))}toSchema(){return new f({value:Array.from(this.attributes,e=>e.toSchema())})}toJSON(){return{attributes:Array.from(this.attributes,e=>e.toJSON())}}}Nc.CLASS_NAME="SubjectDirectoryAttributes";class de{static getItems(){return this.types||(this.types={},de.register(Mm,"SubjectAltName",Wa),de.register(Km,"IssuerAltName",Wa),de.register(Ef,"AuthorityKeyIdentifier",bn),de.register(bf,"BasicConstraints",qi),de.register(Gw,"MicrosoftCaVersion",pc),de.register(Wm,"CertificatePolicies",Ga),de.register(Kw,"CertificatePoliciesMicrosoft",Ga),de.register(Ww,"MicrosoftCertTemplateV2",Pa),de.register(qm,"CRLDistributionPoints",Ya),de.register(kf,"FreshestCRL",Ya),de.register(Jw,"ExtKeyUsage",bc),de.register(jm,"CertificateIssuer",xe),de.register(Nf,"AuthorityInfoAccess",Qa),de.register(Fw,"SubjectInfoAccess",Qa),de.register(Jm,"IssuingDistributionPoint",De),de.register(Fm,"NameConstraints",_a),de.register(Ym,"PolicyConstraints",$a),de.register(Gm,"PolicyMappings",kc),de.register(Uw,"PrivateKeyUsagePeriod",Ma),de.register(Yw,"QCStatements",Ec),de.register(qw,"SignedCertificateTimestampList",zu),de.register(Dw,"SubjectDirectoryAttributes",Nc)),this.types}static fromBER(e,t){const s=Oe(t);if(s.offset===-1)return null;const n=this.find(e);if(n)try{return new n.type({schema:s.result})}catch{const i=new n.type;return i.parsingError=`Incorrectly formatted value of extension ${n.name} (${e})`,i}return s.result}static find(e){return this.getItems()[e]||null}static register(e,t,s){this.getItems()[e]={name:t,type:s}}}const sl="extnID",Ws="critical",nl="extnValue",Uc="parsedValue",Ty=[sl,Ws,nl];class Ve extends k{get parsedValue(){if(this._parsedValue===void 0){const e=de.fromBER(this.extnID,this.extnValue.valueBlock.valueHexView);this._parsedValue=e}return this._parsedValue||void 0}set parsedValue(e){this._parsedValue=e}constructor(e={}){super(),this.extnID=a(e,sl,Ve.defaultValues(sl)),this.critical=a(e,Ws,Ve.defaultValues(Ws)),nl in e?this.extnValue=new I({valueHex:e.extnValue}):this.extnValue=Ve.defaultValues(nl),Uc in e&&(this.parsedValue=a(e,Uc,Ve.defaultValues(Uc))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case sl:return u;case Ws:return!1;case nl:return new I;case Uc:return{};default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.extnID||u}),new Ft({name:t.critical||u,optional:!0}),new I({name:t.extnValue||u})]})}fromSchema(e){C(e,Ty);const t=N(e,e,Ve.schema({names:{extnID:sl,critical:Ws,extnValue:nl}}));p.assertSchema(t,this.className),this.extnID=t.result.extnID.valueBlock.toString(),Ws in t.result&&(this.critical=t.result.critical.valueBlock.value),this.extnValue=t.result.extnValue}toSchema(){const e=[];return e.push(new T({value:this.extnID})),this.critical!==Ve.defaultValues(Ws)&&e.push(new Ft({value:this.critical})),e.push(this.extnValue),new f({value:e})}toJSON(){const e={extnID:this.extnID,extnValue:this.extnValue.toJSON()};return this.critical!==Ve.defaultValues(Ws)&&(e.critical=this.critical),this.parsedValue&&this.parsedValue.toJSON&&(e.parsedValue=this.parsedValue.toJSON()),e}}Ve.CLASS_NAME="Extension";const il="extensions",Dy=[il];class ke extends k{constructor(e={}){super(),this.extensions=a(e,il,ke.defaultValues(il)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===il?[]:super.defaultValues(e)}static schema(e={},t=!1){const s=a(e,"names",{});return new f({optional:t,name:s.blockName||u,value:[new J({name:s.extensions||u,value:Ve.schema(s.extension||{})})]})}fromSchema(e){C(e,Dy);const t=N(e,e,ke.schema({names:{extensions:il}}));p.assertSchema(t,this.className),this.extensions=Array.from(t.result.extensions,s=>new Ve({schema:s}))}toSchema(){return new f({value:Array.from(this.extensions,e=>e.toSchema())})}toJSON(){return{extensions:this.extensions.map(e=>e.toJSON())}}}ke.CLASS_NAME="Extensions";const rl="issuer",al="serialNumber",Zn="issuerUID",Py=[rl,al,Zn];class Xe extends k{constructor(e={}){super(),this.issuer=a(e,rl,Xe.defaultValues(rl)),this.serialNumber=a(e,al,Xe.defaultValues(al)),Zn in e&&(this.issuerUID=a(e,Zn,Xe.defaultValues(Zn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case rl:return new xe;case al:return new S;case Zn:return new W;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[xe.schema(t.issuer||{}),new S({name:t.serialNumber||u}),new W({optional:!0,name:t.issuerUID||u})]})}fromSchema(e){C(e,Py);const t=N(e,e,Xe.schema({names:{issuer:{names:{blockName:rl}},serialNumber:al,issuerUID:Zn}}));p.assertSchema(t,this.className),this.issuer=new xe({schema:t.result.issuer}),this.serialNumber=t.result.serialNumber,Zn in t.result&&(this.issuerUID=t.result.issuerUID)}toSchema(){const e=new f({value:[this.issuer.toSchema(),this.serialNumber]});return this.issuerUID&&e.valueBlock.value.push(this.issuerUID),e}toJSON(){const e={issuer:this.issuer.toJSON(),serialNumber:this.serialNumber.toJSON()};return this.issuerUID&&(e.issuerUID=this.issuerUID.toJSON()),e}}Xe.CLASS_NAME="IssuerSerial";const ol="version",zn="baseCertificateID",ei="subjectName",ll="issuer",cl="signature",ul="serialNumber",hl="attrCertValidityPeriod",fl="attributes",ti="issuerUniqueID",si="extensions",Ly=[ol,zn,ei,ll,cl,ul,hl,fl,ti,si];class Ke extends k{constructor(e={}){super(),this.version=a(e,ol,Ke.defaultValues(ol)),zn in e&&(this.baseCertificateID=a(e,zn,Ke.defaultValues(zn))),ei in e&&(this.subjectName=a(e,ei,Ke.defaultValues(ei))),this.issuer=a(e,ll,Ke.defaultValues(ll)),this.signature=a(e,cl,Ke.defaultValues(cl)),this.serialNumber=a(e,ul,Ke.defaultValues(ul)),this.attrCertValidityPeriod=a(e,hl,Ke.defaultValues(hl)),this.attributes=a(e,fl,Ke.defaultValues(fl)),ti in e&&(this.issuerUniqueID=a(e,ti,Ke.defaultValues(ti))),si in e&&(this.extensions=a(e,si,Ke.defaultValues(si))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ol:return 0;case zn:return new Xe;case ei:return new xe;case ll:return new xe;case cl:return new v;case ul:return new S;case hl:return new Rt;case fl:return[];case ti:return new W;case si:return new ke;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),new he({value:[new w({name:t.baseCertificateID||u,idBlock:{tagClass:3,tagNumber:0},value:Xe.schema().valueBlock.value}),new w({name:t.subjectName||u,idBlock:{tagClass:3,tagNumber:1},value:xe.schema().valueBlock.value})]}),xe.schema({names:{blockName:t.issuer||u}}),v.schema(t.signature||{}),new S({name:t.serialNumber||u}),Rt.schema(t.attrCertValidityPeriod||{}),new f({name:t.attributes||u,value:[new J({value:le.schema()})]}),new W({optional:!0,name:t.issuerUniqueID||u}),ke.schema(t.extensions||{},!0)]})}fromSchema(e){C(e,Ly);const t=N(e,e,Ke.schema({names:{version:ol,baseCertificateID:zn,subjectName:ei,issuer:ll,signature:{names:{blockName:cl}},serialNumber:ul,attrCertValidityPeriod:{names:{blockName:hl}},attributes:fl,issuerUniqueID:ti,extensions:{names:{blockName:si}}}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,zn in t.result&&(this.baseCertificateID=new Xe({schema:new f({value:t.result.baseCertificateID.valueBlock.value})})),ei in t.result&&(this.subjectName=new xe({schema:new f({value:t.result.subjectName.valueBlock.value})})),this.issuer=t.result.issuer,this.signature=new v({schema:t.result.signature}),this.serialNumber=t.result.serialNumber,this.attrCertValidityPeriod=new Rt({schema:t.result.attrCertValidityPeriod}),this.attributes=Array.from(t.result.attributes.valueBlock.value,s=>new le({schema:s})),ti in t.result&&(this.issuerUniqueID=t.result.issuerUniqueID),si in t.result&&(this.extensions=new ke({schema:t.result.extensions}))}toSchema(){const e=new f({value:[new S({value:this.version})]});return this.baseCertificateID&&e.valueBlock.value.push(new w({idBlock:{tagClass:3,tagNumber:0},value:this.baseCertificateID.toSchema().valueBlock.value})),this.subjectName&&e.valueBlock.value.push(new w({idBlock:{tagClass:3,tagNumber:1},value:this.subjectName.toSchema().valueBlock.value})),e.valueBlock.value.push(this.issuer.toSchema()),e.valueBlock.value.push(this.signature.toSchema()),e.valueBlock.value.push(this.serialNumber),e.valueBlock.value.push(this.attrCertValidityPeriod.toSchema()),e.valueBlock.value.push(new f({value:Array.from(this.attributes,t=>t.toSchema())})),this.issuerUniqueID&&e.valueBlock.value.push(this.issuerUniqueID),this.extensions&&e.valueBlock.value.push(this.extensions.toSchema()),e}toJSON(){const e={version:this.version};return this.baseCertificateID&&(e.baseCertificateID=this.baseCertificateID.toJSON()),this.subjectName&&(e.subjectName=this.subjectName.toJSON()),e.issuer=this.issuer.toJSON(),e.signature=this.signature.toJSON(),e.serialNumber=this.serialNumber.toJSON(),e.attrCertValidityPeriod=this.attrCertValidityPeriod.toJSON(),e.attributes=Array.from(this.attributes,t=>t.toJSON()),this.issuerUniqueID&&(e.issuerUniqueID=this.issuerUniqueID.toJSON()),this.extensions&&(e.extensions=this.extensions.toJSON()),e}}Ke.CLASS_NAME="AttributeCertificateInfoV1";const dl="acinfo",ml="signatureAlgorithm",gl="signatureValue",Uy=[dl,gl,ml];class us extends k{constructor(e={}){super(),this.acinfo=a(e,dl,us.defaultValues(dl)),this.signatureAlgorithm=a(e,ml,us.defaultValues(ml)),this.signatureValue=a(e,gl,us.defaultValues(gl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case dl:return new Ke;case ml:return new v;case gl:return new W;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[Ke.schema(t.acinfo||{}),v.schema(t.signatureAlgorithm||{}),new W({name:t.signatureValue||u})]})}fromSchema(e){C(e,Uy);const t=N(e,e,us.schema({names:{acinfo:{names:{blockName:dl}},signatureAlgorithm:{names:{blockName:ml}},signatureValue:gl}}));p.assertSchema(t,this.className),this.acinfo=new Ke({schema:t.result.acinfo}),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}toSchema(){return new f({value:[this.acinfo.toSchema(),this.signatureAlgorithm.toSchema(),this.signatureValue]})}toJSON(){return{acinfo:this.acinfo.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signatureValue:this.signatureValue.toJSON()}}}us.CLASS_NAME="AttributeCertificateV1";const wl="digestedObjectType",ni="otherObjectTypeID",yl="digestAlgorithm",vl="objectDigest",Hy=[wl,ni,yl,vl];class ut extends k{constructor(e={}){super(),this.digestedObjectType=a(e,wl,ut.defaultValues(wl)),ni in e&&(this.otherObjectTypeID=a(e,ni,ut.defaultValues(ni))),this.digestAlgorithm=a(e,yl,ut.defaultValues(yl)),this.objectDigest=a(e,vl,ut.defaultValues(vl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case wl:return new sr;case ni:return new T;case yl:return new v;case vl:return new W;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new sr({name:t.digestedObjectType||u}),new T({optional:!0,name:t.otherObjectTypeID||u}),v.schema(t.digestAlgorithm||{}),new W({name:t.objectDigest||u})]})}fromSchema(e){C(e,Hy);const t=N(e,e,ut.schema({names:{digestedObjectType:wl,otherObjectTypeID:ni,digestAlgorithm:{names:{blockName:yl}},objectDigest:vl}}));p.assertSchema(t,this.className),this.digestedObjectType=t.result.digestedObjectType,ni in t.result&&(this.otherObjectTypeID=t.result.otherObjectTypeID),this.digestAlgorithm=new v({schema:t.result.digestAlgorithm}),this.objectDigest=t.result.objectDigest}toSchema(){const e=new f({value:[this.digestedObjectType]});return this.otherObjectTypeID&&e.valueBlock.value.push(this.otherObjectTypeID),e.valueBlock.value.push(this.digestAlgorithm.toSchema()),e.valueBlock.value.push(this.objectDigest),e}toJSON(){const e={digestedObjectType:this.digestedObjectType.toJSON(),digestAlgorithm:this.digestAlgorithm.toJSON(),objectDigest:this.objectDigest.toJSON()};return this.otherObjectTypeID&&(e.otherObjectTypeID=this.otherObjectTypeID.toJSON()),e}}ut.CLASS_NAME="ObjectDigestInfo";const ii="issuerName",ri="baseCertificateID",ai="objectDigestInfo",_y=[ii,ri,ai];class En extends k{constructor(e={}){super(),ii in e&&(this.issuerName=a(e,ii,En.defaultValues(ii))),ri in e&&(this.baseCertificateID=a(e,ri,En.defaultValues(ri))),ai in e&&(this.objectDigestInfo=a(e,ai,En.defaultValues(ai))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ii:return new xe;case ri:return new Xe;case ai:return new ut;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[xe.schema({names:{blockName:t.issuerName}},!0),new w({optional:!0,name:t.baseCertificateID||u,idBlock:{tagClass:3,tagNumber:0},value:Xe.schema().valueBlock.value}),new w({optional:!0,name:t.objectDigestInfo||u,idBlock:{tagClass:3,tagNumber:1},value:ut.schema().valueBlock.value})]})}fromSchema(e){C(e,_y);const t=N(e,e,En.schema({names:{issuerName:ii,baseCertificateID:ri,objectDigestInfo:ai}}));p.assertSchema(t,this.className),ii in t.result&&(this.issuerName=new xe({schema:t.result.issuerName})),ri in t.result&&(this.baseCertificateID=new Xe({schema:new f({value:t.result.baseCertificateID.valueBlock.value})})),ai in t.result&&(this.objectDigestInfo=new ut({schema:new f({value:t.result.objectDigestInfo.valueBlock.value})}))}toSchema(){const e=new f;return this.issuerName&&e.valueBlock.value.push(this.issuerName.toSchema()),this.baseCertificateID&&e.valueBlock.value.push(new w({idBlock:{tagClass:3,tagNumber:0},value:this.baseCertificateID.toSchema().valueBlock.value})),this.objectDigestInfo&&e.valueBlock.value.push(new w({idBlock:{tagClass:3,tagNumber:1},value:this.objectDigestInfo.toSchema().valueBlock.value})),e}toJSON(){const e={};return this.issuerName&&(e.issuerName=this.issuerName.toJSON()),this.baseCertificateID&&(e.baseCertificateID=this.baseCertificateID.toJSON()),this.objectDigestInfo&&(e.objectDigestInfo=this.objectDigestInfo.toJSON()),e}}En.CLASS_NAME="V2Form";const oi="baseCertificateID",li="entityName",ci="objectDigestInfo",$y=[oi,li,ci];class hs extends k{constructor(e={}){super(),oi in e&&(this.baseCertificateID=a(e,oi,hs.defaultValues(oi))),li in e&&(this.entityName=a(e,li,hs.defaultValues(li))),ci in e&&(this.objectDigestInfo=a(e,ci,hs.defaultValues(ci))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case oi:return new Xe;case li:return new xe;case ci:return new ut;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new w({optional:!0,name:t.baseCertificateID||u,idBlock:{tagClass:3,tagNumber:0},value:Xe.schema().valueBlock.value}),new w({optional:!0,name:t.entityName||u,idBlock:{tagClass:3,tagNumber:1},value:xe.schema().valueBlock.value}),new w({optional:!0,name:t.objectDigestInfo||u,idBlock:{tagClass:3,tagNumber:2},value:ut.schema().valueBlock.value})]})}fromSchema(e){C(e,$y);const t=N(e,e,hs.schema({names:{baseCertificateID:oi,entityName:li,objectDigestInfo:ci}}));p.assertSchema(t,this.className),oi in t.result&&(this.baseCertificateID=new Xe({schema:new f({value:t.result.baseCertificateID.valueBlock.value})})),li in t.result&&(this.entityName=new xe({schema:new f({value:t.result.entityName.valueBlock.value})})),ci in t.result&&(this.objectDigestInfo=new ut({schema:new f({value:t.result.objectDigestInfo.valueBlock.value})}))}toSchema(){const e=new f;return this.baseCertificateID&&e.valueBlock.value.push(new w({idBlock:{tagClass:3,tagNumber:0},value:this.baseCertificateID.toSchema().valueBlock.value})),this.entityName&&e.valueBlock.value.push(new w({idBlock:{tagClass:3,tagNumber:1},value:this.entityName.toSchema().valueBlock.value})),this.objectDigestInfo&&e.valueBlock.value.push(new w({idBlock:{tagClass:3,tagNumber:2},value:this.objectDigestInfo.toSchema().valueBlock.value})),e}toJSON(){const e={};return this.baseCertificateID&&(e.baseCertificateID=this.baseCertificateID.toJSON()),this.entityName&&(e.entityName=this.entityName.toJSON()),this.objectDigestInfo&&(e.objectDigestInfo=this.objectDigestInfo.toJSON()),e}}hs.CLASS_NAME="Holder";const Sl="version",Al="holder",pl="issuer",bl="signature",kl="serialNumber",El="attrCertValidityPeriod",Nl="attributes",ui="issuerUniqueID",hi="extensions",My=[Sl,Al,pl,bl,kl,El,Nl,ui,hi];class We extends k{constructor(e={}){super(),this.version=a(e,Sl,We.defaultValues(Sl)),this.holder=a(e,Al,We.defaultValues(Al)),this.issuer=a(e,pl,We.defaultValues(pl)),this.signature=a(e,bl,We.defaultValues(bl)),this.serialNumber=a(e,kl,We.defaultValues(kl)),this.attrCertValidityPeriod=a(e,El,We.defaultValues(El)),this.attributes=a(e,Nl,We.defaultValues(Nl)),ui in e&&(this.issuerUniqueID=a(e,ui,We.defaultValues(ui))),hi in e&&(this.extensions=a(e,hi,We.defaultValues(hi))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Sl:return 1;case Al:return new hs;case pl:return{};case bl:return new v;case kl:return new S;case El:return new Rt;case Nl:return[];case ui:return new W;case hi:return new ke;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),hs.schema(t.holder||{}),new he({value:[xe.schema({names:{blockName:t.issuer||u}}),new w({name:t.issuer||u,idBlock:{tagClass:3,tagNumber:0},value:En.schema().valueBlock.value})]}),v.schema(t.signature||{}),new S({name:t.serialNumber||u}),Rt.schema(t.attrCertValidityPeriod||{}),new f({name:t.attributes||u,value:[new J({value:le.schema()})]}),new W({optional:!0,name:t.issuerUniqueID||u}),ke.schema(t.extensions||{},!0)]})}fromSchema(e){C(e,My);const t=N(e,e,We.schema({names:{version:Sl,holder:{names:{blockName:Al}},issuer:pl,signature:{names:{blockName:bl}},serialNumber:kl,attrCertValidityPeriod:{names:{blockName:El}},attributes:Nl,issuerUniqueID:ui,extensions:{names:{blockName:hi}}}}));if(p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.holder=new hs({schema:t.result.holder}),t.result.issuer.idBlock.tagClass===3)this.issuer=new En({schema:new f({value:t.result.issuer.valueBlock.value})});else throw new Error("Incorrect value for 'issuer' in AttributeCertificateInfoV2");this.signature=new v({schema:t.result.signature}),this.serialNumber=t.result.serialNumber,this.attrCertValidityPeriod=new Rt({schema:t.result.attrCertValidityPeriod}),this.attributes=Array.from(t.result.attributes.valueBlock.value,s=>new le({schema:s})),ui in t.result&&(this.issuerUniqueID=t.result.issuerUniqueID),hi in t.result&&(this.extensions=new ke({schema:t.result.extensions}))}toSchema(){const e=new f({value:[new S({value:this.version}),this.holder.toSchema(),new w({idBlock:{tagClass:3,tagNumber:0},value:this.issuer.toSchema().valueBlock.value}),this.signature.toSchema(),this.serialNumber,this.attrCertValidityPeriod.toSchema(),new f({value:Array.from(this.attributes,t=>t.toSchema())})]});return this.issuerUniqueID&&e.valueBlock.value.push(this.issuerUniqueID),this.extensions&&e.valueBlock.value.push(this.extensions.toSchema()),e}toJSON(){const e={version:this.version,holder:this.holder.toJSON(),issuer:this.issuer.toJSON(),signature:this.signature.toJSON(),serialNumber:this.serialNumber.toJSON(),attrCertValidityPeriod:this.attrCertValidityPeriod.toJSON(),attributes:Array.from(this.attributes,t=>t.toJSON())};return this.issuerUniqueID&&(e.issuerUniqueID=this.issuerUniqueID.toJSON()),this.extensions&&(e.extensions=this.extensions.toJSON()),e}}We.CLASS_NAME="AttributeCertificateInfoV2";const Cl="acinfo",Bl="signatureAlgorithm",Il="signatureValue",Ky=[Cl,Bl,Il];class ht extends k{constructor(e={}){super(),this.acinfo=a(e,Cl,ht.defaultValues(Cl)),this.signatureAlgorithm=a(e,Bl,ht.defaultValues(Bl)),this.signatureValue=a(e,Il,ht.defaultValues(Il)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Cl:return new We;case Bl:return new v;case Il:return new W;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[We.schema(t.acinfo||{}),v.schema(t.signatureAlgorithm||{}),new W({name:t.signatureValue||u})]})}fromSchema(e){C(e,Ky);const t=N(e,e,ht.schema({names:{acinfo:{names:{blockName:Cl}},signatureAlgorithm:{names:{blockName:Bl}},signatureValue:Il}}));p.assertSchema(t,this.className),this.acinfo=new We({schema:t.result.acinfo}),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}toSchema(){return new f({value:[this.acinfo.toSchema(),this.signatureAlgorithm.toSchema(),this.signatureValue]})}toJSON(){return{acinfo:this.acinfo.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signatureValue:this.signatureValue.toJSON()}}}ht.CLASS_NAME="AttributeCertificateV2";const fi="contentType",Cr="content",Jy=[fi,Cr];class oe extends k{constructor(e={}){super(),this.contentType=a(e,fi,oe.defaultValues(fi)),this.content=a(e,Cr,oe.defaultValues(Cr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case fi:return u;case Cr:return new K;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case fi:return typeof t=="string"&&t===this.defaultValues(fi);case Cr:return t instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return"optional"in t||(t.optional=!1),new f({name:t.blockName||"ContentInfo",optional:t.optional,value:[new T({name:t.contentType||fi}),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.content||Cr})]})]})}fromSchema(e){C(e,Jy);const t=N(e,e,oe.schema());p.assertSchema(t,this.className),this.contentType=t.result.contentType.valueBlock.toString(),this.content=t.result.content}toSchema(){return new f({value:[new T({value:this.contentType}),new w({idBlock:{tagClass:3,tagNumber:0},value:[this.content]})]})}toJSON(){const e={contentType:this.contentType};return this.content instanceof K||(e.content=this.content.toJSON()),e}}oe.CLASS_NAME="ContentInfo";oe.DATA=Cf;oe.SIGNED_DATA=Qm;oe.ENVELOPED_DATA=Xm;oe.ENCRYPTED_DATA=Zm;const yh="type",vh="value",Kh="utcTimeName",Jh="generalTimeName",jy=[Kh,Jh];var md;(function(r){r[r.UTCTime=0]="UTCTime",r[r.GeneralizedTime=1]="GeneralizedTime",r[r.empty=2]="empty"})(md||(md={}));class Ce extends k{constructor(e={}){super(),this.type=a(e,yh,Ce.defaultValues(yh)),this.value=a(e,vh,Ce.defaultValues(vh)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case yh:return 0;case vh:return new Date(0,0,0);default:return super.defaultValues(e)}}static schema(e={},t=!1){const s=a(e,"names",{});return new he({optional:t,value:[new qa({name:s.utcTimeName||u}),new ue({name:s.generalTimeName||u})]})}fromSchema(e){C(e,jy);const t=N(e,e,Ce.schema({names:{utcTimeName:Kh,generalTimeName:Jh}}));p.assertSchema(t,this.className),Kh in t.result&&(this.type=0,this.value=t.result.utcTimeName.toDate()),Jh in t.result&&(this.type=1,this.value=t.result.generalTimeName.toDate())}toSchema(){return this.type===0?new qa({valueDate:this.value}):this.type===1?new ue({valueDate:this.value}):{}}toJSON(){return{type:this.type,value:this.value}}}Ce.CLASS_NAME="Time";const Sh="tbs",Gs="version",iu="serialNumber",ru="signature",au="issuer",ou="notBefore",lu="notAfter",cu="subject",uu="subjectPublicKeyInfo",Vl="issuerUniqueID",xl="subjectUniqueID",Ol="extensions",Rl="signatureAlgorithm",Tl="signatureValue",dt="tbsCertificate",Hu=`${dt}.${Gs}`,Bf=`${dt}.${iu}`,If=`${dt}.${ru}`,Vf=`${dt}.${au}`,_u=`${dt}.${ou}`,$u=`${dt}.${lu}`,xf=`${dt}.${cu}`,Of=`${dt}.${uu}`,Mu=`${dt}.${Vl}`,Ku=`${dt}.${xl}`,dc=`${dt}.${Ol}`,Fy=[dt,Hu,Bf,If,Vf,_u,$u,xf,Of,Mu,Ku,dc,Rl,Tl];function qy(r={}){const e=a(r,"names",{});return new f({name:e.blockName||dt,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({name:e.tbsCertificateVersion||Hu})]}),new S({name:e.tbsCertificateSerialNumber||Bf}),v.schema(e.signature||{names:{blockName:If}}),re.schema(e.issuer||{names:{blockName:Vf}}),new f({name:e.tbsCertificateValidity||"tbsCertificate.validity",value:[Ce.schema(e.notBefore||{names:{utcTimeName:_u,generalTimeName:_u}}),Ce.schema(e.notAfter||{names:{utcTimeName:$u,generalTimeName:$u}})]}),re.schema(e.subject||{names:{blockName:xf}}),je.schema(e.subjectPublicKeyInfo||{names:{blockName:Of}}),new _({name:e.tbsCertificateIssuerUniqueID||Mu,optional:!0,idBlock:{tagClass:3,tagNumber:1}}),new _({name:e.tbsCertificateSubjectUniqueID||Ku,optional:!0,idBlock:{tagClass:3,tagNumber:2}}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:3},value:[ke.schema(e.extensions||{names:{blockName:dc}})]})]})}class ee extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(a(e,Sh,ee.defaultValues(Sh))),this.version=a(e,Gs,ee.defaultValues(Gs)),this.serialNumber=a(e,iu,ee.defaultValues(iu)),this.signature=a(e,ru,ee.defaultValues(ru)),this.issuer=a(e,au,ee.defaultValues(au)),this.notBefore=a(e,ou,ee.defaultValues(ou)),this.notAfter=a(e,lu,ee.defaultValues(lu)),this.subject=a(e,cu,ee.defaultValues(cu)),this.subjectPublicKeyInfo=a(e,uu,ee.defaultValues(uu)),Vl in e&&(this.issuerUniqueID=a(e,Vl,ee.defaultValues(Vl))),xl in e&&(this.subjectUniqueID=a(e,xl,ee.defaultValues(xl))),Ol in e&&(this.extensions=a(e,Ol,ee.defaultValues(Ol))),this.signatureAlgorithm=a(e,Rl,ee.defaultValues(Rl)),this.signatureValue=a(e,Tl,ee.defaultValues(Tl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Sh:return be;case Gs:return 0;case iu:return new S;case ru:return new v;case au:return new re;case ou:return new Ce;case lu:return new Ce;case cu:return new re;case uu:return new je;case Vl:return be;case xl:return be;case Ol:return[];case Rl:return new v;case Tl:return new W;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[qy(t.tbsCertificate),v.schema(t.signatureAlgorithm||{names:{blockName:Rl}}),new W({name:t.signatureValue||Tl})]})}fromSchema(e){C(e,Fy);const t=N(e,e,ee.schema({names:{tbsCertificate:{names:{extensions:{names:{extensions:dc}}}}}}));p.assertSchema(t,this.className),this.tbsView=t.result.tbsCertificate.valueBeforeDecodeView,Hu in t.result&&(this.version=t.result[Hu].valueBlock.valueDec),this.serialNumber=t.result[Bf],this.signature=new v({schema:t.result[If]}),this.issuer=new re({schema:t.result[Vf]}),this.notBefore=new Ce({schema:t.result[_u]}),this.notAfter=new Ce({schema:t.result[$u]}),this.subject=new re({schema:t.result[xf]}),this.subjectPublicKeyInfo=new je({schema:t.result[Of]}),Mu in t.result&&(this.issuerUniqueID=t.result[Mu].valueBlock.valueHex),Ku in t.result&&(this.subjectUniqueID=t.result[Ku].valueBlock.valueHex),dc in t.result&&(this.extensions=Array.from(t.result[dc],s=>new Ve({schema:s}))),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}encodeTBS(){const e=[];return Gs in this&&this.version!==ee.defaultValues(Gs)&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({value:this.version})]})),e.push(this.serialNumber),e.push(this.signature.toSchema()),e.push(this.issuer.toSchema()),e.push(new f({value:[this.notBefore.toSchema(),this.notAfter.toSchema()]})),e.push(this.subject.toSchema()),e.push(this.subjectPublicKeyInfo.toSchema()),this.issuerUniqueID&&e.push(new _({optional:!0,idBlock:{tagClass:3,tagNumber:1},valueHex:this.issuerUniqueID})),this.subjectUniqueID&&e.push(new _({optional:!0,idBlock:{tagClass:3,tagNumber:2},valueHex:this.subjectUniqueID})),this.extensions&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:3},value:[new f({value:Array.from(this.extensions,t=>t.toSchema())})]})),new f({value:e})}toSchema(e=!1){let t;if(e===!1){if(!this.tbsView.byteLength)return ee.schema().value[0];const s=Oe(this.tbsView);p.assert(s,"TBS Certificate"),t=s.result}else t=this.encodeTBS();return new f({value:[t,this.signatureAlgorithm.toSchema(),this.signatureValue]})}toJSON(){const e={tbs:H.ToHex(this.tbsView),version:this.version,serialNumber:this.serialNumber.toJSON(),signature:this.signature.toJSON(),issuer:this.issuer.toJSON(),notBefore:this.notBefore.toJSON(),notAfter:this.notAfter.toJSON(),subject:this.subject.toJSON(),subjectPublicKeyInfo:this.subjectPublicKeyInfo.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signatureValue:this.signatureValue.toJSON()};return Gs in this&&this.version!==ee.defaultValues(Gs)&&(e.version=this.version),this.issuerUniqueID&&(e.issuerUniqueID=H.ToHex(this.issuerUniqueID)),this.subjectUniqueID&&(e.subjectUniqueID=H.ToHex(this.subjectUniqueID)),this.extensions&&(e.extensions=Array.from(this.extensions,t=>t.toJSON())),e}async getPublicKey(e,t=q(!0)){return t.getPublicKey(this.subjectPublicKeyInfo,this.signatureAlgorithm,e)}async getKeyHash(e="SHA-1",t=q(!0)){return t.digest({name:e},this.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView)}async sign(e,t="SHA-1",s=q(!0)){if(!e)throw new Error("Need to provide a private key for signing");const n=await s.getSignatureParameters(e,t),i=n.parameters;this.signature=n.signatureAlgorithm,this.signatureAlgorithm=n.signatureAlgorithm,this.tbsView=new Uint8Array(this.encodeTBS().toBER());const o=await s.signWithPrivateKey(this.tbsView,e,i);this.signatureValue=new W({valueHex:o})}async verify(e,t=q(!0)){let s;if(e?s=e.subjectPublicKeyInfo:this.issuer.isEqual(this.subject)&&(s=this.subjectPublicKeyInfo),!(s instanceof je))throw new Error("Please provide issuer certificate as a parameter");return t.verifyWithPublicKey(this.tbsView,this.signatureValue,s,this.signatureAlgorithm)}}ee.CLASS_NAME="Certificate";function ig(r,e=null){if(e&&r.issuer.isEqual(e.issuer)&&r.serialNumber.isEqual(e.serialNumber))return null;let t=!1;if(r.extensions){for(const s of r.extensions)if(s.extnID===bf&&s.parsedValue instanceof qi&&s.parsedValue.cA){t=!0;break}}return t?r:null}const Br="certId",Ir="certValue",lr="parsedValue",Wy=[Br,Ir];class Mi extends k{constructor(e={}){super(),this.certId=a(e,Br,Mi.defaultValues(Br)),this.certValue=a(e,Ir,Mi.defaultValues(Ir)),lr in e&&(this.parsedValue=a(e,lr,Mi.defaultValues(lr))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Br:return u;case Ir:return new K;case lr:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Br:return t===u;case Ir:return t instanceof K;case lr:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.id||"id"}),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.value||"value"})]})]})}fromSchema(e){C(e,Wy);const t=N(e,e,Mi.schema({names:{id:Br,value:Ir}}));p.assertSchema(t,this.className),this.certId=t.result.certId.valueBlock.toString(),this.certValue=t.result.certValue;const s=this.certValue.valueBlock.valueHexView;switch(this.certId){case Yf:try{this.parsedValue=ee.fromBER(s)}catch{ht.fromBER(s)}break;case Qf:this.parsedValue=ht.fromBER(s);break;case Xw:default:throw new Error(`Incorrect CERT_ID value in CertBag: ${this.certId}`)}}toSchema(){return lr in this&&("acinfo"in this.parsedValue?this.certId=Qf:this.certId=Yf,this.certValue=new I({valueHex:this.parsedValue.toSchema().toBER(!1)})),new f({value:[new T({value:this.certId}),new w({idBlock:{tagClass:3,tagNumber:0},value:["toSchema"in this.certValue?this.certValue.toSchema():this.certValue]})]})}toJSON(){return{certId:this.certId,certValue:this.certValue.toJSON()}}}Mi.CLASS_NAME="CertBag";const Dl="userCertificate",Vr="revocationDate",di="crlEntryExtensions",Gy=[Dl,Vr,di];class Ki extends k{constructor(e={}){super(),this.userCertificate=a(e,Dl,Ki.defaultValues(Dl)),this.revocationDate=a(e,Vr,Ki.defaultValues(Vr)),di in e&&(this.crlEntryExtensions=a(e,di,Ki.defaultValues(di))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Dl:return new S;case Vr:return new Ce;case di:return new ke;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.userCertificate||Dl}),Ce.schema({names:{utcTimeName:t.revocationDate||Vr,generalTimeName:t.revocationDate||Vr}}),ke.schema({names:{blockName:t.crlEntryExtensions||di}},!0)]})}fromSchema(e){C(e,Gy);const t=N(e,e,Ki.schema());p.assertSchema(t,this.className),this.userCertificate=t.result.userCertificate,this.revocationDate=new Ce({schema:t.result.revocationDate}),di in t.result&&(this.crlEntryExtensions=new ke({schema:t.result.crlEntryExtensions}))}toSchema(){const e=[this.userCertificate,this.revocationDate.toSchema()];return this.crlEntryExtensions&&e.push(this.crlEntryExtensions.toSchema()),new f({value:e})}toJSON(){const e={userCertificate:this.userCertificate.toJSON(),revocationDate:this.revocationDate.toJSON()};return this.crlEntryExtensions&&(e.crlEntryExtensions=this.crlEntryExtensions.toJSON()),e}}Ki.CLASS_NAME="RevokedCertificate";const Ah="tbs",ro="version",ph="signature",bh="issuer",kh="thisUpdate",Hc="nextUpdate",_c="revokedCertificates",$c="crlExtensions",Pl="signatureAlgorithm",Ll="signatureValue",bs="tbsCertList",Ju=`${bs}.version`,Rf=`${bs}.signature`,Tf=`${bs}.issuer`,ju=`${bs}.thisUpdate`,Cc=`${bs}.nextUpdate`,Fu=`${bs}.revokedCertificates`,qu=`${bs}.extensions`,Yy=[bs,Ju,Rf,Tf,ju,Cc,Fu,qu,Pl,Ll];function Qy(r={}){const e=a(r,"names",{});return new f({name:e.blockName||bs,value:[new S({optional:!0,name:e.tbsCertListVersion||Ju,value:2}),v.schema(e.signature||{names:{blockName:Rf}}),re.schema(e.issuer||{names:{blockName:Tf}}),Ce.schema(e.tbsCertListThisUpdate||{names:{utcTimeName:ju,generalTimeName:ju}}),Ce.schema(e.tbsCertListNextUpdate||{names:{utcTimeName:Cc,generalTimeName:Cc}},!0),new f({optional:!0,value:[new J({name:e.tbsCertListRevokedCertificates||Fu,value:new f({value:[new S,Ce.schema(),ke.schema({},!0)]})})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[ke.schema(e.crlExtensions||{names:{blockName:qu}})]})]})}const Xy=[Ef,Km,Hw,_w,Jm,kf,Nf,$w,Mw,jm];class Ie extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(a(e,Ah,Ie.defaultValues(Ah))),this.version=a(e,ro,Ie.defaultValues(ro)),this.signature=a(e,ph,Ie.defaultValues(ph)),this.issuer=a(e,bh,Ie.defaultValues(bh)),this.thisUpdate=a(e,kh,Ie.defaultValues(kh)),Hc in e&&(this.nextUpdate=a(e,Hc,Ie.defaultValues(Hc))),_c in e&&(this.revokedCertificates=a(e,_c,Ie.defaultValues(_c))),$c in e&&(this.crlExtensions=a(e,$c,Ie.defaultValues($c))),this.signatureAlgorithm=a(e,Pl,Ie.defaultValues(Pl)),this.signatureValue=a(e,Ll,Ie.defaultValues(Ll)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ah:return be;case ro:return 0;case ph:return new v;case bh:return new re;case kh:return new Ce;case Hc:return new Ce;case _c:return[];case $c:return new ke;case Pl:return new v;case Ll:return new W;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||"CertificateList",value:[Qy(e),v.schema(t.signatureAlgorithm||{names:{blockName:Pl}}),new W({name:t.signatureValue||Ll})]})}fromSchema(e){C(e,Yy);const t=N(e,e,Ie.schema());p.assertSchema(t,this.className),this.tbsView=t.result.tbsCertList.valueBeforeDecodeView,Ju in t.result&&(this.version=t.result[Ju].valueBlock.valueDec),this.signature=new v({schema:t.result[Rf]}),this.issuer=new re({schema:t.result[Tf]}),this.thisUpdate=new Ce({schema:t.result[ju]}),Cc in t.result&&(this.nextUpdate=new Ce({schema:t.result[Cc]})),Fu in t.result&&(this.revokedCertificates=Array.from(t.result[Fu],s=>new Ki({schema:s}))),qu in t.result&&(this.crlExtensions=new ke({schema:t.result[qu]})),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}encodeTBS(){const e=[];return this.version!==Ie.defaultValues(ro)&&e.push(new S({value:this.version})),e.push(this.signature.toSchema()),e.push(this.issuer.toSchema()),e.push(this.thisUpdate.toSchema()),this.nextUpdate&&e.push(this.nextUpdate.toSchema()),this.revokedCertificates&&e.push(new f({value:Array.from(this.revokedCertificates,t=>t.toSchema())})),this.crlExtensions&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[this.crlExtensions.toSchema()]})),new f({value:e})}toSchema(e=!1){let t;if(e)t=this.encodeTBS();else{if(!this.tbsView.byteLength)return Ie.schema();const s=Oe(this.tbsView);p.assert(s,"TBS Certificate Revocation List"),t=s.result}return new f({value:[t,this.signatureAlgorithm.toSchema(),this.signatureValue]})}toJSON(){const e={tbs:H.ToHex(this.tbsView),version:this.version,signature:this.signature.toJSON(),issuer:this.issuer.toJSON(),thisUpdate:this.thisUpdate.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signatureValue:this.signatureValue.toJSON()};return this.version!==Ie.defaultValues(ro)&&(e.version=this.version),this.nextUpdate&&(e.nextUpdate=this.nextUpdate.toJSON()),this.revokedCertificates&&(e.revokedCertificates=Array.from(this.revokedCertificates,t=>t.toJSON())),this.crlExtensions&&(e.crlExtensions=this.crlExtensions.toJSON()),e}isCertificateRevoked(e){if(!this.issuer.isEqual(e.issuer)||!this.revokedCertificates)return!1;for(const t of this.revokedCertificates)if(t.userCertificate.isEqual(e.serialNumber))return!0;return!1}async sign(e,t="SHA-1",s=q(!0)){if(!e)throw new Error("Need to provide a private key for signing");const n=await s.getSignatureParameters(e,t),{parameters:i}=n;this.signature=n.signatureAlgorithm,this.signatureAlgorithm=n.signatureAlgorithm,this.tbsView=new Uint8Array(this.encodeTBS().toBER());const o=await s.signWithPrivateKey(this.tbsView,e,i);this.signatureValue=new W({valueHex:o})}async verify(e={},t=q(!0)){let s;if(e.issuerCertificate&&(s=e.issuerCertificate.subjectPublicKeyInfo,!this.issuer.isEqual(e.issuerCertificate.subject)))return!1;if(e.publicKeyInfo&&(s=e.publicKeyInfo),!s)throw new Error("Issuer's certificate must be provided as an input parameter");if(this.crlExtensions){for(const n of this.crlExtensions.extensions)if(n.critical&&!Xy.includes(n.extnID))return!1}return t.verifyWithPublicKey(this.tbsView,this.signatureValue,s,this.signatureAlgorithm)}}Ie.CLASS_NAME="CertificateRevocationList";const xr="crlId",Or="crlValue",ao="parsedValue",Zy=[xr,Or];class Ji extends k{constructor(e={}){super(),this.crlId=a(e,xr,Ji.defaultValues(xr)),this.crlValue=a(e,Or,Ji.defaultValues(Or)),ao in e&&(this.parsedValue=a(e,ao,Ji.defaultValues(ao))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case xr:return u;case Or:return new K;case ao:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case xr:return t===u;case Or:return t instanceof K;case ao:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.id||"id"}),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.value||"value"})]})]})}fromSchema(e){C(e,Zy);const t=N(e,e,Ji.schema({names:{id:xr,value:Or}}));if(p.assertSchema(t,this.className),this.crlId=t.result.crlId.valueBlock.toString(),this.crlValue=t.result.crlValue,this.crlId===Xf)this.parsedValue=Ie.fromBER(this.certValue.valueBlock.valueHex);else throw new Error(`Incorrect CRL_ID value in CRLBag: ${this.crlId}`)}toSchema(){return this.parsedValue&&(this.crlId=Xf,this.crlValue=new I({valueHex:this.parsedValue.toSchema().toBER(!1)})),new f({value:[new T({value:this.crlId}),new w({idBlock:{tagClass:3,tagNumber:0},value:[this.crlValue.toSchema()]})]})}toJSON(){return{crlId:this.crlId,crlValue:this.crlValue.toJSON()}}}Ji.CLASS_NAME="CRLBag";const Rr="version",Tr="encryptedContentInfo",Ys="unprotectedAttrs",zy=[Rr,Tr,Ys];class Kt extends k{constructor(e={}){super(),this.version=a(e,Rr,Kt.defaultValues(Rr)),this.encryptedContentInfo=a(e,Tr,Kt.defaultValues(Tr)),Ys in e&&(this.unprotectedAttrs=a(e,Ys,Kt.defaultValues(Ys))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Rr:return 0;case Tr:return new Ee;case Ys:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Rr:return t===0;case Tr:return Ee.compareWithDefault("contentType",t.contentType)&&Ee.compareWithDefault("contentEncryptionAlgorithm",t.contentEncryptionAlgorithm)&&Ee.compareWithDefault("encryptedContent",t.encryptedContent);case Ys:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),Ee.schema(t.encryptedContentInfo||{}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.unprotectedAttrs||u,value:le.schema()})]})]})}fromSchema(e){C(e,zy);const t=N(e,e,Kt.schema({names:{version:Rr,encryptedContentInfo:{names:{blockName:Tr}},unprotectedAttrs:Ys}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.encryptedContentInfo=new Ee({schema:t.result.encryptedContentInfo}),Ys in t.result&&(this.unprotectedAttrs=Array.from(t.result.unprotectedAttrs,s=>new le({schema:s})))}toSchema(){const e=[];return e.push(new S({value:this.version})),e.push(this.encryptedContentInfo.toSchema()),this.unprotectedAttrs&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:Array.from(this.unprotectedAttrs,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={version:this.version,encryptedContentInfo:this.encryptedContentInfo.toJSON()};return this.unprotectedAttrs&&(e.unprotectedAttrs=Array.from(this.unprotectedAttrs,t=>t.toJSON())),e}async encrypt(e,t=q(!0)){ie.assert(e,"parameters","object");const s={...e,contentType:"1.2.840.113549.1.7.1"};this.encryptedContentInfo=await t.encryptEncryptedContentInfo(s)}async decrypt(e,t=q(!0)){ie.assert(e,"parameters","object");const s={...e,encryptedContentInfo:this.encryptedContentInfo};return t.decryptEncryptedContentInfo(s)}}Kt.CLASS_NAME="EncryptedData";const mi="encryptionAlgorithm",Qs="encryptedData",oo="parsedValue",ev=[mi,Qs];class Sn extends k{constructor(e={}){super(),this.encryptionAlgorithm=a(e,mi,Sn.defaultValues(mi)),this.encryptedData=a(e,Qs,Sn.defaultValues(Qs)),oo in e&&(this.parsedValue=a(e,oo,Sn.defaultValues(oo))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case mi:return new v;case Qs:return new I;case oo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case mi:return v.compareWithDefault("algorithmId",t.algorithmId)&&!("algorithmParams"in t);case Qs:return t.isEqual(Sn.defaultValues(e));case oo:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[v.schema(t.encryptionAlgorithm||{names:{blockName:mi}}),new he({value:[new I({name:t.encryptedData||Qs}),new I({idBlock:{isConstructed:!0},name:t.encryptedData||Qs})]})]})}fromSchema(e){C(e,ev);const t=N(e,e,Sn.schema({names:{encryptionAlgorithm:{names:{blockName:mi}},encryptedData:Qs}}));p.assertSchema(t,this.className),this.encryptionAlgorithm=new v({schema:t.result.encryptionAlgorithm}),this.encryptedData=t.result.encryptedData}toSchema(){return new f({value:[this.encryptionAlgorithm.toSchema(),this.encryptedData]})}toJSON(){return{encryptionAlgorithm:this.encryptionAlgorithm.toJSON(),encryptedData:this.encryptedData.toJSON()}}async parseInternalValues(e,t=q(!0)){const n=await new Kt({encryptedContentInfo:new Ee({contentEncryptionAlgorithm:this.encryptionAlgorithm,encryptedContent:this.encryptedData})}).decrypt(e,t);this.parsedValue=St.fromBER(n)}async makeInternalValues(e,t=q(!0)){if(!this.parsedValue)throw new Error('Please initialize "parsedValue" first');const s=new Kt,n={...e,contentToEncrypt:this.parsedValue.toSchema().toBER(!1)};if(await s.encrypt(n,t),!s.encryptedContentInfo.encryptedContent)throw new Error("The filed `encryptedContent` in EncryptedContentInfo is empty");this.encryptionAlgorithm=s.encryptedContentInfo.contentEncryptionAlgorithm,this.encryptedData=s.encryptedContentInfo.encryptedContent}}Sn.CLASS_NAME="PKCS8ShroudedKeyBag";const Dr="secretTypeId",Pr="secretValue",tv=[Dr,Pr];class Ka extends k{constructor(e={}){super(),this.secretTypeId=a(e,Dr,Ka.defaultValues(Dr)),this.secretValue=a(e,Pr,Ka.defaultValues(Pr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Dr:return u;case Pr:return new K;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Dr:return t===u;case Pr:return t instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.id||"id"}),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.value||"value"})]})]})}fromSchema(e){C(e,tv);const t=N(e,e,Ka.schema({names:{id:Dr,value:Pr}}));p.assertSchema(t,this.className),this.secretTypeId=t.result.secretTypeId.valueBlock.toString(),this.secretValue=t.result.secretValue}toSchema(){return new f({value:[new T({value:this.secretTypeId}),new w({idBlock:{tagClass:3,tagNumber:0},value:[this.secretValue.toSchema()]})]})}toJSON(){return{secretTypeId:this.secretTypeId,secretValue:this.secretValue.toJSON()}}}Ka.CLASS_NAME="SecretBag";class yn{static getItems(){return this.items||(this.items={},yn.register("1.2.840.113549.1.12.10.1.1",St),yn.register("1.2.840.113549.1.12.10.1.2",Sn),yn.register("1.2.840.113549.1.12.10.1.3",Mi),yn.register("1.2.840.113549.1.12.10.1.4",Ji),yn.register("1.2.840.113549.1.12.10.1.5",Ka),yn.register("1.2.840.113549.1.12.10.1.6",fs)),this.items}static register(e,t){this.getItems()[e]=t}static find(e){return this.getItems()[e]||null}}const gi="bagId",wi="bagValue",ss="bagAttributes",sv=[gi,wi,ss];class Nn extends k{constructor(e={}){super(),this.bagId=a(e,gi,Nn.defaultValues(gi)),this.bagValue=a(e,wi,Nn.defaultValues(wi)),ss in e&&(this.bagAttributes=a(e,ss,Nn.defaultValues(ss))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case gi:return u;case wi:return new K;case ss:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case gi:return t===u;case wi:return t instanceof K;case ss:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.bagId||gi}),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.bagValue||wi})]}),new pe({optional:!0,value:[new J({name:t.bagAttributes||ss,value:le.schema()})]})]})}fromSchema(e){C(e,sv);const t=N(e,e,Nn.schema({names:{bagId:gi,bagValue:wi,bagAttributes:ss}}));p.assertSchema(t,this.className),this.bagId=t.result.bagId.valueBlock.toString();const s=yn.find(this.bagId);if(!s)throw new Error(`Invalid BAG_ID for SafeBag: ${this.bagId}`);this.bagValue=new s({schema:t.result.bagValue}),ss in t.result&&(this.bagAttributes=Array.from(t.result.bagAttributes,n=>new le({schema:n})))}toSchema(){const e=[new T({value:this.bagId}),new w({idBlock:{tagClass:3,tagNumber:0},value:[this.bagValue.toSchema()]})];return this.bagAttributes&&e.push(new pe({value:Array.from(this.bagAttributes,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={bagId:this.bagId,bagValue:this.bagValue.toJSON()};return this.bagAttributes&&(e.bagAttributes=Array.from(this.bagAttributes,t=>t.toJSON())),e}}Nn.CLASS_NAME="SafeBag";const cr="safeBags";class fs extends k{constructor(e={}){super(),this.safeBags=a(e,cr,fs.defaultValues(cr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===cr?[]:super.defaultValues(e)}static compareWithDefault(e,t){return e===cr?t.length===0:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.safeBags||u,value:Nn.schema()})]})}fromSchema(e){C(e,[cr]);const t=N(e,e,fs.schema({names:{safeBags:cr}}));p.assertSchema(t,this.className),this.safeBags=Array.from(t.result.safeBags,s=>new Nn({schema:s}))}toSchema(){return new f({value:Array.from(this.safeBags,e=>e.toSchema())})}toJSON(){return{safeBags:Array.from(this.safeBags,e=>e.toJSON())}}}fs.CLASS_NAME="SafeContents";const Ul="otherCertFormat",Hl="otherCert",nv=[Ul,Hl];class xn extends k{constructor(e={}){super(),this.otherCertFormat=a(e,Ul,xn.defaultValues(Ul)),this.otherCert=a(e,Hl,xn.defaultValues(Hl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ul:return u;case Hl:return new K;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.otherCertFormat||Ul}),new K({name:t.otherCert||Hl})]})}fromSchema(e){C(e,nv);const t=N(e,e,xn.schema());p.assertSchema(t,this.className),this.otherCertFormat=t.result.otherCertFormat.valueBlock.toString(),this.otherCert=t.result.otherCert}toSchema(){return new f({value:[new T({value:this.otherCertFormat}),this.otherCert]})}toJSON(){const e={otherCertFormat:this.otherCertFormat};return this.otherCert instanceof K||(e.otherCert=this.otherCert.toJSON()),e}}const _l="certificates",iv=[_l];class Jt extends k{constructor(e={}){super(),this.certificates=a(e,_l,Jt.defaultValues(_l)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===_l?[]:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new pe({name:t.blockName||u,value:[new J({name:t.certificates||_l,value:new he({value:[ee.schema(),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K]}),new w({idBlock:{tagClass:3,tagNumber:1},value:[new f]}),new w({idBlock:{tagClass:3,tagNumber:2},value:ht.schema().valueBlock.value}),new w({idBlock:{tagClass:3,tagNumber:3},value:xn.schema().valueBlock.value})]})})]})}fromSchema(e){C(e,iv);const t=N(e,e,Jt.schema());p.assertSchema(t,this.className),this.certificates=Array.from(t.result.certificates||[],s=>{const n=s.idBlock.tagNumber;if(s.idBlock.tagClass===1)return new ee({schema:s});const i=new f({value:s.valueBlock.value});switch(n){case 1:return i.valueBlock.value[0].valueBlock.value[0].valueBlock.valueDec===1?new ht({schema:i}):new us({schema:i});case 2:return new ht({schema:i});case 3:return new xn({schema:i})}return s})}toSchema(){return new pe({value:Array.from(this.certificates,e=>{switch(!0){case e instanceof ee:return e.toSchema();case e instanceof us:return new w({idBlock:{tagClass:3,tagNumber:1},value:e.toSchema().valueBlock.value});case e instanceof ht:return new w({idBlock:{tagClass:3,tagNumber:2},value:e.toSchema().valueBlock.value});case e instanceof xn:return new w({idBlock:{tagClass:3,tagNumber:3},value:e.toSchema().valueBlock.value})}return e.toSchema()})})}toJSON(){return{certificates:Array.from(this.certificates,e=>e.toJSON())}}}Jt.CLASS_NAME="CertificateSet";const $l="otherRevInfoFormat",Ml="otherRevInfo",rv=[$l,Ml];class ws extends k{constructor(e={}){super(),this.otherRevInfoFormat=a(e,$l,ws.defaultValues($l)),this.otherRevInfo=a(e,Ml,ws.defaultValues(Ml)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case $l:return u;case Ml:return new K;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.otherRevInfoFormat||$l}),new K({name:t.otherRevInfo||Ml})]})}fromSchema(e){C(e,rv);const t=N(e,e,ws.schema());p.assertSchema(t,this.className),this.otherRevInfoFormat=t.result.otherRevInfoFormat.valueBlock.toString(),this.otherRevInfo=t.result.otherRevInfo}toSchema(){return new f({value:[new T({value:this.otherRevInfoFormat}),this.otherRevInfo]})}toJSON(){const e={otherRevInfoFormat:this.otherRevInfoFormat};return this.otherRevInfo instanceof K||(e.otherRevInfo=this.otherRevInfo.toJSON()),e}}ws.CLASS_NAME="OtherRevocationInfoFormat";const Kl="crls",Eh="otherRevocationInfos",av=[Kl];class ys extends k{constructor(e={}){super(),this.crls=a(e,Kl,ys.defaultValues(Kl)),this.otherRevocationInfos=a(e,Eh,ys.defaultValues(Eh)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Kl:return[];case Eh:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new pe({name:t.blockName||u,value:[new J({name:t.crls||u,value:new he({value:[Ie.schema(),new w({idBlock:{tagClass:3,tagNumber:1},value:[new T,new K]})]})})]})}fromSchema(e){C(e,av);const t=N(e,e,ys.schema({names:{crls:Kl}}));if(p.assertSchema(t,this.className),t.result.crls)for(const s of t.result.crls)s.idBlock.tagClass===1?this.crls.push(new Ie({schema:s})):this.otherRevocationInfos.push(new ws({schema:s}))}toSchema(){const e=[];return e.push(...Array.from(this.crls,t=>t.toSchema())),e.push(...Array.from(this.otherRevocationInfos,t=>{const s=t.toSchema();return s.idBlock.tagClass=3,s.idBlock.tagNumber=1,s})),new pe({value:e})}toJSON(){return{crls:Array.from(this.crls,e=>e.toJSON()),otherRevocationInfos:Array.from(this.otherRevocationInfos,e=>e.toJSON())}}}ys.CLASS_NAME="RevocationInfoChoices";const Jl="certs",yi="crls",ov=[Jl,yi];class zi extends k{constructor(e={}){super(),this.crls=a(e,yi,zi.defaultValues(yi)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Jl:return new Jt;case yi:return new ys;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Jl:return t.certificates.length===0;case yi:return t.crls.length===0&&t.otherRevocationInfos.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new w({name:t.certs||u,optional:!0,idBlock:{tagClass:3,tagNumber:0},value:Jt.schema().valueBlock.value}),new w({name:t.crls||u,optional:!0,idBlock:{tagClass:3,tagNumber:1},value:ys.schema().valueBlock.value})]})}fromSchema(e){C(e,ov);const t=N(e,e,zi.schema({names:{certs:Jl,crls:yi}}));p.assertSchema(t,this.className),Jl in t.result&&(this.certs=new Jt({schema:new pe({value:t.result.certs.valueBlock.value})})),yi in t.result&&(this.crls=new ys({schema:new pe({value:t.result.crls.valueBlock.value})}))}toSchema(){const e=[];return this.certs&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:this.certs.toSchema().valueBlock.value})),this.crls&&e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:this.crls.toSchema().valueBlock.value})),new f({value:e})}toJSON(){const e={};return this.certs&&(e.certs=this.certs.toJSON()),this.crls&&(e.crls=this.crls.toJSON()),e}}zi.CLASS_NAME="OriginatorInfo";const jl="issuer",Fl="serialNumber",lv=[jl,Fl];class Be extends k{constructor(e={}){super(),this.issuer=a(e,jl,Be.defaultValues(jl)),this.serialNumber=a(e,Fl,Be.defaultValues(Fl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case jl:return new re;case Fl:return new S;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[re.schema(t.issuer||{}),new S({name:t.serialNumber||u})]})}fromSchema(e){C(e,lv);const t=N(e,e,Be.schema({names:{issuer:{names:{blockName:jl}},serialNumber:Fl}}));p.assertSchema(t,this.className),this.issuer=new re({schema:t.result.issuer}),this.serialNumber=t.result.serialNumber}toSchema(){return new f({value:[this.issuer.toSchema(),this.serialNumber]})}toJSON(){return{issuer:this.issuer.toJSON(),serialNumber:this.serialNumber.toJSON()}}}Be.CLASS_NAME="IssuerAndSerialNumber";const Mc="variant",lo="value",cv=["blockName"];class Ja extends k{constructor(e={}){super(),this.variant=a(e,Mc,Ja.defaultValues(Mc)),lo in e&&(this.value=a(e,lo,Ja.defaultValues(lo))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Mc:return-1;case lo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Mc:return t===-1;case lo:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new he({value:[Be.schema({names:{blockName:t.blockName||u}}),new _({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:0}})]})}fromSchema(e){C(e,cv);const t=N(e,e,Ja.schema({names:{blockName:"blockName"}}));p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1?(this.variant=1,this.value=new Be({schema:t.result.blockName})):(this.variant=2,this.value=new I({valueHex:t.result.blockName.valueBlock.valueHex}))}toSchema(){switch(this.variant){case 1:if(!(this.value instanceof Be))throw new Error("Incorrect type of RecipientIdentifier.value. It should be IssuerAndSerialNumber.");return this.value.toSchema();case 2:if(!(this.value instanceof I))throw new Error("Incorrect type of RecipientIdentifier.value. It should be ASN.1 OctetString.");return new _({idBlock:{tagClass:3,tagNumber:0},valueHex:this.value.valueBlock.valueHexView});default:return new K}}toJSON(){const e={variant:this.variant};return(this.variant===1||this.variant===2)&&this.value&&(e.value=this.value.toJSON()),e}}Ja.CLASS_NAME="RecipientIdentifier";const vi="version",Lr="rid",Ur="keyEncryptionAlgorithm",Hr="encryptedKey",Kc="recipientCertificate",uv=[vi,Lr,Ur,Hr];class rt extends k{constructor(e={}){super(),this.version=a(e,vi,rt.defaultValues(vi)),this.rid=a(e,Lr,rt.defaultValues(Lr)),this.keyEncryptionAlgorithm=a(e,Ur,rt.defaultValues(Ur)),this.encryptedKey=a(e,Hr,rt.defaultValues(Hr)),this.recipientCertificate=a(e,Kc,rt.defaultValues(Kc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case vi:return-1;case Lr:return{};case Ur:return new v;case Hr:return new I;case Kc:return new ee;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case vi:return t===rt.defaultValues(vi);case Lr:return Object.keys(t).length===0;case Ur:case Hr:return t.isEqual(rt.defaultValues(e));case Kc:return!1;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),Ja.schema(t.rid||{}),v.schema(t.keyEncryptionAlgorithm||{}),new I({name:t.encryptedKey||u})]})}fromSchema(e){C(e,uv);const t=N(e,e,rt.schema({names:{version:vi,rid:{names:{blockName:Lr}},keyEncryptionAlgorithm:{names:{blockName:Ur}},encryptedKey:Hr}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,t.result.rid.idBlock.tagClass===3?this.rid=new I({valueHex:t.result.rid.valueBlock.valueHex}):this.rid=new Be({schema:t.result.rid}),this.keyEncryptionAlgorithm=new v({schema:t.result.keyEncryptionAlgorithm}),this.encryptedKey=t.result.encryptedKey}toSchema(){const e=[];return this.rid instanceof Be?(this.version=0,e.push(new S({value:this.version})),e.push(this.rid.toSchema())):(this.version=2,e.push(new S({value:this.version})),e.push(new _({idBlock:{tagClass:3,tagNumber:0},valueHex:this.rid.valueBlock.valueHexView}))),e.push(this.keyEncryptionAlgorithm.toSchema()),e.push(this.encryptedKey),new f({value:e})}toJSON(){return{version:this.version,rid:this.rid.toJSON(),keyEncryptionAlgorithm:this.keyEncryptionAlgorithm.toJSON(),encryptedKey:this.encryptedKey.toJSON()}}}rt.CLASS_NAME="KeyTransRecipientInfo";const _r="algorithm",$r="publicKey",hv=[_r,$r];class ds extends k{constructor(e={}){super(),this.algorithm=a(e,_r,ds.defaultValues(_r)),this.publicKey=a(e,$r,ds.defaultValues($r)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case _r:return new v;case $r:return new W;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case _r:case $r:return t.isEqual(ds.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[v.schema(t.algorithm||{}),new W({name:t.publicKey||u})]})}fromSchema(e){C(e,hv);const t=N(e,e,ds.schema({names:{algorithm:{names:{blockName:_r}},publicKey:$r}}));p.assertSchema(t,this.className),this.algorithm=new v({schema:t.result.algorithm}),this.publicKey=t.result.publicKey}toSchema(){return new f({value:[this.algorithm.toSchema(),this.publicKey]})}toJSON(){return{algorithm:this.algorithm.toJSON(),publicKey:this.publicKey.toJSON()}}}ds.CLASS_NAME="OriginatorPublicKey";const Jc="variant",co="value",fv=["blockName"];class vs extends k{constructor(e={}){super(),this.variant=a(e,Jc,vs.defaultValues(Jc)),co in e&&(this.value=a(e,co,vs.defaultValues(co))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Jc:return-1;case co:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Jc:return t===-1;case co:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new he({value:[Be.schema({names:{blockName:t.blockName||u}}),new _({idBlock:{tagClass:3,tagNumber:0},name:t.blockName||u}),new w({idBlock:{tagClass:3,tagNumber:1},name:t.blockName||u,value:ds.schema().valueBlock.value})]})}fromSchema(e){C(e,fv);const t=N(e,e,vs.schema({names:{blockName:"blockName"}}));p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1?(this.variant=1,this.value=new Be({schema:t.result.blockName})):t.result.blockName.idBlock.tagNumber===0?(t.result.blockName.idBlock.tagClass=1,t.result.blockName.idBlock.tagNumber=4,this.variant=2,this.value=t.result.blockName):(this.variant=3,this.value=new ds({schema:new f({value:t.result.blockName.valueBlock.value})}))}toSchema(){switch(this.variant){case 1:return this.value.toSchema();case 2:return this.value.idBlock.tagClass=3,this.value.idBlock.tagNumber=0,this.value;case 3:{const e=this.value.toSchema();return e.idBlock.tagClass=3,e.idBlock.tagNumber=1,e}default:return new K}}toJSON(){const e={variant:this.variant};return(this.variant===1||this.variant===2||this.variant===3)&&(e.value=this.value.toJSON()),e}}vs.CLASS_NAME="OriginatorIdentifierOrKey";const Mr="keyAttrId",Ht="keyAttr",dv=[Mr,Ht];class Tt extends k{constructor(e={}){super(),this.keyAttrId=a(e,Mr,Tt.defaultValues(Mr)),Ht in e&&(this.keyAttr=a(e,Ht,Tt.defaultValues(Ht))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Mr:return u;case Ht:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Mr:return typeof t=="string"&&t===u;case Ht:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({optional:t.optional||!0,name:t.blockName||u,value:[new T({name:t.keyAttrId||u}),new K({optional:!0,name:t.keyAttr||u})]})}fromSchema(e){C(e,dv);const t=N(e,e,Tt.schema({names:{keyAttrId:Mr,keyAttr:Ht}}));p.assertSchema(t,this.className),this.keyAttrId=t.result.keyAttrId.valueBlock.toString(),Ht in t.result&&(this.keyAttr=t.result.keyAttr)}toSchema(){const e=[];return e.push(new T({value:this.keyAttrId})),Ht in this&&e.push(this.keyAttr),new f({value:e})}toJSON(){const e={keyAttrId:this.keyAttrId};return Ht in this&&(e.keyAttr=this.keyAttr.toJSON()),e}}Tt.CLASS_NAME="OtherKeyAttribute";const Si="subjectKeyIdentifier",Xs="date",Zs="other",mv=[Si,Xs,Zs];class $t extends k{constructor(e={}){super(),this.subjectKeyIdentifier=a(e,Si,$t.defaultValues(Si)),Xs in e&&(this.date=a(e,Xs,$t.defaultValues(Xs))),Zs in e&&(this.other=a(e,Zs,$t.defaultValues(Zs))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Si:return new I;case Xs:return new ue;case Zs:return new Tt;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Si:return t.isEqual($t.defaultValues(Si));case Xs:return t.year===0&&t.month===0&&t.day===0&&t.hour===0&&t.minute===0&&t.second===0&&t.millisecond===0;case Zs:return t.keyAttrId===u&&!("keyAttr"in t);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new I({name:t.subjectKeyIdentifier||u}),new ue({optional:!0,name:t.date||u}),Tt.schema(t.other||{})]})}fromSchema(e){C(e,mv);const t=N(e,e,$t.schema({names:{subjectKeyIdentifier:Si,date:Xs,other:{names:{blockName:Zs}}}}));p.assertSchema(t,this.className),this.subjectKeyIdentifier=t.result.subjectKeyIdentifier,Xs in t.result&&(this.date=t.result.date),Zs in t.result&&(this.other=new Tt({schema:t.result.other}))}toSchema(){const e=[];return e.push(this.subjectKeyIdentifier),this.date&&e.push(this.date),this.other&&e.push(this.other.toSchema()),new f({value:e})}toJSON(){const e={subjectKeyIdentifier:this.subjectKeyIdentifier.toJSON()};return this.date&&(e.date=this.date.toJSON()),this.other&&(e.other=this.other.toJSON()),e}}$t.CLASS_NAME="RecipientKeyIdentifier";const jc="variant",Fc="value",gv=["blockName"];class jt extends k{constructor(e={}){super(),this.variant=a(e,jc,jt.defaultValues(jc)),this.value=a(e,Fc,jt.defaultValues(Fc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case jc:return-1;case Fc:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case jc:return t===-1;case Fc:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new he({value:[Be.schema(t.issuerAndSerialNumber||{names:{blockName:t.blockName||u}}),new w({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:0},value:$t.schema(t.rKeyId||{names:{blockName:t.blockName||u}}).valueBlock.value})]})}fromSchema(e){C(e,gv);const t=N(e,e,jt.schema({names:{blockName:"blockName"}}));p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1?(this.variant=1,this.value=new Be({schema:t.result.blockName})):(this.variant=2,this.value=new $t({schema:new f({value:t.result.blockName.valueBlock.value})}))}toSchema(){switch(this.variant){case 1:return this.value.toSchema();case 2:return new w({idBlock:{tagClass:3,tagNumber:0},value:this.value.toSchema().valueBlock.value});default:return new K}}toJSON(){const e={variant:this.variant};return(this.variant===1||this.variant===2)&&(e.value=this.value.toJSON()),e}}jt.CLASS_NAME="KeyAgreeRecipientIdentifier";const Kr="rid",Ai="encryptedKey",wv=[Kr,Ai];class ms extends k{constructor(e={}){super(),this.rid=a(e,Kr,ms.defaultValues(Kr)),this.encryptedKey=a(e,Ai,ms.defaultValues(Ai)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Kr:return new jt;case Ai:return new I;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Kr:return t.variant===-1&&!("value"in t);case Ai:return t.isEqual(ms.defaultValues(Ai));default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[jt.schema(t.rid||{}),new I({name:t.encryptedKey||u})]})}fromSchema(e){C(e,wv);const t=N(e,e,ms.schema({names:{rid:{names:{blockName:Kr}},encryptedKey:Ai}}));p.assertSchema(t,this.className),this.rid=new jt({schema:t.result.rid}),this.encryptedKey=t.result.encryptedKey}toSchema(){return new f({value:[this.rid.toSchema(),this.encryptedKey]})}toJSON(){return{rid:this.rid.toJSON(),encryptedKey:this.encryptedKey.toJSON()}}}ms.CLASS_NAME="RecipientEncryptedKey";const qc="encryptedKeys",rg="RecipientEncryptedKeys",yv=[rg];class On extends k{constructor(e={}){super(),this.encryptedKeys=a(e,qc,On.defaultValues(qc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===qc?[]:super.defaultValues(e)}static compareWithDefault(e,t){return e===qc?t.length===0:super.defaultValues(e)}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.RecipientEncryptedKeys||u,value:ms.schema()})]})}fromSchema(e){C(e,yv);const t=N(e,e,On.schema({names:{RecipientEncryptedKeys:rg}}));p.assertSchema(t,this.className),this.encryptedKeys=Array.from(t.result.RecipientEncryptedKeys,s=>new ms({schema:s}))}toSchema(){return new f({value:Array.from(this.encryptedKeys,e=>e.toSchema())})}toJSON(){return{encryptedKeys:Array.from(this.encryptedKeys,e=>e.toJSON())}}}On.CLASS_NAME="RecipientEncryptedKeys";const Jr="version",jr="originator",ns="ukm",Fr="keyEncryptionAlgorithm",qr="recipientEncryptedKeys",Wc="recipientCertificate",Gc="recipientPublicKey",vv=[Jr,jr,ns,Fr,qr];class tt extends k{constructor(e={}){super(),this.version=a(e,Jr,tt.defaultValues(Jr)),this.originator=a(e,jr,tt.defaultValues(jr)),ns in e&&(this.ukm=a(e,ns,tt.defaultValues(ns))),this.keyEncryptionAlgorithm=a(e,Fr,tt.defaultValues(Fr)),this.recipientEncryptedKeys=a(e,qr,tt.defaultValues(qr)),this.recipientCertificate=a(e,Wc,tt.defaultValues(Wc)),this.recipientPublicKey=a(e,Gc,tt.defaultValues(Gc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Jr:return 0;case jr:return new vs;case ns:return new I;case Fr:return new v;case qr:return new On;case Wc:return new ee;case Gc:return null;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Jr:return t===0;case jr:return t.variant===-1&&!("value"in t);case ns:return t.isEqual(tt.defaultValues(ns));case Fr:return t.algorithmId===u&&!("algorithmParams"in t);case qr:return t.encryptedKeys.length===0;case Wc:return!1;case Gc:return!1;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),new w({idBlock:{tagClass:3,tagNumber:0},value:[vs.schema(t.originator||{})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new I({name:t.ukm||u})]}),v.schema(t.keyEncryptionAlgorithm||{}),On.schema(t.recipientEncryptedKeys||{})]})}fromSchema(e){C(e,vv);const t=N(e,e,tt.schema({names:{version:Jr,originator:{names:{blockName:jr}},ukm:ns,keyEncryptionAlgorithm:{names:{blockName:Fr}},recipientEncryptedKeys:{names:{blockName:qr}}}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.originator=new vs({schema:t.result.originator}),ns in t.result&&(this.ukm=t.result.ukm),this.keyEncryptionAlgorithm=new v({schema:t.result.keyEncryptionAlgorithm}),this.recipientEncryptedKeys=new On({schema:t.result.recipientEncryptedKeys})}toSchema(){const e=[];return e.push(new S({value:this.version})),e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[this.originator.toSchema()]})),this.ukm&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[this.ukm]})),e.push(this.keyEncryptionAlgorithm.toSchema()),e.push(this.recipientEncryptedKeys.toSchema()),new f({value:e})}toJSON(){const e={version:this.version,originator:this.originator.toJSON(),keyEncryptionAlgorithm:this.keyEncryptionAlgorithm.toJSON(),recipientEncryptedKeys:this.recipientEncryptedKeys.toJSON()};return this.ukm&&(e.ukm=this.ukm.toJSON()),e}}tt.CLASS_NAME="KeyAgreeRecipientInfo";const pi="keyIdentifier",zs="date",en="other",Sv=[pi,zs,en];class Vt extends k{constructor(e={}){super(),this.keyIdentifier=a(e,pi,Vt.defaultValues(pi)),zs in e&&(this.date=a(e,zs,Vt.defaultValues(zs))),en in e&&(this.other=a(e,en,Vt.defaultValues(en))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case pi:return new I;case zs:return new ue;case en:return new Tt;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case pi:return t.isEqual(Vt.defaultValues(pi));case zs:return t.year===0&&t.month===0&&t.day===0&&t.hour===0&&t.minute===0&&t.second===0&&t.millisecond===0;case en:return t.compareWithDefault("keyAttrId",t.keyAttrId)&&!("keyAttr"in t);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new I({name:t.keyIdentifier||u}),new ue({optional:!0,name:t.date||u}),Tt.schema(t.other||{})]})}fromSchema(e){C(e,Sv);const t=N(e,e,Vt.schema({names:{keyIdentifier:pi,date:zs,other:{names:{blockName:en}}}}));p.assertSchema(t,this.className),this.keyIdentifier=t.result.keyIdentifier,zs in t.result&&(this.date=t.result.date),en in t.result&&(this.other=new Tt({schema:t.result.other}))}toSchema(){const e=[];return e.push(this.keyIdentifier),this.date&&e.push(this.date),this.other&&e.push(this.other.toSchema()),new f({value:e})}toJSON(){const e={keyIdentifier:this.keyIdentifier.toJSON()};return this.date&&(e.date=this.date),this.other&&(e.other=this.other.toJSON()),e}}Vt.CLASS_NAME="KEKIdentifier";const Wr="version",Gr="kekid",Yr="keyEncryptionAlgorithm",bi="encryptedKey",Yc="preDefinedKEK",Av=[Wr,Gr,Yr,bi];class at extends k{constructor(e={}){super(),this.version=a(e,Wr,at.defaultValues(Wr)),this.kekid=a(e,Gr,at.defaultValues(Gr)),this.keyEncryptionAlgorithm=a(e,Yr,at.defaultValues(Yr)),this.encryptedKey=a(e,bi,at.defaultValues(bi)),this.preDefinedKEK=a(e,Yc,at.defaultValues(Yc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Wr:return 0;case Gr:return new Vt;case Yr:return new v;case bi:return new I;case Yc:return be;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case"KEKRecipientInfo":return t===at.defaultValues(Wr);case Gr:return t.compareWithDefault("keyIdentifier",t.keyIdentifier)&&!("date"in t)&&!("other"in t);case Yr:return t.algorithmId===u&&!("algorithmParams"in t);case bi:return t.isEqual(at.defaultValues(bi));case Yc:return t.byteLength===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),Vt.schema(t.kekid||{}),v.schema(t.keyEncryptionAlgorithm||{}),new I({name:t.encryptedKey||u})]})}fromSchema(e){C(e,Av);const t=N(e,e,at.schema({names:{version:Wr,kekid:{names:{blockName:Gr}},keyEncryptionAlgorithm:{names:{blockName:Yr}},encryptedKey:bi}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.kekid=new Vt({schema:t.result.kekid}),this.keyEncryptionAlgorithm=new v({schema:t.result.keyEncryptionAlgorithm}),this.encryptedKey=t.result.encryptedKey}toSchema(){return new f({value:[new S({value:this.version}),this.kekid.toSchema(),this.keyEncryptionAlgorithm.toSchema(),this.encryptedKey]})}toJSON(){return{version:this.version,kekid:this.kekid.toJSON(),keyEncryptionAlgorithm:this.keyEncryptionAlgorithm.toJSON(),encryptedKey:this.encryptedKey.toJSON()}}}at.CLASS_NAME="KEKRecipientInfo";const Qr="version",tn="keyDerivationAlgorithm",Xr="keyEncryptionAlgorithm",ki="encryptedKey",Qc="password",pv=[Qr,tn,Xr,ki];class vt extends k{constructor(e={}){super(),this.version=a(e,Qr,vt.defaultValues(Qr)),tn in e&&(this.keyDerivationAlgorithm=a(e,tn,vt.defaultValues(tn))),this.keyEncryptionAlgorithm=a(e,Xr,vt.defaultValues(Xr)),this.encryptedKey=a(e,ki,vt.defaultValues(ki)),this.password=a(e,Qc,vt.defaultValues(Qc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Qr:return-1;case tn:return new v;case Xr:return new v;case ki:return new I;case Qc:return be;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Qr:return t===-1;case tn:case Xr:return t.algorithmId===u&&!("algorithmParams"in t);case ki:return t.isEqual(vt.defaultValues(ki));case Qc:return t.byteLength===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),new w({name:t.keyDerivationAlgorithm||u,optional:!0,idBlock:{tagClass:3,tagNumber:0},value:v.schema().valueBlock.value}),v.schema(t.keyEncryptionAlgorithm||{}),new I({name:t.encryptedKey||u})]})}fromSchema(e){C(e,pv);const t=N(e,e,vt.schema({names:{version:Qr,keyDerivationAlgorithm:tn,keyEncryptionAlgorithm:{names:{blockName:Xr}},encryptedKey:ki}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,tn in t.result&&(this.keyDerivationAlgorithm=new v({schema:new f({value:t.result.keyDerivationAlgorithm.valueBlock.value})})),this.keyEncryptionAlgorithm=new v({schema:t.result.keyEncryptionAlgorithm}),this.encryptedKey=t.result.encryptedKey}toSchema(){const e=[];return e.push(new S({value:this.version})),this.keyDerivationAlgorithm&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:this.keyDerivationAlgorithm.toSchema().valueBlock.value})),e.push(this.keyEncryptionAlgorithm.toSchema()),e.push(this.encryptedKey),new f({value:e})}toJSON(){const e={version:this.version,keyEncryptionAlgorithm:this.keyEncryptionAlgorithm.toJSON(),encryptedKey:this.encryptedKey.toJSON()};return this.keyDerivationAlgorithm&&(e.keyDerivationAlgorithm=this.keyDerivationAlgorithm.toJSON()),e}}vt.CLASS_NAME="PasswordRecipientInfo";const Zr="oriType",Ei="oriValue",bv=[Zr,Ei];class Cn extends k{constructor(e={}){super(),this.oriType=a(e,Zr,Cn.defaultValues(Zr)),this.oriValue=a(e,Ei,Cn.defaultValues(Ei)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Zr:return u;case Ei:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Zr:return t===u;case Ei:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.oriType||u}),new K({name:t.oriValue||u})]})}fromSchema(e){C(e,bv);const t=N(e,e,Cn.schema({names:{oriType:Zr,oriValue:Ei}}));p.assertSchema(t,this.className),this.oriType=t.result.oriType.valueBlock.toString(),this.oriValue=t.result.oriValue}toSchema(){return new f({value:[new T({value:this.oriType}),this.oriValue]})}toJSON(){const e={oriType:this.oriType};return Cn.compareWithDefault(Ei,this.oriValue)||(e.oriValue=this.oriValue.toJSON()),e}}Cn.CLASS_NAME="OtherRecipientInfo";const Xc="variant",uo="value",kv=["blockName"];class At extends k{constructor(e={}){super(),this.variant=a(e,Xc,At.defaultValues(Xc)),uo in e&&(this.value=a(e,uo,At.defaultValues(uo))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Xc:return-1;case uo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Xc:return t===At.defaultValues(e);case uo:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new he({value:[rt.schema({names:{blockName:t.blockName||u}}),new w({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:1},value:tt.schema().valueBlock.value}),new w({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:2},value:at.schema().valueBlock.value}),new w({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:3},value:vt.schema().valueBlock.value}),new w({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:4},value:Cn.schema().valueBlock.value})]})}fromSchema(e){C(e,kv);const t=N(e,e,At.schema({names:{blockName:"blockName"}}));if(p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1)this.variant=1,this.value=new rt({schema:t.result.blockName});else{const s=new f({value:t.result.blockName.valueBlock.value});switch(t.result.blockName.idBlock.tagNumber){case 1:this.variant=2,this.value=new tt({schema:s});break;case 2:this.variant=3,this.value=new at({schema:s});break;case 3:this.variant=4,this.value=new vt({schema:s});break;case 4:this.variant=5,this.value=new Cn({schema:s});break;default:throw new Error("Incorrect structure of RecipientInfo block")}}}toSchema(){Q.assertEmpty(this.value,"value","RecipientInfo");const e=this.value.toSchema();switch(this.variant){case 1:return e;case 2:case 3:case 4:return e.idBlock.tagClass=3,e.idBlock.tagNumber=this.variant-1,e;default:return new K}}toJSON(){const e={variant:this.variant};return this.value&&this.variant>=1&&this.variant<=4&&(e.value=this.value.toJSON()),e}}At.CLASS_NAME="RecipientInfo";const sn="hashAlgorithm",nn="maskGenAlgorithm",rn="pSourceAlgorithm",Ev=[sn,nn,rn];class Ge extends k{constructor(e={}){super(),this.hashAlgorithm=a(e,sn,Ge.defaultValues(sn)),this.maskGenAlgorithm=a(e,nn,Ge.defaultValues(nn)),this.pSourceAlgorithm=a(e,rn,Ge.defaultValues(rn)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case sn:return new v({algorithmId:"1.3.14.3.2.26",algorithmParams:new Ae});case nn:return new v({algorithmId:"1.2.840.113549.1.1.8",algorithmParams:new v({algorithmId:"1.3.14.3.2.26",algorithmParams:new Ae}).toSchema()});case rn:return new v({algorithmId:"1.2.840.113549.1.1.9",algorithmParams:new I({valueHex:new Uint8Array([218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9]).buffer})});default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new w({idBlock:{tagClass:3,tagNumber:0},optional:!0,value:[v.schema(t.hashAlgorithm||{})]}),new w({idBlock:{tagClass:3,tagNumber:1},optional:!0,value:[v.schema(t.maskGenAlgorithm||{})]}),new w({idBlock:{tagClass:3,tagNumber:2},optional:!0,value:[v.schema(t.pSourceAlgorithm||{})]})]})}fromSchema(e){C(e,Ev);const t=N(e,e,Ge.schema({names:{hashAlgorithm:{names:{blockName:sn}},maskGenAlgorithm:{names:{blockName:nn}},pSourceAlgorithm:{names:{blockName:rn}}}}));p.assertSchema(t,this.className),sn in t.result&&(this.hashAlgorithm=new v({schema:t.result.hashAlgorithm})),nn in t.result&&(this.maskGenAlgorithm=new v({schema:t.result.maskGenAlgorithm})),rn in t.result&&(this.pSourceAlgorithm=new v({schema:t.result.pSourceAlgorithm}))}toSchema(){const e=[];return this.hashAlgorithm.isEqual(Ge.defaultValues(sn))||e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[this.hashAlgorithm.toSchema()]})),this.maskGenAlgorithm.isEqual(Ge.defaultValues(nn))||e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[this.maskGenAlgorithm.toSchema()]})),this.pSourceAlgorithm.isEqual(Ge.defaultValues(rn))||e.push(new w({idBlock:{tagClass:3,tagNumber:2},value:[this.pSourceAlgorithm.toSchema()]})),new f({value:e})}toJSON(){const e={};return this.hashAlgorithm.isEqual(Ge.defaultValues(sn))||(e.hashAlgorithm=this.hashAlgorithm.toJSON()),this.maskGenAlgorithm.isEqual(Ge.defaultValues(nn))||(e.maskGenAlgorithm=this.maskGenAlgorithm.toJSON()),this.pSourceAlgorithm.isEqual(Ge.defaultValues(rn))||(e.pSourceAlgorithm=this.pSourceAlgorithm.toJSON()),e}}Ge.CLASS_NAME="RSAESOAEPParams";const zr="keyInfo",an="entityUInfo",ea="suppPubInfo",Nv=[zr,an,ea];class ls extends k{constructor(e={}){super(),this.keyInfo=a(e,zr,ls.defaultValues(zr)),an in e&&(this.entityUInfo=a(e,an,ls.defaultValues(an))),this.suppPubInfo=a(e,ea,ls.defaultValues(ea)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case zr:return new v;case an:return new I;case ea:return new I;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case zr:case an:case ea:return t.isEqual(ls.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[v.schema(t.keyInfo||{}),new w({name:t.entityUInfo||u,idBlock:{tagClass:3,tagNumber:0},optional:!0,value:[new I]}),new w({name:t.suppPubInfo||u,idBlock:{tagClass:3,tagNumber:2},value:[new I]})]})}fromSchema(e){C(e,Nv);const t=N(e,e,ls.schema({names:{keyInfo:{names:{blockName:zr}},entityUInfo:an,suppPubInfo:ea}}));p.assertSchema(t,this.className),this.keyInfo=new v({schema:t.result.keyInfo}),an in t.result&&(this.entityUInfo=t.result.entityUInfo.valueBlock.value[0]),this.suppPubInfo=t.result.suppPubInfo.valueBlock.value[0]}toSchema(){const e=[];return e.push(this.keyInfo.toSchema()),this.entityUInfo&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[this.entityUInfo]})),e.push(new w({idBlock:{tagClass:3,tagNumber:2},value:[this.suppPubInfo]})),new f({value:e})}toJSON(){const e={keyInfo:this.keyInfo.toJSON(),suppPubInfo:this.suppPubInfo.toJSON()};return this.entityUInfo&&(e.entityUInfo=this.entityUInfo.toJSON()),e}}ls.CLASS_NAME="ECCCMSSharedInfo";const ta="version",on="originatorInfo",sa="recipientInfos",na="encryptedContentInfo",ln="unprotectedAttrs",Cv=[ta,on,sa,na,ln],gd={kdfAlgorithm:"SHA-512",kekEncryptionLength:256},Bv={"P-256":256,"P-384":384,"P-521":528};class Bt extends k{constructor(e={}){super(),this.version=a(e,ta,Bt.defaultValues(ta)),on in e&&(this.originatorInfo=a(e,on,Bt.defaultValues(on))),this.recipientInfos=a(e,sa,Bt.defaultValues(sa)),this.encryptedContentInfo=a(e,na,Bt.defaultValues(na)),ln in e&&(this.unprotectedAttrs=a(e,ln,Bt.defaultValues(ln))),this.policy={disableSplit:!!e.disableSplit},e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ta:return 0;case on:return new zi;case sa:return[];case na:return new Ee;case ln:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ta:return t===Bt.defaultValues(e);case on:return t.certs.certificates.length===0&&t.crls.crls.length===0;case sa:case ln:return t.length===0;case na:return Ee.compareWithDefault("contentType",t.contentType)&&Ee.compareWithDefault("contentEncryptionAlgorithm",t.contentEncryptionAlgorithm)&&Ee.compareWithDefault("encryptedContent",t.encryptedContent);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||u}),new w({name:t.originatorInfo||u,optional:!0,idBlock:{tagClass:3,tagNumber:0},value:zi.schema().valueBlock.value}),new pe({value:[new J({name:t.recipientInfos||u,value:At.schema()})]}),Ee.schema(t.encryptedContentInfo||{}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.unprotectedAttrs||u,value:le.schema()})]})]})}fromSchema(e){C(e,Cv);const t=N(e,e,Bt.schema({names:{version:ta,originatorInfo:on,recipientInfos:sa,encryptedContentInfo:{names:{blockName:na}},unprotectedAttrs:ln}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,on in t.result&&(this.originatorInfo=new zi({schema:new f({value:t.result.originatorInfo.valueBlock.value})})),this.recipientInfos=Array.from(t.result.recipientInfos,s=>new At({schema:s})),this.encryptedContentInfo=new Ee({schema:t.result.encryptedContentInfo}),ln in t.result&&(this.unprotectedAttrs=Array.from(t.result.unprotectedAttrs,s=>new le({schema:s})))}toSchema(){const e=[];return e.push(new S({value:this.version})),this.originatorInfo&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:this.originatorInfo.toSchema().valueBlock.value})),e.push(new pe({value:Array.from(this.recipientInfos,t=>t.toSchema())})),e.push(this.encryptedContentInfo.toSchema()),this.unprotectedAttrs&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:Array.from(this.unprotectedAttrs,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={version:this.version,recipientInfos:Array.from(this.recipientInfos,t=>t.toJSON()),encryptedContentInfo:this.encryptedContentInfo.toJSON()};return this.originatorInfo&&(e.originatorInfo=this.originatorInfo.toJSON()),this.unprotectedAttrs&&(e.unprotectedAttrs=Array.from(this.unprotectedAttrs,t=>t.toJSON())),e}addRecipientByCertificate(e,t,s,n=q(!0)){const i=Object.assign({useOAEP:!0,oaepHashAlgorithm:"SHA-512"},gd,t||{});if(e.subjectPublicKeyInfo.algorithm.algorithmId.indexOf("1.2.840.113549")!==-1)s=1;else if(e.subjectPublicKeyInfo.algorithm.algorithmId.indexOf("1.2.840.10045")!==-1)s=2;else throw new Error(`Unknown type of certificate's public key: ${e.subjectPublicKeyInfo.algorithm.algorithmId}`);switch(s){case 1:{let o,l;if(i.useOAEP===!0){o=n.getOIDByAlgorithm({name:"RSA-OAEP"},!0,"keyEncryptionAlgorithm");const h=n.getOIDByAlgorithm({name:i.oaepHashAlgorithm},!0,"RSAES-OAEP-params"),m=new v({algorithmId:h,algorithmParams:new Ae});l=new Ge({hashAlgorithm:m,maskGenAlgorithm:new v({algorithmId:"1.2.840.113549.1.1.8",algorithmParams:m.toSchema()})}).toSchema()}else{if(o=n.getOIDByAlgorithm({name:"RSAES-PKCS1-v1_5"}),o===u)throw new Error("Can not find OID for RSAES-PKCS1-v1_5");l=new Ae}const c=new rt({version:0,rid:new Be({issuer:e.issuer,serialNumber:e.serialNumber}),keyEncryptionAlgorithm:new v({algorithmId:o,algorithmParams:l}),recipientCertificate:e});this.recipientInfos.push(new At({variant:1,value:c}))}break;case 2:{const o=new jt({variant:1,value:new Be({issuer:e.issuer,serialNumber:e.serialNumber})});this._addKeyAgreeRecipientInfo(o,i,{recipientCertificate:e},n)}break;default:throw new Error(`Unknown "variant" value: ${s}`)}return!0}addRecipientByPreDefinedData(e,t={},s,n=q(!0)){if(ie.assert(e,"preDefinedData","ArrayBuffer"),!e.byteLength)throw new Error("Pre-defined data could have zero length");if(!t.keyIdentifier){const i=new ArrayBuffer(16),o=new Uint8Array(i);n.getRandomValues(o),t.keyIdentifier=i}switch(t.hmacHashAlgorithm||(t.hmacHashAlgorithm="SHA-512"),t.iterationCount===void 0&&(t.iterationCount=2048),t.keyEncryptionAlgorithm||(t.keyEncryptionAlgorithm={name:"AES-KW",length:256}),t.keyEncryptionAlgorithmParams||(t.keyEncryptionAlgorithmParams=new Ae),s){case 1:{const i=n.getOIDByAlgorithm(t.keyEncryptionAlgorithm,!0,"keyEncryptionAlgorithm"),o=new at({version:4,kekid:new Vt({keyIdentifier:new I({valueHex:t.keyIdentifier})}),keyEncryptionAlgorithm:new v({algorithmId:i,algorithmParams:t.keyEncryptionAlgorithmParams}),preDefinedKEK:e});this.recipientInfos.push(new At({variant:3,value:o}))}break;case 2:{const i=n.getOIDByAlgorithm({name:"PBKDF2"},!0,"keyDerivationAlgorithm"),o=new ArrayBuffer(64),l=new Uint8Array(o);n.getRandomValues(l);const c=n.getOIDByAlgorithm({name:"HMAC",hash:{name:t.hmacHashAlgorithm}},!0,"hmacHashAlgorithm"),h=new Je({salt:new I({valueHex:o}),iterationCount:t.iterationCount,prf:new v({algorithmId:c,algorithmParams:new Ae})}),m=n.getOIDByAlgorithm(t.keyEncryptionAlgorithm,!0,"keyEncryptionAlgorithm"),g=new vt({version:0,keyDerivationAlgorithm:new v({algorithmId:i,algorithmParams:h.toSchema()}),keyEncryptionAlgorithm:new v({algorithmId:m,algorithmParams:t.keyEncryptionAlgorithmParams}),password:e});this.recipientInfos.push(new At({variant:4,value:g}))}break;default:throw new Error(`Unknown value for "variant": ${s}`)}}addRecipientByKeyIdentifier(e,t,s,n=q(!0)){const i=Object.assign({},gd,s||{}),o=new jt({variant:2,value:new $t({subjectKeyIdentifier:new I({valueHex:t})})});this._addKeyAgreeRecipientInfo(o,i,{recipientPublicKey:e},n)}_addKeyAgreeRecipientInfo(e,t,s,n=q(!0)){const i=new ms({rid:e}),o=n.getOIDByAlgorithm({name:"AES-KW",length:t.kekEncryptionLength},!0,"keyEncryptionAlgorithm"),l=new v({algorithmId:o}),c=n.getOIDByAlgorithm({name:"ECDH",kdf:t.kdfAlgorithm},!0,"KeyAgreeRecipientInfo"),h=new ArrayBuffer(64),m=new Uint8Array(h);n.getRandomValues(m);const g={version:3,ukm:new I({valueHex:h}),keyEncryptionAlgorithm:new v({algorithmId:c,algorithmParams:l.toSchema()}),recipientEncryptedKeys:new On({encryptedKeys:[i]})},d=new tt(Object.assign(g,s));this.recipientInfos.push(new At({variant:2,value:d}))}async encrypt(e,t,s=q(!0)){const n=new ArrayBuffer(16),i=new Uint8Array(n);s.getRandomValues(i);const o=new Uint8Array(t),l=s.getOIDByAlgorithm(e,!0,"contentEncryptionAlgorithm"),c=await s.generateKey(e,!0,["encrypt"]),h=await s.encrypt({name:e.name,iv:i},c,o),m=await s.exportKey("raw",c);this.version=2,this.encryptedContentInfo=new Ee({disableSplit:this.policy.disableSplit,contentType:"1.2.840.113549.1.7.1",contentEncryptionAlgorithm:new v({algorithmId:l,algorithmParams:new I({valueHex:n})}),encryptedContent:new I({valueHex:h})});const g=async y=>{const O=this.recipientInfos[y].value;let x,B;if(O.recipientPublicKey)x=O.recipientPublicKey.algorithm.namedCurve,B=O.recipientPublicKey;else if(O.recipientCertificate){const P=O.recipientCertificate.subjectPublicKeyInfo.algorithm.algorithmParams;if(P.constructor.blockName()!==T.blockName())throw new Error(`Incorrect "recipientCertificate" for index ${y}`);switch(P.valueBlock.toString()){case"1.2.840.10045.3.1.7":x="P-256";break;case"1.3.132.0.34":x="P-384";break;case"1.3.132.0.35":x="P-521";break;default:throw new Error(`Incorrect curve OID for index ${y}`)}B=await O.recipientCertificate.getPublicKey({algorithm:{algorithm:{name:"ECDH",namedCurve:x},usages:[]}},s)}else throw new Error("Unsupported RecipientInfo");const V=Bv[x],R=await s.generateKey({name:"ECDH",namedCurve:x},!0,["deriveBits"]),$=await s.exportKey("spki",R.publicKey),te=await s.deriveBits({name:"ECDH",public:B},R.privateKey,V),j=new v({schema:O.keyEncryptionAlgorithm.algorithmParams}),Z=s.getAlgorithmByOID(j.algorithmId,!0,"aesKWAlgorithm");let ye=Z.length;const se=new ArrayBuffer(4),ae=new Uint8Array(se);for(let P=3;P>=0;P--)ae[P]=ye,ye>>=8;const _e=new ls({keyInfo:new v({algorithmId:j.algorithmId}),entityUInfo:O.ukm,suppPubInfo:new I({valueHex:se})}).toSchema().toBER(!1),fe=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"ecdhAlgorithm"),ze=await sd(fe.kdf,te,Z.length,_e,s),et=await s.importKey("raw",ze,{name:"AES-KW"},!0,["wrapKey"]),mt=await s.wrapKey("raw",c,et,{name:"AES-KW"}),we=new vs;return we.variant=3,we.value=ds.fromBER($),O.originator=we,O.recipientEncryptedKeys.encryptedKeys[0].encryptedKey=new I({valueHex:mt}),{ecdhPrivateKey:R.privateKey}},d=async y=>{const O=this.recipientInfos[y].value,x=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"keyEncryptionAlgorithm");if(x.name==="RSA-OAEP"){const B=O.keyEncryptionAlgorithm.algorithmParams,V=new Ge({schema:B});if(x.hash=s.getAlgorithmByOID(V.hashAlgorithm.algorithmId),!("name"in x.hash))throw new Error(`Incorrect OID for hash algorithm: ${V.hashAlgorithm.algorithmId}`)}try{const B=await O.recipientCertificate.getPublicKey({algorithm:{algorithm:x,usages:["encrypt","wrapKey"]}},s),V=await s.encrypt(B.algorithm,B,m);O.encryptedKey=new I({valueHex:V})}catch{}},b=async y=>{const O=this.recipientInfos[y].value,x=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"kekAlgorithm"),B=await s.importKey("raw",new Uint8Array(O.preDefinedKEK),x,!0,["wrapKey"]),V=await s.wrapKey("raw",c,B,x);O.encryptedKey=new I({valueHex:V})},A=async y=>{const O=this.recipientInfos[y].value;let x;if(!O.keyDerivationAlgorithm)throw new Error('Please append encoded "keyDerivationAlgorithm"');if(!O.keyDerivationAlgorithm.algorithmParams)throw new Error('Incorrectly encoded "keyDerivationAlgorithm"');try{x=new Je({schema:O.keyDerivationAlgorithm.algorithmParams})}catch{throw new Error('Incorrectly encoded "keyDerivationAlgorithm"')}const B=new Uint8Array(O.password),V=await s.importKey("raw",B,"PBKDF2",!1,["deriveKey"]),R=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"kekAlgorithm");let $="SHA-1";x.prf&&($=s.getAlgorithmByOID(x.prf.algorithmId,!0,"prfAlgorithm").hash.name);const te=new Uint8Array(x.salt.valueBlock.valueHex),j=x.iterationCount,Z=await s.deriveKey({name:"PBKDF2",hash:{name:$},salt:te,iterations:j},V,R,!0,["wrapKey"]),ye=await s.wrapKey("raw",c,Z,R);O.encryptedKey=new I({valueHex:ye})},E=[];for(let y=0;ythis.recipientInfos.length)throw new Error(`Maximum value for "index" is: ${this.recipientInfos.length-1}`);const i=async E=>{const y=this.recipientInfos[E].value;let O,x,B;const V=y.originator;if(n.recipientCertificate){const fe=n.recipientCertificate.subjectPublicKeyInfo.algorithm.algorithmParams;if(fe.constructor.blockName()!==T.blockName())throw new Error(`Incorrect "recipientCertificate" for index ${E}`);O=fe.valueBlock.toString()}else if(V.value.algorithm.algorithmParams){const fe=V.value.algorithm.algorithmParams;if(fe.constructor.blockName()!==T.blockName())throw new Error(`Incorrect originator for index ${E}`);O=fe.valueBlock.toString()}else throw new Error('Parameter "recipientCertificate" is mandatory for "KeyAgreeRecipientInfo" if algorithm params are missing from originator');if(!n.recipientPrivateKey)throw new Error('Parameter "recipientPrivateKey" is mandatory for "KeyAgreeRecipientInfo"');switch(O){case"1.2.840.10045.3.1.7":x="P-256",B=256;break;case"1.3.132.0.34":x="P-384",B=384;break;case"1.3.132.0.35":x="P-521",B=528;break;default:throw new Error(`Incorrect curve OID for index ${E}`)}let R,$=s;L.isBufferSource(n.recipientPrivateKey)?R=await s.importKey("pkcs8",n.recipientPrivateKey,{name:"ECDH",namedCurve:x},!0,["deriveBits"]):(R=n.recipientPrivateKey,"crypto"in n&&n.crypto&&($=n.crypto.subtle)),"algorithmParams"in V.value.algorithm||(V.value.algorithm.algorithmParams=new T({value:O}));const te=V.value.toSchema().toBER(!1),j=await s.importKey("spki",te,{name:"ECDH",namedCurve:x},!0,[]),Z=await $.deriveBits({name:"ECDH",public:j},R,B);async function ye(fe){fe=fe||!1;const ze=new v({schema:y.keyEncryptionAlgorithm.algorithmParams}),et=s.getAlgorithmByOID(ze.algorithmId,!0,"kwAlgorithm");let mt=et.length;const we=new ArrayBuffer(4),P=new Uint8Array(we);for(let Te=3;Te>=0;Te--)P[Te]=mt,mt>>=8;const F={algorithmId:ze.algorithmId};fe&&(F.algorithmParams=new Ae);const Y=new ls({keyInfo:new v(F),entityUInfo:y.ukm,suppPubInfo:new I({valueHex:we})}).toSchema().toBER(!1),ne=s.getAlgorithmByOID(y.keyEncryptionAlgorithm.algorithmId,!0,"ecdhAlgorithm");if(!ne.name)throw new Error(`Incorrect OID for key encryption algorithm: ${y.keyEncryptionAlgorithm.algorithmId}`);return sd(ne.kdf,Z,et.length,Y,s)}const se=await ye(),ae=async fe=>s.importKey("raw",fe,{name:"AES-KW"},!0,["unwrapKey"]),Wt=await ae(se),_e=async fe=>{const ze=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,et=s.getAlgorithmByOID(ze,!0,"contentEncryptionAlgorithm");return s.unwrapKey("raw",y.recipientEncryptedKeys.encryptedKeys[0].encryptedKey.valueBlock.valueHexView,fe,{name:"AES-KW"},et,!0,["decrypt"])};try{return await _e(Wt)}catch{const fe=await ye(!0),ze=await ae(fe);return _e(ze)}},o=async E=>{const y=this.recipientInfos[E].value;if(!n.recipientPrivateKey)throw new Error('Parameter "recipientPrivateKey" is mandatory for "KeyTransRecipientInfo"');const O=s.getAlgorithmByOID(y.keyEncryptionAlgorithm.algorithmId,!0,"keyEncryptionAlgorithm");if(O.name==="RSA-OAEP"){const te=y.keyEncryptionAlgorithm.algorithmParams,j=new Ge({schema:te});if(O.hash=s.getAlgorithmByOID(j.hashAlgorithm.algorithmId),!("name"in O.hash))throw new Error(`Incorrect OID for hash algorithm: ${j.hashAlgorithm.algorithmId}`)}let x,B=s;L.isBufferSource(n.recipientPrivateKey)?x=await s.importKey("pkcs8",n.recipientPrivateKey,O,!0,["decrypt"]):(x=n.recipientPrivateKey,"crypto"in n&&n.crypto&&(B=n.crypto.subtle));const V=await B.decrypt(x.algorithm,x,y.encryptedKey.valueBlock.valueHexView),R=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,$=s.getAlgorithmByOID(R,!0,"contentEncryptionAlgorithm");if(!("name"in $))throw new Error(`Incorrect "contentEncryptionAlgorithm": ${R}`);return s.importKey("raw",V,$,!0,["decrypt"])},l=async E=>{const y=this.recipientInfos[E].value;if(!n.preDefinedData)throw new Error('Parameter "preDefinedData" is mandatory for "KEKRecipientInfo"');const O=s.getAlgorithmByOID(y.keyEncryptionAlgorithm.algorithmId,!0,"kekAlgorithm"),x=await s.importKey("raw",n.preDefinedData,O,!0,["unwrapKey"]),B=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,V=s.getAlgorithmByOID(B,!0,"contentEncryptionAlgorithm");if(!V.name)throw new Error(`Incorrect "contentEncryptionAlgorithm": ${B}`);return s.unwrapKey("raw",y.encryptedKey.valueBlock.valueHexView,x,O,V,!0,["decrypt"])},c=async E=>{const y=this.recipientInfos[E].value;let O;if(!n.preDefinedData)throw new Error('Parameter "preDefinedData" is mandatory for "KEKRecipientInfo"');if(!y.keyDerivationAlgorithm)throw new Error('Please append encoded "keyDerivationAlgorithm"');if(!y.keyDerivationAlgorithm.algorithmParams)throw new Error('Incorrectly encoded "keyDerivationAlgorithm"');try{O=new Je({schema:y.keyDerivationAlgorithm.algorithmParams})}catch{throw new Error('Incorrectly encoded "keyDerivationAlgorithm"')}const x=await s.importKey("raw",n.preDefinedData,"PBKDF2",!1,["deriveKey"]),B=s.getAlgorithmByOID(y.keyEncryptionAlgorithm.algorithmId,!0,"keyEncryptionAlgorithm"),V=O.prf?s.getAlgorithmByOID(O.prf.algorithmId,!0,"prfAlgorithm").hash.name:"SHA-1",R=new Uint8Array(O.salt.valueBlock.valueHex),$=O.iterationCount,te=await s.deriveKey({name:"PBKDF2",hash:{name:V},salt:R,iterations:$},x,B,!0,["unwrapKey"]),j=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,Z=s.getAlgorithmByOID(j,!0,"contentEncryptionAlgorithm");return s.unwrapKey("raw",y.encryptedKey.valueBlock.valueHexView,te,B,Z,!0,["decrypt"])};let h;switch(this.recipientInfos[e].variant){case 1:h=await o(e);break;case 2:h=await i(e);break;case 3:h=await l(e);break;case 4:h=await c(e);break;default:throw new Error(`Unknown recipient type in array with index ${e}`)}const m=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,g=s.getAlgorithmByOID(m,!0,"contentEncryptionAlgorithm"),d=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmParams.valueBlock.valueHex,b=new Uint8Array(d);if(!this.encryptedContentInfo.encryptedContent)throw new Error("Required property `encryptedContent` is empty");const A=this.encryptedContentInfo.getEncryptedContent();return s.decrypt({name:g.name,iv:b},h,A)}}Bt.CLASS_NAME="EnvelopedData";const ur="safeContents",ho="parsedValue",wd="contentInfos";class er extends k{constructor(e={}){super(),this.safeContents=a(e,ur,er.defaultValues(ur)),ho in e&&(this.parsedValue=a(e,ho,er.defaultValues(ho))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ur:return[];case ho:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ur:return t.length===0;case ho:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new J({name:t.contentInfos||u,value:oe.schema()})]})}fromSchema(e){C(e,[wd]);const t=N(e,e,er.schema({names:{contentInfos:wd}}));p.assertSchema(t,this.className),this.safeContents=Array.from(t.result.contentInfos,s=>new oe({schema:s}))}toSchema(){return new f({value:Array.from(this.safeContents,e=>e.toSchema())})}toJSON(){return{safeContents:Array.from(this.safeContents,e=>e.toJSON())}}async parseInternalValues(e,t=q(!0)){if(Q.assert(e,ur),ie.assert(e.safeContents,ur,"Array"),e.safeContents.length!==this.safeContents.length)throw new ie('Length of "parameters.safeContents" must be equal to "this.safeContents.length"');this.parsedValue={safeContents:[]};for(const[s,n]of this.safeContents.entries()){const i=e.safeContents[s],o=`parameters.safeContents[${s}]`;switch(n.contentType){case Cf:{ie.assert(n.content,"this.safeContents[j].content",I);const l=n.content.getValue();this.parsedValue.safeContents.push({privacyMode:0,value:fs.fromBER(l)})}break;case Xm:{const l=new Bt({schema:n.content});Q.assert(o,i,"recipientCertificate","recipientKey");const c=i,h=c.recipientCertificate,m=c.recipientKey,g=await l.decrypt(0,{recipientCertificate:h,recipientPrivateKey:m},t);this.parsedValue.safeContents.push({privacyMode:2,value:fs.fromBER(g)})}break;case Zm:{const l=new Kt({schema:n.content});Q.assert(o,i,"password");const c=i.password,h=await l.decrypt({password:c},t);this.parsedValue.safeContents.push({privacyMode:1,value:fs.fromBER(h)})}break;default:throw new Error(`Unknown "contentType" for AuthenticatedSafe: " ${n.contentType}`)}}}async makeInternalValues(e,t=q(!0)){if(!this.parsedValue)throw new Error('Please run "parseValues" first or add "parsedValue" manually');if(ie.assert(this.parsedValue,"this.parsedValue","object"),ie.assert(this.parsedValue.safeContents,"this.parsedValue.safeContents","Array"),ie.assert(e,"parameters","object"),Q.assert(e,"safeContents"),ie.assert(e.safeContents,"parameters.safeContents","Array"),e.safeContents.length!==this.parsedValue.safeContents.length)throw new ie('Length of "parameters.safeContents" must be equal to "this.parsedValue.safeContents"');this.safeContents=[];for(const[s,n]of this.parsedValue.safeContents.entries())switch(Q.assert("content",n,"privacyMode","value"),ie.assert(n.value,"content.value",fs),n.privacyMode){case 0:{const i=n.value.toSchema().toBER(!1);this.safeContents.push(new oe({contentType:"1.2.840.113549.1.7.1",content:new I({valueHex:i})}))}break;case 1:{const i=new Kt,o=e.safeContents[s];o.contentToEncrypt=n.value.toSchema().toBER(!1),await i.encrypt(o,t),this.safeContents.push(new oe({contentType:"1.2.840.113549.1.7.6",content:i.toSchema()}))}break;case 2:{const i=new Bt,o=n.value.toSchema().toBER(!1),l=e.safeContents[s];switch(Q.assert(`parameters.safeContents[${s}]`,l,"encryptingCertificate","encryptionAlgorithm"),!0){case l.encryptionAlgorithm.name.toLowerCase()==="aes-cbc":case l.encryptionAlgorithm.name.toLowerCase()==="aes-gcm":break;default:throw new Error(`Incorrect parameter "encryptionAlgorithm" in "parameters.safeContents[i]": ${l.encryptionAlgorithm}`)}switch(!0){case l.encryptionAlgorithm.length===128:case l.encryptionAlgorithm.length===192:case l.encryptionAlgorithm.length===256:break;default:throw new Error(`Incorrect parameter "encryptionAlgorithm.length" in "parameters.safeContents[i]": ${l.encryptionAlgorithm.length}`)}const c=l.encryptionAlgorithm;i.addRecipientByCertificate(l.encryptingCertificate,{},void 0,t),await i.encrypt(c,o,t),this.safeContents.push(new oe({contentType:"1.2.840.113549.1.7.3",content:i.toSchema()}))}break;default:throw new Error(`Incorrect value for "content.privacyMode": ${n.privacyMode}`)}return this}}er.CLASS_NAME="AuthenticatedSafe";const Ni="hashAlgorithm",ia="issuerNameHash",ra="issuerKeyHash",Ci="serialNumber",Iv=[Ni,ia,ra,Ci];class Ne extends k{static async create(e,t,s=q(!0)){const n=new Ne;return await n.createForCertificate(e,t,s),n}constructor(e={}){super(),this.hashAlgorithm=a(e,Ni,Ne.defaultValues(Ni)),this.issuerNameHash=a(e,ia,Ne.defaultValues(ia)),this.issuerKeyHash=a(e,ra,Ne.defaultValues(ra)),this.serialNumber=a(e,Ci,Ne.defaultValues(Ci)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ni:return new v;case ia:case ra:return new I;case Ci:return new S;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ni:return t.algorithmId===u&&!("algorithmParams"in t);case ia:case ra:case Ci:return t.isEqual(Ne.defaultValues(Ci));default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[v.schema(t.hashAlgorithmObject||{names:{blockName:t.hashAlgorithm||u}}),new I({name:t.issuerNameHash||u}),new I({name:t.issuerKeyHash||u}),new S({name:t.serialNumber||u})]})}fromSchema(e){C(e,Iv);const t=N(e,e,Ne.schema({names:{hashAlgorithm:Ni,issuerNameHash:ia,issuerKeyHash:ra,serialNumber:Ci}}));p.assertSchema(t,this.className),this.hashAlgorithm=new v({schema:t.result.hashAlgorithm}),this.issuerNameHash=t.result.issuerNameHash,this.issuerKeyHash=t.result.issuerKeyHash,this.serialNumber=t.result.serialNumber}toSchema(){return new f({value:[this.hashAlgorithm.toSchema(),this.issuerNameHash,this.issuerKeyHash,this.serialNumber]})}toJSON(){return{hashAlgorithm:this.hashAlgorithm.toJSON(),issuerNameHash:this.issuerNameHash.toJSON(),issuerKeyHash:this.issuerKeyHash.toJSON(),serialNumber:this.serialNumber.toJSON()}}isEqual(e){return!(this.hashAlgorithm.algorithmId!==e.hashAlgorithm.algorithmId||!L.isEqual(this.issuerNameHash.valueBlock.valueHexView,e.issuerNameHash.valueBlock.valueHexView)||!L.isEqual(this.issuerKeyHash.valueBlock.valueHexView,e.issuerKeyHash.valueBlock.valueHexView)||!this.serialNumber.isEqual(e.serialNumber))}async createForCertificate(e,t,s=q(!0)){Q.assert(t,Ni,"issuerCertificate");const n=s.getOIDByAlgorithm({name:t.hashAlgorithm},!0,"hashAlgorithm");this.hashAlgorithm=new v({algorithmId:n,algorithmParams:new Ae});const i=t.issuerCertificate;this.serialNumber=e.serialNumber;const o=await s.digest({name:t.hashAlgorithm},i.subject.toSchema().toBER(!1));this.issuerNameHash=new I({valueHex:o});const l=i.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView,c=await s.digest({name:t.hashAlgorithm},l);this.issuerKeyHash=new I({valueHex:c})}}Ne.CLASS_NAME="CertID";const aa="certID",oa="certStatus",la="thisUpdate",cn="nextUpdate",Bi="singleExtensions",Vv=[aa,oa,la,cn,Bi];class It extends k{constructor(e={}){super(),this.certID=a(e,aa,It.defaultValues(aa)),this.certStatus=a(e,oa,It.defaultValues(oa)),this.thisUpdate=a(e,la,It.defaultValues(la)),cn in e&&(this.nextUpdate=a(e,cn,It.defaultValues(cn))),Bi in e&&(this.singleExtensions=a(e,Bi,It.defaultValues(Bi))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case aa:return new Ne;case oa:return{};case la:case cn:return new Date(0,0,0);case Bi:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case aa:return Ne.compareWithDefault("hashAlgorithm",t.hashAlgorithm)&&Ne.compareWithDefault("issuerNameHash",t.issuerNameHash)&&Ne.compareWithDefault("issuerKeyHash",t.issuerKeyHash)&&Ne.compareWithDefault("serialNumber",t.serialNumber);case oa:return Object.keys(t).length===0;case la:case cn:return t===It.defaultValues(e);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[Ne.schema(t.certID||{}),new he({value:[new _({name:t.certStatus||u,idBlock:{tagClass:3,tagNumber:0}}),new w({name:t.certStatus||u,idBlock:{tagClass:3,tagNumber:1},value:[new ue,new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new sr]})]}),new _({name:t.certStatus||u,idBlock:{tagClass:3,tagNumber:2},lenBlock:{length:1}})]}),new ue({name:t.thisUpdate||u}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new ue({name:t.nextUpdate||u})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[ke.schema(t.singleExtensions||{})]})]})}fromSchema(e){C(e,Vv);const t=N(e,e,It.schema({names:{certID:{names:{blockName:aa}},certStatus:oa,thisUpdate:la,nextUpdate:cn,singleExtensions:{names:{blockName:Bi}}}}));p.assertSchema(t,this.className),this.certID=new Ne({schema:t.result.certID}),this.certStatus=t.result.certStatus,this.thisUpdate=t.result.thisUpdate.toDate(),cn in t.result&&(this.nextUpdate=t.result.nextUpdate.toDate()),Bi in t.result&&(this.singleExtensions=Array.from(t.result.singleExtensions.valueBlock.value,s=>new Ve({schema:s})))}toSchema(){const e=[];return e.push(this.certID.toSchema()),e.push(this.certStatus),e.push(new ue({valueDate:this.thisUpdate})),this.nextUpdate&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[new ue({valueDate:this.nextUpdate})]})),this.singleExtensions&&e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[new f({value:Array.from(this.singleExtensions,t=>t.toSchema())})]})),new f({value:e})}toJSON(){const e={certID:this.certID.toJSON(),certStatus:this.certStatus.toJSON(),thisUpdate:this.thisUpdate};return this.nextUpdate&&(e.nextUpdate=this.nextUpdate),this.singleExtensions&&(e.singleExtensions=Array.from(this.singleExtensions,t=>t.toJSON())),e}}It.CLASS_NAME="SingleResponse";const Zc="tbs",Ii="version",ql="responderID",Wl="producedAt",Gl="responses",ca="responseExtensions",ir="ResponseData",hu=`${ir}.${Ii}`,ua=`${ir}.${ql}`,jh=`${ir}.${Wl}`,Fh=`${ir}.${Gl}`,fu=`${ir}.${ca}`,xv=[ir,hu,ua,jh,Fh,fu];class Re extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(a(e,Zc,Re.defaultValues(Zc))),Ii in e&&(this.version=a(e,Ii,Re.defaultValues(Ii))),this.responderID=a(e,ql,Re.defaultValues(ql)),this.producedAt=a(e,Wl,Re.defaultValues(Wl)),this.responses=a(e,Gl,Re.defaultValues(Gl)),ca in e&&(this.responseExtensions=a(e,ca,Re.defaultValues(ca))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ii:return 0;case Zc:return be;case ql:return{};case Wl:return new Date(0,0,0);case Gl:case ca:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Zc:return t.byteLength===0;case ql:return Object.keys(t).length===0;case Wl:return t===Re.defaultValues(e);case Gl:case ca:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||ir,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({name:t.version||hu})]}),new he({value:[new w({name:t.responderID||ua,idBlock:{tagClass:3,tagNumber:1},value:[re.schema(t.ResponseDataByName||{names:{blockName:"ResponseData.byName"}})]}),new w({name:t.responderID||ua,idBlock:{tagClass:3,tagNumber:2},value:[new I({name:t.ResponseDataByKey||"ResponseData.byKey"})]})]}),new ue({name:t.producedAt||jh}),new f({value:[new J({name:Fh,value:It.schema(t.response||{})})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[ke.schema(t.extensions||{names:{blockName:fu}})]})]})}fromSchema(e){C(e,xv);const t=N(e,e,Re.schema());p.assertSchema(t,this.className),this.tbsView=t.result.ResponseData.valueBeforeDecodeView,hu in t.result&&(this.version=t.result[hu].valueBlock.valueDec),t.result[ua].idBlock.tagNumber===1?this.responderID=new re({schema:t.result[ua].valueBlock.value[0]}):this.responderID=t.result[ua].valueBlock.value[0],this.producedAt=t.result[jh].toDate(),this.responses=Array.from(t.result[Fh],s=>new It({schema:s})),fu in t.result&&(this.responseExtensions=Array.from(t.result[fu].valueBlock.value,s=>new Ve({schema:s})))}toSchema(e=!1){let t;if(e===!1){if(!this.tbsView.byteLength)return Re.schema();const s=Oe(this.tbsView);p.assert(s,"TBS Response Data"),t=s.result}else{const s=[];Ii in this&&s.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[new S({value:this.version})]})),this.responderID instanceof re?s.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[this.responderID.toSchema()]})):s.push(new w({idBlock:{tagClass:3,tagNumber:2},value:[this.responderID]})),s.push(new ue({valueDate:this.producedAt})),s.push(new f({value:Array.from(this.responses,n=>n.toSchema())})),this.responseExtensions&&s.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[new f({value:Array.from(this.responseExtensions,n=>n.toSchema())})]})),t=new f({value:s})}return t}toJSON(){const e={};return Ii in this&&(e.version=this.version),this.responderID&&(e.responderID=this.responderID),this.producedAt&&(e.producedAt=this.producedAt),this.responses&&(e.responses=Array.from(this.responses,t=>t.toJSON())),this.responseExtensions&&(e.responseExtensions=Array.from(this.responseExtensions,t=>t.toJSON())),e}}Re.CLASS_NAME="ResponseData";const Nh="trustedCerts",Ch="certs",Bh="crls",Ih="ocsps",Vh="checkDate",xh="findOrigin",Oh="findIssuer";var Hi;(function(r){r[r.unknown=-1]="unknown",r[r.success=0]="success",r[r.noRevocation=11]="noRevocation",r[r.noPath=60]="noPath",r[r.noValidPath=97]="noValidPath"})(Hi||(Hi={}));class An extends Error{constructor(e,t){super(t),this.name=An.NAME,this.code=e,this.message=t}}An.NAME="ChainValidationError";function Ov(r,e){for(let t=0;t=0;h--)try{await e.verify(n[h],s)===!1&&n.splice(h,1)}catch{n.splice(h,1)}return n}defaultValues(e){switch(e){case Nh:return[];case Ch:return[];case Bh:return[];case Ih:return[];case Vh:return new Date;case xh:return eh.defaultFindOrigin;case Oh:return this.defaultFindIssuer;default:throw new Error(`Invalid member name for CertificateChainValidationEngine class: ${e}`)}}async sort(e=!1,t=q(!0)){const s=[],n=async(A,E)=>{const y=[];function O(B){let V=!0;for(let R=0;R{const E=[],y=[],O=[];if(E.push(...s.filter(x=>A.issuer.isEqual(x.subject))),E.length===0)return{status:1,statusMessage:"No certificate's issuers"};if(y.push(...this.crls.filter(x=>x.issuer.isEqual(A.issuer))),y.length===0)return{status:2,statusMessage:"No CRLs for specific certificate issuer"};for(let x=0;x{const y=t.getAlgorithmByOID(A.signatureAlgorithm.algorithmId);if(!y.name||!y.hash)return 1;for(let O=0;O{for(let y=0;yE||A[y].notAfter.value=0;y--)if(A[y].issuer.isEqual(A[y].subject)===!1&&A[y].issuer.isEqual(A[y+1].subject)===!1)return{result:!1,resultCode:10,resultMessage:"Incorrect name chaining"};if(this.crls.length!==0||this.ocsps.length!==0)for(let y=0;y=0;A--){let E=!1;for(let y=0;y1)return!1;if(d.length>1){for(let E=0;E0&&d[E].charAt(d[E].length-1)!==":"){m=d[E].split(":")[0];break}}if(s(m,g)){const E=m.split("."),y=g.split(".");return y[0].length===0?!0:E.length===y.length}return!1}function o(c,h){const m=c.valueBlock.valueHexView,g=h.valueBlock.valueHexView;if(m.length===4&&g.length===8){for(let d=0;d<4;d++)if((m[d]^g[d])&g[d+4])return!1;return!0}if(m.length===16&&g.length===32){for(let d=0;d<16;d++)if((m[d]^g[d])&g[d+16])return!1;return!0}return!1}function l(c,h){if(c.typesAndValues.length===0||h.typesAndValues.length===0)return!0;if(c.typesAndValues.length=0;P--,ye++){const F=this.certs[P];if(F.extensions){for(let U=0;UY.parsedValue.requireExplicitPolicy?Y.parsedValue.requireExplicitPolicy:V,Y.parsedValue.inhibitPolicyMapping===0?O=!0:B[1]===!1?(B[1]=!0,R=Y.parsedValue.inhibitPolicyMapping+1):R=R>Y.parsedValue.inhibitPolicyMapping+1?Y.parsedValue.inhibitPolicyMapping+1:R),Y.extnID===jw&&x===!1&&(Y.parsedValue.valueBlock.valueDec===0?x=!0:B[2]===!1?(B[2]=!0,$=Y.parsedValue.valueBlock.valueDec):$=$>Y.parsedValue.valueBlock.valueDec?Y.parsedValue.valueBlock.valueDec:$)}if(x===!0){let U=-1;for(let Y=0;Y1){F=!1;break}if(typeof ae[P][U]>"u"){if(U>=ze){for(let ne=0;ne0,resultCode:0,resultMessage:mt.length>0?u:'Zero "userConstrPolicies" array, no intersections with "authConstrPolicies"',authConstrPolicies:et,userConstrPolicies:mt,explicitPolicyIndicator:y,policyMappings:_e,certificatePath:this.certs};if(mt.length===0||we.result===!1)return we;ye=1;for(let P=this.certs.length-2;P>=0;P--,ye++){const F=this.certs[P];let U=[],Y=[],ne=[];if(F.extensions)for(let z=0;z0)for(let ce=0;ce0)for(let ce=0;ce0)for(let ce=0;ce0)for(let ce=0;ce0&&Tn)throw we.result=!1,we.resultCode=41,we.resultMessage='Failed to meet "permitted sub-trees" name constraint',we}let ve=!1;for(let z=0;z=0)for(let M=0;M0)for(let M=0;M0)for(let M=0;M0)for(let M=0;Mnew ee({schema:s})))}toSchema(){const e=[];return e.push(this.tbsResponseData.toSchema()),e.push(this.signatureAlgorithm.toSchema()),e.push(this.signature),this.certs&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[new f({value:Array.from(this.certs,t=>t.toSchema())})]})),new f({value:e})}toJSON(){const e={tbsResponseData:this.tbsResponseData.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signature:this.signature.toJSON()};return this.certs&&(e.certs=Array.from(this.certs,t=>t.toJSON())),e}async getCertificateStatus(e,t,s=q(!0)){const n={isForCertificate:!1,status:2},i={},o=[];for(const l of this.tbsResponseData.responses){const c=s.getAlgorithmByOID(l.certID.hashAlgorithm.algorithmId,!0,"CertID.hashAlgorithm");if(!i[c.name]){i[c.name]=1;const h=new Ne;o.push(h),await h.createForCertificate(e,{hashAlgorithm:c.name,issuerCertificate:t},s)}}for(const l of this.tbsResponseData.responses)for(const c of o)if(l.certID.isEqual(c)){n.isForCertificate=!0;try{switch(l.certStatus.idBlock.isConstructed){case!0:l.certStatus.idBlock.tagNumber===1&&(n.status=1);break;case!1:switch(l.certStatus.idBlock.tagNumber){case 0:n.status=0;break;case 2:n.status=2;break;default:}break;default:}}catch{}return n}return n}async sign(e,t="SHA-1",s=q(!0)){if(!e)throw new Error("Need to provide a private key for signing");const n=await s.getSignatureParameters(e,t),i=n.parameters.algorithm;if(!("name"in i))throw new Error("Empty algorithm");this.signatureAlgorithm=n.signatureAlgorithm,this.tbsResponseData.tbsView=new Uint8Array(this.tbsResponseData.toSchema(!0).toBER());const o=await s.signWithPrivateKey(this.tbsResponseData.tbsView,e,{algorithm:i});this.signature=new W({valueHex:o})}async verify(e={},t=q(!0)){let s=null,n=-1;const i=e.trustedCerts||[];if(!this.certs)throw new Error("No certificates attached to the BasicOCSPResponse");switch(!0){case this.tbsResponseData.responderID instanceof re:for(const[h,m]of this.certs.entries())if(m.subject.isEqual(this.tbsResponseData.responderID)){n=h;break}break;case this.tbsResponseData.responderID instanceof I:for(const[h,m]of this.certs.entries()){const g=await t.digest({name:"sha-1"},m.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView);if(ja(g,this.tbsResponseData.responderID.valueBlock.valueHex)){n=h;break}}break;default:throw new Error("Wrong value for responderID")}if(n===-1)throw new Error("Correct certificate was not found in OCSP response");s=this.certs[n];const o=[s];for(const h of this.certs){const m=await ig(h,s);m&&o.push(m)}if(!(await new eh({certs:o,trustedCerts:i}).verify({},t)).result)throw new Error("Validation of signer's certificate failed");return t.verifyWithPublicKey(this.tbsResponseData.tbsView,this.signature,this.certs[n].subjectPublicKeyInfo,this.signatureAlgorithm)}}pt.CLASS_NAME="BasicOCSPResponse";const Rh="tbs",Th="version",Dh="subject",Ph="subjectPublicKeyInfo",hr="attributes",Xl="signatureAlgorithm",Zl="signatureValue",Xa="CertificationRequestInfo",Df=`${Xa}.version`,Pf=`${Xa}.subject`,Lf=`${Xa}.subjectPublicKeyInfo`,Wu=`${Xa}.attributes`,Tv=[Xa,Df,Pf,Lf,Wu,Xl,Zl];function Dv(r={}){const e=a(r,"names",{});return new f({name:e.CertificationRequestInfo||Xa,value:[new S({name:e.CertificationRequestInfoVersion||Df}),re.schema(e.subject||{names:{blockName:Pf}}),je.schema({names:{blockName:Lf}}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({optional:!0,name:e.CertificationRequestInfoAttributes||Wu,value:le.schema(e.attributes||{})})]})]})}class wt extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(a(e,Rh,wt.defaultValues(Rh))),this.version=a(e,Th,wt.defaultValues(Th)),this.subject=a(e,Dh,wt.defaultValues(Dh)),this.subjectPublicKeyInfo=a(e,Ph,wt.defaultValues(Ph)),hr in e&&(this.attributes=a(e,hr,wt.defaultValues(hr))),this.signatureAlgorithm=a(e,Xl,wt.defaultValues(Xl)),this.signatureValue=a(e,Zl,wt.defaultValues(Zl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Rh:return be;case Th:return 0;case Dh:return new re;case Ph:return new je;case hr:return[];case Xl:return new v;case Zl:return new W;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({value:[Dv(t.certificationRequestInfo||{}),new f({name:t.signatureAlgorithm||Xl,value:[new T,new K({optional:!0})]}),new W({name:t.signatureValue||Zl})]})}fromSchema(e){C(e,Tv);const t=N(e,e,wt.schema());p.assertSchema(t,this.className),this.tbsView=t.result.CertificationRequestInfo.valueBeforeDecodeView,this.version=t.result[Df].valueBlock.valueDec,this.subject=new re({schema:t.result[Pf]}),this.subjectPublicKeyInfo=new je({schema:t.result[Lf]}),Wu in t.result&&(this.attributes=Array.from(t.result[Wu],s=>new le({schema:s}))),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}encodeTBS(){const e=[new S({value:this.version}),this.subject.toSchema(),this.subjectPublicKeyInfo.toSchema()];return hr in this&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.attributes||[],t=>t.toSchema())})),new f({value:e})}toSchema(e=!1){let t;if(e===!1){if(this.tbsView.byteLength===0)return wt.schema();const s=Oe(this.tbsView);p.assert(s,"PKCS#10 Certificate Request"),t=s.result}else t=this.encodeTBS();return new f({value:[t,this.signatureAlgorithm.toSchema(),this.signatureValue]})}toJSON(){const e={tbs:H.ToHex(this.tbsView),version:this.version,subject:this.subject.toJSON(),subjectPublicKeyInfo:this.subjectPublicKeyInfo.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signatureValue:this.signatureValue.toJSON()};return hr in this&&(e.attributes=Array.from(this.attributes||[],t=>t.toJSON())),e}async sign(e,t="SHA-1",s=q(!0)){if(!e)throw new Error("Need to provide a private key for signing");const n=await s.getSignatureParameters(e,t),i=n.parameters;this.signatureAlgorithm=n.signatureAlgorithm,this.tbsView=new Uint8Array(this.encodeTBS().toBER());const o=await s.signWithPrivateKey(this.tbsView,e,i);this.signatureValue=new W({valueHex:o})}async verify(e=q(!0)){return e.verifyWithPublicKey(this.tbsView,this.signatureValue,this.subjectPublicKeyInfo,this.signatureAlgorithm)}async getPublicKey(e,t=q(!0)){return t.getPublicKey(this.subjectPublicKeyInfo,this.signatureAlgorithm,e)}}wt.CLASS_NAME="CertificationRequest";const Vi="digestAlgorithm",xi="digest",Pv=[Vi,xi];class kt extends k{constructor(e={}){super(),this.digestAlgorithm=a(e,Vi,kt.defaultValues(Vi)),this.digest=a(e,xi,kt.defaultValues(xi)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Vi:return new v;case xi:return new I;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Vi:return v.compareWithDefault("algorithmId",t.algorithmId)&&!("algorithmParams"in t);case xi:return t.isEqual(kt.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[v.schema(t.digestAlgorithm||{names:{blockName:Vi}}),new I({name:t.digest||xi})]})}fromSchema(e){C(e,Pv);const t=N(e,e,kt.schema({names:{digestAlgorithm:{names:{blockName:Vi}},digest:xi}}));p.assertSchema(t,this.className),this.digestAlgorithm=new v({schema:t.result.digestAlgorithm}),this.digest=t.result.digest}toSchema(){return new f({value:[this.digestAlgorithm.toSchema(),this.digest]})}toJSON(){return{digestAlgorithm:this.digestAlgorithm.toJSON(),digest:this.digest.toJSON()}}}kt.CLASS_NAME="DigestInfo";const fa="eContentType",Ct="eContent",Lv=[fa,Ct];class nt extends k{constructor(e={}){if(super(),this.eContentType=a(e,fa,nt.defaultValues(fa)),Ct in e&&(this.eContent=a(e,Ct,nt.defaultValues(Ct)),this.eContent.idBlock.tagClass===1&&this.eContent.idBlock.tagNumber===4&&this.eContent.idBlock.isConstructed===!1)){const t=new I({idBlock:{isConstructed:!0},isConstructed:!0});let s=0;const n=this.eContent.valueBlock.valueHexView.slice().buffer;let i=n.byteLength;for(;i>0;){const o=new Uint8Array(n,s,s+65536>n.byteLength?n.byteLength-s:65536),l=new ArrayBuffer(o.length),c=new Uint8Array(l);for(let h=0;hnew Ve({schema:s})))}toSchema(){const e=[];return e.push(this.reqCert.toSchema()),this.singleRequestExtensions&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new f({value:Array.from(this.singleRequestExtensions,t=>t.toSchema())})]})),new f({value:e})}toJSON(){const e={reqCert:this.reqCert.toJSON()};return this.singleRequestExtensions&&(e.singleRequestExtensions=Array.from(this.singleRequestExtensions,t=>t.toJSON())),e}}gs.CLASS_NAME="Request";const zc="tbs",ma="version",ga="requestorName",eu="requestList",wa="requestExtensions",Za="TBSRequest",gu=`${Za}.${ma}`,wu=`${Za}.${ga}`,Yh=`${Za}.requests`,yu=`${Za}.${wa}`,$v=[Za,gu,wu,Yh,yu];class Le extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(a(e,zc,Le.defaultValues(zc))),ma in e&&(this.version=a(e,ma,Le.defaultValues(ma))),ga in e&&(this.requestorName=a(e,ga,Le.defaultValues(ga))),this.requestList=a(e,eu,Le.defaultValues(eu)),wa in e&&(this.requestExtensions=a(e,wa,Le.defaultValues(wa))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case zc:return be;case ma:return 0;case ga:return new X;case eu:case wa:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case zc:return t.byteLength===0;case ma:return t===Le.defaultValues(e);case ga:return t.type===X.defaultValues("type")&&Object.keys(t.value).length===0;case eu:case wa:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||Za,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({name:t.TBSRequestVersion||gu})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[X.schema(t.requestorName||{names:{blockName:wu}})]}),new f({name:t.requestList||"TBSRequest.requestList",value:[new J({name:t.requests||Yh,value:gs.schema(t.requestNames||{})})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:2},value:[ke.schema(t.extensions||{names:{blockName:t.requestExtensions||yu}})]})]})}fromSchema(e){C(e,$v);const t=N(e,e,Le.schema());p.assertSchema(t,this.className),this.tbsView=t.result.TBSRequest.valueBeforeDecodeView,gu in t.result&&(this.version=t.result[gu].valueBlock.valueDec),wu in t.result&&(this.requestorName=new X({schema:t.result[wu]})),this.requestList=Array.from(t.result[Yh],s=>new gs({schema:s})),yu in t.result&&(this.requestExtensions=Array.from(t.result[yu].valueBlock.value,s=>new Ve({schema:s})))}toSchema(e=!1){let t;if(e===!1){if(this.tbsView.byteLength===0)return Le.schema();const s=Oe(this.tbsView);if(p.assert(s,"TBS Request"),!(s.result instanceof f))throw new Error("ASN.1 result should be SEQUENCE");t=s.result}else{const s=[];this.version!==void 0&&s.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[new S({value:this.version})]})),this.requestorName&&s.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[this.requestorName.toSchema()]})),s.push(new f({value:Array.from(this.requestList,n=>n.toSchema())})),this.requestExtensions&&s.push(new w({idBlock:{tagClass:3,tagNumber:2},value:[new f({value:Array.from(this.requestExtensions,n=>n.toSchema())})]})),t=new f({value:s})}return t}toJSON(){const e={};return this.version!=null&&(e.version=this.version),this.requestorName&&(e.requestorName=this.requestorName.toJSON()),e.requestList=Array.from(this.requestList,t=>t.toJSON()),this.requestExtensions&&(e.requestExtensions=Array.from(this.requestExtensions,t=>t.toJSON())),e}}Le.CLASS_NAME="TBSRequest";const fr="signatureAlgorithm",dr="signature",xs="certs";class ct extends k{constructor(e={}){super(),this.signatureAlgorithm=a(e,fr,ct.defaultValues(fr)),this.signature=a(e,dr,ct.defaultValues(dr)),xs in e&&(this.certs=a(e,xs,ct.defaultValues(xs))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case fr:return new v;case dr:return new W;case xs:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case fr:return t.algorithmId===u&&!("algorithmParams"in t);case dr:return t.isEqual(ct.defaultValues(e));case xs:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[v.schema(t.signatureAlgorithm||{}),new W({name:t.signature||u}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new f({value:[new J({name:t.certs||u,value:ee.schema({})})]})]})]})}fromSchema(e){C(e,[fr,dr,xs]);const t=N(e,e,ct.schema({names:{signatureAlgorithm:{names:{blockName:fr}},signature:dr,certs:xs}}));p.assertSchema(t,this.className),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signature=t.result.signature,xs in t.result&&(this.certs=Array.from(t.result.certs,s=>new ee({schema:s})))}toSchema(){const e=[];return e.push(this.signatureAlgorithm.toSchema()),e.push(this.signature),this.certs&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new f({value:Array.from(this.certs,t=>t.toSchema())})]})),new f({value:e})}toJSON(){const e={signatureAlgorithm:this.signatureAlgorithm.toJSON(),signature:this.signature.toJSON()};return this.certs&&(e.certs=Array.from(this.certs,t=>t.toJSON())),e}}ct.CLASS_NAME="Signature";const ya="tbsRequest",hn="optionalSignature",Mv=[ya,hn];class mc extends k{constructor(e={}){super(),this.tbsRequest=a(e,ya,mc.defaultValues(ya)),hn in e&&(this.optionalSignature=a(e,hn,mc.defaultValues(hn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ya:return new Le;case hn:return new ct;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ya:return Le.compareWithDefault("tbs",t.tbs)&&Le.compareWithDefault("version",t.version)&&Le.compareWithDefault("requestorName",t.requestorName)&&Le.compareWithDefault("requestList",t.requestList)&&Le.compareWithDefault("requestExtensions",t.requestExtensions);case hn:return ct.compareWithDefault("signatureAlgorithm",t.signatureAlgorithm)&&ct.compareWithDefault("signature",t.signature)&&ct.compareWithDefault("certs",t.certs);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||"OCSPRequest",value:[Le.schema(t.tbsRequest||{names:{blockName:ya}}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[ct.schema(t.optionalSignature||{names:{blockName:hn}})]})]})}fromSchema(e){C(e,Mv);const t=N(e,e,mc.schema());p.assertSchema(t,this.className),this.tbsRequest=new Le({schema:t.result.tbsRequest}),hn in t.result&&(this.optionalSignature=new ct({schema:t.result.optionalSignature}))}toSchema(e=!1){const t=[];return t.push(this.tbsRequest.toSchema(e)),this.optionalSignature&&t.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[this.optionalSignature.toSchema()]})),new f({value:t})}toJSON(){const e={tbsRequest:this.tbsRequest.toJSON()};return this.optionalSignature&&(e.optionalSignature=this.optionalSignature.toJSON()),e}async createForCertificate(e,t,s=q(!0)){const n=new Ne;await n.createForCertificate(e,t,s),this.tbsRequest.requestList.push(new gs({reqCert:n}))}async sign(e,t="SHA-1",s=q(!0)){if(Q.assertEmpty(e,"privateKey","OCSPRequest.sign method"),!this.optionalSignature)throw new Error('Need to create "optionalSignature" field before signing');const n=await s.getSignatureParameters(e,t),i=n.parameters;this.optionalSignature.signatureAlgorithm=n.signatureAlgorithm;const o=this.tbsRequest.toSchema(!0).toBER(!1),l=await s.signWithPrivateKey(o,e,i);this.optionalSignature.signature=new W({valueHex:l})}verify(){}}mc.CLASS_NAME="OCSPRequest";const va="responseType",Sa="response",Kv=[va,Sa];class xt extends k{constructor(e={}){super(),this.responseType=a(e,va,xt.defaultValues(va)),this.response=a(e,Sa,xt.defaultValues(Sa)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case va:return u;case Sa:return new I;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case va:return t===u;case Sa:return t.isEqual(xt.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new T({name:t.responseType||u}),new I({name:t.response||u})]})}fromSchema(e){C(e,Kv);const t=N(e,e,xt.schema({names:{responseType:va,response:Sa}}));p.assertSchema(t,this.className),this.responseType=t.result.responseType.valueBlock.toString(),this.response=t.result.response}toSchema(){return new f({value:[new T({value:this.responseType}),this.response]})}toJSON(){return{responseType:this.responseType,response:this.response.toJSON()}}}xt.CLASS_NAME="ResponseBytes";const mr="responseStatus",Yt="responseBytes";class La extends k{constructor(e={}){super(),this.responseStatus=a(e,mr,La.defaultValues(mr)),Yt in e&&(this.responseBytes=a(e,Yt,La.defaultValues(Yt))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case mr:return new sr;case Yt:return new xt;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case mr:return t.isEqual(La.defaultValues(e));case Yt:return xt.compareWithDefault("responseType",t.responseType)&&xt.compareWithDefault("response",t.response);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||"OCSPResponse",value:[new sr({name:t.responseStatus||mr}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[xt.schema(t.responseBytes||{names:{blockName:Yt}})]})]})}fromSchema(e){C(e,[mr,Yt]);const t=N(e,e,La.schema());p.assertSchema(t,this.className),this.responseStatus=t.result.responseStatus,Yt in t.result&&(this.responseBytes=new xt({schema:t.result.responseBytes}))}toSchema(){const e=[];return e.push(this.responseStatus),this.responseBytes&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[this.responseBytes.toSchema()]})),new f({value:e})}toJSON(){const e={responseStatus:this.responseStatus.toJSON()};return this.responseBytes&&(e.responseBytes=this.responseBytes.toJSON()),e}async getCertificateStatus(e,t,s=q(!0)){let n;const i={isForCertificate:!1,status:2};if(!this.responseBytes||this.responseBytes.responseType!==nu)return i;try{const o=Oe(this.responseBytes.response.valueBlock.valueHexView);p.assert(o,"Basic OCSP response"),n=new pt({schema:o.result})}catch{return i}return n.getCertificateStatus(e,t,s)}async sign(e,t,s=q(!0)){var n;if(this.responseBytes&&this.responseBytes.responseType===nu)return pt.fromBER(this.responseBytes.response.valueBlock.valueHexView).sign(e,t,s);throw new Error(`Unknown ResponseBytes type: ${((n=this.responseBytes)===null||n===void 0?void 0:n.responseType)||"Unknown"}`)}async verify(e=null,t=q(!0)){var s;if(!(Yt in this))throw new Error("Empty ResponseBytes field");if(this.responseBytes&&this.responseBytes.responseType===nu){const n=pt.fromBER(this.responseBytes.response.valueBlock.valueHexView);return e!==null&&(n.certs||(n.certs=[]),n.certs.push(e)),n.verify({},t)}throw new Error(`Unknown ResponseBytes type: ${((s=this.responseBytes)===null||s===void 0?void 0:s.responseType)||"Unknown"}`)}}La.CLASS_NAME="OCSPResponse";const Un="type",rs="attributes",tu="encodedValue",Jv=[rs];class me extends k{constructor(e={}){super(),this.type=a(e,Un,me.defaultValues(Un)),this.attributes=a(e,rs,me.defaultValues(rs)),this.encodedValue=a(e,tu,me.defaultValues(tu)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Un:return-1;case rs:return[];case tu:return be;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Un:return t===me.defaultValues(Un);case rs:return t.length===0;case tu:return t.byteLength===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new w({name:t.blockName||u,optional:!0,idBlock:{tagClass:3,tagNumber:t.tagNumber||0},value:[new J({name:t.attributes||u,value:le.schema()})]})}fromSchema(e){C(e,Jv);const t=N(e,e,me.schema({names:{tagNumber:this.type,attributes:rs}}));p.assertSchema(t,this.className),this.type=t.result.idBlock.tagNumber,this.encodedValue=L.toArrayBuffer(t.result.valueBeforeDecodeView);const s=new Uint8Array(this.encodedValue);if(s[0]=49,!(rs in t.result)){if(this.type===0)throw new Error("Wrong structure of SignedUnsignedAttributes");return}this.attributes=Array.from(t.result.attributes,n=>new le({schema:n}))}toSchema(){if(me.compareWithDefault(Un,this.type)||me.compareWithDefault(rs,this.attributes))throw new Error('Incorrectly initialized "SignedAndUnsignedAttributes" class');return new w({optional:!0,idBlock:{tagClass:3,tagNumber:this.type},value:Array.from(this.attributes,e=>e.toSchema())})}toJSON(){if(me.compareWithDefault(Un,this.type)||me.compareWithDefault(rs,this.attributes))throw new Error('Incorrectly initialized "SignedAndUnsignedAttributes" class');return{type:this.type,attributes:Array.from(this.attributes,e=>e.toJSON())}}}me.CLASS_NAME="SignedAndUnsignedAttributes";const Aa="version",Ti="sid",pa="digestAlgorithm",fn="signedAttrs",ba="signatureAlgorithm",zl="signature",dn="unsignedAttrs",Rn="SignerInfo",Qh=`${Rn}.${Aa}`,ec=`${Rn}.${Ti}`,Xh=`${Rn}.${pa}`,vu=`${Rn}.${fn}`,Zh=`${Rn}.${ba}`,zh=`${Rn}.${zl}`,Su=`${Rn}.${dn}`,jv=[Qh,ec,Xh,vu,Zh,zh,Su];class Se extends k{constructor(e={}){super(),this.version=a(e,Aa,Se.defaultValues(Aa)),this.sid=a(e,Ti,Se.defaultValues(Ti)),this.digestAlgorithm=a(e,pa,Se.defaultValues(pa)),fn in e&&(this.signedAttrs=a(e,fn,Se.defaultValues(fn))),this.signatureAlgorithm=a(e,ba,Se.defaultValues(ba)),this.signature=a(e,zl,Se.defaultValues(zl)),dn in e&&(this.unsignedAttrs=a(e,dn,Se.defaultValues(dn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Aa:return 0;case Ti:return new K;case pa:return new v;case fn:return new me({type:0});case ba:return new v;case zl:return new I;case dn:return new me({type:1});default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Aa:return Se.defaultValues(Aa)===t;case Ti:return t instanceof K;case pa:return t instanceof v?t.isEqual(Se.defaultValues(pa)):!1;case fn:return me.compareWithDefault("type",t.type)&&me.compareWithDefault("attributes",t.attributes)&&me.compareWithDefault("encodedValue",t.encodedValue);case ba:return t instanceof v?t.isEqual(Se.defaultValues(ba)):!1;case zl:case dn:return me.compareWithDefault("type",t.type)&&me.compareWithDefault("attributes",t.attributes)&&me.compareWithDefault("encodedValue",t.encodedValue);default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:Rn,value:[new S({name:t.version||Qh}),new he({value:[Be.schema(t.sidSchema||{names:{blockName:ec}}),new he({value:[new w({optional:!0,name:t.sid||ec,idBlock:{tagClass:3,tagNumber:0},value:[new I]}),new _({optional:!0,name:t.sid||ec,idBlock:{tagClass:3,tagNumber:0}})]})]}),v.schema(t.digestAlgorithm||{names:{blockName:Xh}}),me.schema(t.signedAttrs||{names:{blockName:vu,tagNumber:0}}),v.schema(t.signatureAlgorithm||{names:{blockName:Zh}}),new I({name:t.signature||zh}),me.schema(t.unsignedAttrs||{names:{blockName:Su,tagNumber:1}})]})}fromSchema(e){C(e,jv);const t=N(e,e,Se.schema());p.assertSchema(t,this.className),this.version=t.result[Qh].valueBlock.valueDec;const s=t.result[ec];s.idBlock.tagClass===1?this.sid=new Be({schema:s}):this.sid=s,this.digestAlgorithm=new v({schema:t.result[Xh]}),vu in t.result&&(this.signedAttrs=new me({type:0,schema:t.result[vu]})),this.signatureAlgorithm=new v({schema:t.result[Zh]}),this.signature=t.result[zh],Su in t.result&&(this.unsignedAttrs=new me({type:1,schema:t.result[Su]}))}toSchema(){if(Se.compareWithDefault(Ti,this.sid))throw new Error('Incorrectly initialized "SignerInfo" class');const e=[];return e.push(new S({value:this.version})),this.sid instanceof Be?e.push(this.sid.toSchema()):e.push(this.sid),e.push(this.digestAlgorithm.toSchema()),this.signedAttrs&&Se.compareWithDefault(fn,this.signedAttrs)===!1&&e.push(this.signedAttrs.toSchema()),e.push(this.signatureAlgorithm.toSchema()),e.push(this.signature),this.unsignedAttrs&&Se.compareWithDefault(dn,this.unsignedAttrs)===!1&&e.push(this.unsignedAttrs.toSchema()),new f({value:e})}toJSON(){if(Se.compareWithDefault(Ti,this.sid))throw new Error('Incorrectly initialized "SignerInfo" class');const e={version:this.version,digestAlgorithm:this.digestAlgorithm.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signature:this.signature.toJSON()};return this.sid instanceof K||(e.sid=this.sid.toJSON()),this.signedAttrs&&Se.compareWithDefault(fn,this.signedAttrs)===!1&&(e.signedAttrs=this.signedAttrs.toJSON()),this.unsignedAttrs&&Se.compareWithDefault(dn,this.unsignedAttrs)===!1&&(e.unsignedAttrs=this.unsignedAttrs.toJSON()),e}}Se.CLASS_NAME="SignerInfo";const tc="version",sc="policy",nc="messageImprint",ic="serialNumber",rc="genTime",Di="ordering",Pi="nonce",ka="accuracy",Ea="tsa",Na="extensions",Pt="TSTInfo",ef=`${Pt}.${tc}`,tf=`${Pt}.${sc}`,sf=`${Pt}.${nc}`,nf=`${Pt}.${ic}`,rf=`${Pt}.${rc}`,Au=`${Pt}.${ka}`,pu=`${Pt}.${Di}`,bu=`${Pt}.${Pi}`,ku=`${Pt}.${Ea}`,Eu=`${Pt}.${Na}`,Fv=[ef,tf,sf,nf,rf,Au,pu,bu,ku,Eu];class Me extends k{constructor(e={}){super(),this.version=a(e,tc,Me.defaultValues(tc)),this.policy=a(e,sc,Me.defaultValues(sc)),this.messageImprint=a(e,nc,Me.defaultValues(nc)),this.serialNumber=a(e,ic,Me.defaultValues(ic)),this.genTime=a(e,rc,Me.defaultValues(rc)),ka in e&&(this.accuracy=a(e,ka,Me.defaultValues(ka))),Di in e&&(this.ordering=a(e,Di,Me.defaultValues(Di))),Pi in e&&(this.nonce=a(e,Pi,Me.defaultValues(Pi))),Ea in e&&(this.tsa=a(e,Ea,Me.defaultValues(Ea))),Na in e&&(this.extensions=a(e,Na,Me.defaultValues(Na))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case tc:return 0;case sc:return u;case nc:return new He;case ic:return new S;case rc:return new Date(0,0,0);case ka:return new lt;case Di:return!1;case Pi:return new S;case Ea:return new X;case Na:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case tc:case sc:case rc:case Di:return t===Me.defaultValues(Di);case nc:return He.compareWithDefault(_i,t.hashAlgorithm)&&He.compareWithDefault($i,t.hashedMessage);case ic:case Pi:return t.isEqual(Me.defaultValues(Pi));case ka:return lt.compareWithDefault(Os,t.seconds)&<.compareWithDefault(Rs,t.millis)&<.compareWithDefault(Ts,t.micros);case Ea:return X.compareWithDefault(wo,t.type)&&X.compareWithDefault(yo,t.value);case Na:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||Pt,value:[new S({name:t.version||ef}),new T({name:t.policy||tf}),He.schema(t.messageImprint||{names:{blockName:sf}}),new S({name:t.serialNumber||nf}),new ue({name:t.genTime||rf}),lt.schema(t.accuracy||{names:{blockName:Au}}),new Ft({name:t.ordering||pu,optional:!0}),new S({name:t.nonce||bu,optional:!0}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[X.schema(t.tsa||{names:{blockName:ku}})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.extensions||Eu,value:Ve.schema(t.extension||{})})]})]})}fromSchema(e){C(e,Fv);const t=N(e,e,Me.schema());p.assertSchema(t,this.className),this.version=t.result[ef].valueBlock.valueDec,this.policy=t.result[tf].valueBlock.toString(),this.messageImprint=new He({schema:t.result[sf]}),this.serialNumber=t.result[nf],this.genTime=t.result[rf].toDate(),Au in t.result&&(this.accuracy=new lt({schema:t.result[Au]})),pu in t.result&&(this.ordering=t.result[pu].valueBlock.value),bu in t.result&&(this.nonce=t.result[bu]),ku in t.result&&(this.tsa=new X({schema:t.result[ku]})),Eu in t.result&&(this.extensions=Array.from(t.result[Eu],s=>new Ve({schema:s})))}toSchema(){const e=[];return e.push(new S({value:this.version})),e.push(new T({value:this.policy})),e.push(this.messageImprint.toSchema()),e.push(this.serialNumber),e.push(new ue({valueDate:this.genTime})),this.accuracy&&e.push(this.accuracy.toSchema()),this.ordering!==void 0&&e.push(new Ft({value:this.ordering})),this.nonce&&e.push(this.nonce),this.tsa&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[this.tsa.toSchema()]})),this.extensions&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:Array.from(this.extensions,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={version:this.version,policy:this.policy,messageImprint:this.messageImprint.toJSON(),serialNumber:this.serialNumber.toJSON(),genTime:this.genTime};return this.accuracy&&(e.accuracy=this.accuracy.toJSON()),this.ordering!==void 0&&(e.ordering=this.ordering),this.nonce&&(e.nonce=this.nonce.toJSON()),this.tsa&&(e.tsa=this.tsa.toJSON()),this.extensions&&(e.extensions=Array.from(this.extensions,t=>t.toJSON())),e}async verify(e,t=q(!0)){if(!e.data)throw new Error('"data" is a mandatory attribute for TST_INFO verification');const s=e.data;if(e.notBefore&&this.genTimee.notAfter)throw new Error("Generation time for TSTInfo object is more than notAfter value");const n=t.getAlgorithmByOID(this.messageImprint.hashAlgorithm.algorithmId,!0,"MessageImprint.hashAlgorithm"),i=await t.digest(n.name,new Uint8Array(s));return L.isEqual(i,this.messageImprint.hashedMessage.valueBlock.valueHexView)}}Me.CLASS_NAME="TSTInfo";const Ca="version",ac="digestAlgorithms",oc="encapContentInfo",Ba="certificates",Ia="crls",lc="signerInfos",fo="ocsps",rr="SignedData",af=`${rr}.${Ca}`,Nu=`${rr}.${ac}`,of=`${rr}.${oc}`,Cu=`${rr}.${Ba}`,Bu=`${rr}.${Ia}`,Iu=`${rr}.${lc}`,qv=[af,Nu,of,Cu,Bu,Iu];class $e extends Error{constructor({message:e,code:t=0,date:s=new Date,signatureVerified:n=null,signerCertificate:i=null,signerCertificateVerified:o=null,timestampSerial:l=null,certificatePath:c=[]}){super(e),this.name="SignedDataVerifyError",this.date=s,this.code=t,this.timestampSerial=l,this.signatureVerified=n,this.signerCertificate=i,this.signerCertificateVerified=o,this.certificatePath=c}}class Ue extends k{constructor(e={}){super(),this.version=a(e,Ca,Ue.defaultValues(Ca)),this.digestAlgorithms=a(e,ac,Ue.defaultValues(ac)),this.encapContentInfo=a(e,oc,Ue.defaultValues(oc)),Ba in e&&(this.certificates=a(e,Ba,Ue.defaultValues(Ba))),Ia in e&&(this.crls=a(e,Ia,Ue.defaultValues(Ia))),fo in e&&(this.ocsps=a(e,fo,Ue.defaultValues(fo))),this.signerInfos=a(e,lc,Ue.defaultValues(lc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ca:return 0;case ac:return[];case oc:return new nt;case Ba:return[];case Ia:return[];case fo:return[];case lc:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ca:return t===Ue.defaultValues(Ca);case oc:return nt.compareWithDefault("eContentType",t.eContentType)&&nt.compareWithDefault("eContent",t.eContent);case ac:case Ba:case Ia:case fo:case lc:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return t.optional===void 0&&(t.optional=!1),new f({name:t.blockName||rr,optional:t.optional,value:[new S({name:t.version||af}),new pe({value:[new J({name:t.digestAlgorithms||Nu,value:v.schema()})]}),nt.schema(t.encapContentInfo||{names:{blockName:of}}),new w({name:t.certificates||Cu,optional:!0,idBlock:{tagClass:3,tagNumber:0},value:Jt.schema().valueBlock.value}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:ys.schema(t.crls||{names:{crls:Bu}}).valueBlock.value}),new pe({value:[new J({name:t.signerInfos||Iu,value:Se.schema()})]})]})}fromSchema(e){C(e,qv);const t=N(e,e,Ue.schema());if(p.assertSchema(t,this.className),this.version=t.result[af].valueBlock.valueDec,Nu in t.result&&(this.digestAlgorithms=Array.from(t.result[Nu],s=>new v({schema:s}))),this.encapContentInfo=new nt({schema:t.result[of]}),Cu in t.result){const s=new Jt({schema:new pe({value:t.result[Cu].valueBlock.value})});this.certificates=s.certificates.slice(0)}Bu in t.result&&(this.crls=Array.from(t.result[Bu],s=>s.idBlock.tagClass===1?new Ie({schema:s}):(s.idBlock.tagClass=1,s.idBlock.tagNumber=16,new ws({schema:s})))),Iu in t.result&&(this.signerInfos=Array.from(t.result[Iu],s=>new Se({schema:s})))}toSchema(e=!1){const t=[];if(this.certificates&&this.certificates.length&&this.certificates.some(s=>s instanceof xn)||this.crls&&this.crls.length&&this.crls.some(s=>s instanceof ws)?this.version=5:this.certificates&&this.certificates.length&&this.certificates.some(s=>s instanceof ht)?this.version=4:this.certificates&&this.certificates.length&&this.certificates.some(s=>s instanceof us)||this.signerInfos.some(s=>s.version===3)||this.encapContentInfo.eContentType!==Ue.ID_DATA?this.version=3:this.version=1,t.push(new S({value:this.version})),t.push(new pe({value:Array.from(this.digestAlgorithms,s=>s.toSchema())})),t.push(this.encapContentInfo.toSchema()),this.certificates){const n=new Jt({certificates:this.certificates}).toSchema();t.push(new w({idBlock:{tagClass:3,tagNumber:0},value:n.valueBlock.value}))}return this.crls&&t.push(new w({idBlock:{tagClass:3,tagNumber:1},value:Array.from(this.crls,s=>{if(s instanceof ws){const n=s.toSchema();return n.idBlock.tagClass=3,n.idBlock.tagNumber=1,n}return s.toSchema(e)})})),t.push(new pe({value:Array.from(this.signerInfos,s=>s.toSchema())})),new f({value:t})}toJSON(){const e={version:this.version,digestAlgorithms:Array.from(this.digestAlgorithms,t=>t.toJSON()),encapContentInfo:this.encapContentInfo.toJSON(),signerInfos:Array.from(this.signerInfos,t=>t.toJSON())};return this.certificates&&(e.certificates=Array.from(this.certificates,t=>t.toJSON())),this.crls&&(e.crls=Array.from(this.crls,t=>t.toJSON())),e}async verify({signer:e=-1,data:t=be,trustedCerts:s=[],checkDate:n=new Date,checkChain:i=!1,passedWhenNotRevValues:o=!1,extendedMode:l=!1,findOrigin:c=null,findIssuer:h=null}={},m=q(!0)){let g=null,d=null;try{let b=be,A=u,E=[];const y=this.signerInfos[e];if(!y)throw new $e({date:n,code:1,message:"Unable to get signer by supplied index"});if(!this.certificates)throw new $e({date:n,code:2,message:"No certificates attached to this signed data"});if(y.sid instanceof Be){for(const V of this.certificates)if(V instanceof ee&&V.issuer.isEqual(y.sid.issuer)&&V.serialNumber.isEqual(y.sid.serialNumber)){g=V;break}}else{const V=y.sid,R=V.idBlock.isConstructed?V.valueBlock.value[0].valueBlock.valueHex:V.valueBlock.valueHex;for(const $ of this.certificates){if(!($ instanceof ee))continue;const te=await m.digest({name:"sha-1"},$.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView);if(ja(te,R)){g=$;break}}}if(!g)throw new $e({date:n,code:3,message:"Unable to find signer certificate"});if(this.encapContentInfo.eContentType===Qw){if(!this.encapContentInfo.eContent)throw new $e({date:n,code:15,message:"Error during verification: TSTInfo eContent is empty",signatureVerified:null,signerCertificate:g,timestampSerial:d,signerCertificateVerified:!0});let V;try{V=Me.fromBER(this.encapContentInfo.eContent.valueBlock.valueHexView)}catch{throw new $e({date:n,code:15,message:"Error during verification: TSTInfo wrong ASN.1 schema ",signatureVerified:null,signerCertificate:g,timestampSerial:d,signerCertificateVerified:!0})}if(n=V.genTime,d=V.serialNumber.valueBlock.valueHexView.slice().buffer,t.byteLength===0)throw new $e({date:n,code:4,message:"Missed detached data input array"});if(!await V.verify({data:t},m))throw new $e({date:n,code:15,message:"Error during verification: TSTInfo verification is failed",signatureVerified:!1,signerCertificate:g,timestampSerial:d,signerCertificateVerified:!0})}if(i){const V=this.certificates.filter(j=>j instanceof ee&&!!ig(j,g)),R={checkDate:n,certs:V,trustedCerts:s};h&&(R.findIssuer=h),c&&(R.findOrigin=c);const $=new eh(R);if($.certs.push(g),this.crls)for(const j of this.crls)"thisUpdate"in j?$.crls.push(j):j.otherRevInfoFormat===nu&&$.ocsps.push(new pt({schema:j.otherRevInfo}));this.ocsps&&$.ocsps.push(...this.ocsps);const te=await $.verify({passedWhenNotRevValues:o},m).catch(j=>{throw new $e({date:n,code:5,message:`Validation of signer's certificate failed with error: ${j instanceof Object?j.resultMessage:j}`,signerCertificate:g,signerCertificateVerified:!1})});if(te.certificatePath&&(E=te.certificatePath),!te.result)throw new $e({date:n,code:5,message:`Validation of signer's certificate failed: ${te.resultMessage}`,signerCertificate:g,signerCertificateVerified:!1})}const O=m.getAlgorithmByOID(y.digestAlgorithm.algorithmId);if(!("name"in O))throw new $e({date:n,code:7,message:`Unsupported signature algorithm: ${y.digestAlgorithm.algorithmId}`,signerCertificate:g,signerCertificateVerified:!0});A=O.name;const x=this.encapContentInfo.eContent;if(x)x.idBlock.tagClass===1&&x.idBlock.tagNumber===4?t=x.getValue():t=x.valueBlock.valueBeforeDecodeView.slice().buffer;else if(t.byteLength===0)throw new $e({date:n,code:8,message:"Missed detached data input array",signerCertificate:g,signerCertificateVerified:!0});if(y.signedAttrs){let V=!1,R=!1;for(const $ of y.signedAttrs.attributes)if($.type==="1.2.840.113549.1.9.3"&&(V=!0),$.type==="1.2.840.113549.1.9.4"&&(R=!0,b=$.values[0].valueBlock.valueHex),V&&R)break;if(V===!1)throw new $e({date:n,code:9,message:'Attribute "content-type" is a mandatory attribute for "signed attributes"',signerCertificate:g,signerCertificateVerified:!0});if(R===!1)throw new $e({date:n,code:10,message:'Attribute "message-digest" is a mandatory attribute for "signed attributes"',signatureVerified:null,signerCertificate:g,signerCertificateVerified:!0})}if(y.signedAttrs){const V=await m.digest(A,new Uint8Array(t));if(!ja(V,b))throw new $e({date:n,code:15,message:"Error during verification: Message digest doesn't match",signatureVerified:null,signerCertificate:g,timestampSerial:d,signerCertificateVerified:!0});t=y.signedAttrs.encodedValue}const B=y.signatureAlgorithm.algorithmId==="1.2.840.113549.1.1.1"?await m.verifyWithPublicKey(t,y.signature,g.subjectPublicKeyInfo,y.signatureAlgorithm,A):await m.verifyWithPublicKey(t,y.signature,g.subjectPublicKeyInfo,y.signatureAlgorithm);return l?{date:n,code:14,message:u,signatureVerified:B,signerCertificate:g,timestampSerial:d,signerCertificateVerified:!0,certificatePath:E}:B}catch(b){throw b instanceof $e?b:new $e({date:n,code:15,message:`Error during verification: ${b instanceof Error?b.message:b}`,signatureVerified:null,signerCertificate:g,timestampSerial:d,signerCertificateVerified:!0})}}async sign(e,t,s="SHA-1",n=be,i=q(!0)){var o;if(!e)throw new Error("Need to provide a private key for signing");const l=this.signerInfos[t];if(!l)throw new RangeError("SignerInfo index is out of range");!(!((o=l.signedAttrs)===null||o===void 0)&&o.attributes.length)&&"hash"in e.algorithm&&"hash"in e.algorithm&&e.algorithm.hash&&(s=e.algorithm.hash.name);const c=i.getOIDByAlgorithm({name:s},!0,"hashAlgorithm");this.digestAlgorithms.filter(d=>d.algorithmId===c).length===0&&this.digestAlgorithms.push(new v({algorithmId:c,algorithmParams:new Ae})),l.digestAlgorithm=new v({algorithmId:c,algorithmParams:new Ae});const h=await i.getSignatureParameters(e,s),m=h.parameters;if(l.signatureAlgorithm=h.signatureAlgorithm,l.signedAttrs)if(l.signedAttrs.encodedValue.byteLength!==0)n=l.signedAttrs.encodedValue;else{n=l.signedAttrs.toSchema().toBER();const d=L.toUint8Array(n);d[0]=49}else{const d=this.encapContentInfo.eContent;if(d)d.idBlock.tagClass===1&&d.idBlock.tagNumber===4?n=d.getValue():n=d.valueBlock.valueBeforeDecodeView.slice().buffer;else if(n.byteLength===0)throw new Error("Missed detached data input array")}const g=await i.signWithPrivateKey(n,e,m);l.signature=new I({valueHex:g})}}Ue.CLASS_NAME="SignedData";Ue.ID_DATA=Cf;const Li="version",Ui="authSafe",as="macData",mo="parsedValue",Wv=[Li,Ui,as];class vn extends k{constructor(e={}){super(),this.version=a(e,Li,vn.defaultValues(Li)),this.authSafe=a(e,Ui,vn.defaultValues(Ui)),as in e&&(this.macData=a(e,as,vn.defaultValues(as))),mo in e&&(this.parsedValue=a(e,mo,vn.defaultValues(mo))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Li:return 3;case Ui:return new oe;case as:return new Ye;case mo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Li:return t===vn.defaultValues(e);case Ui:return oe.compareWithDefault("contentType",t.contentType)&&oe.compareWithDefault("content",t.content);case as:return Ye.compareWithDefault("mac",t.mac)&&Ye.compareWithDefault("macSalt",t.macSalt)&&Ye.compareWithDefault("iterations",t.iterations);case mo:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.version||Li}),oe.schema(t.authSafe||{names:{blockName:Ui}}),Ye.schema(t.macData||{names:{blockName:as,optional:!0}})]})}fromSchema(e){C(e,Wv);const t=N(e,e,vn.schema({names:{version:Li,authSafe:{names:{blockName:Ui}},macData:{names:{blockName:as}}}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.authSafe=new oe({schema:t.result.authSafe}),as in t.result&&(this.macData=new Ye({schema:t.result.macData}))}toSchema(){const e=[new S({value:this.version}),this.authSafe.toSchema()];return this.macData&&e.push(this.macData.toSchema()),new f({value:e})}toJSON(){const e={version:this.version,authSafe:this.authSafe.toJSON()};return this.macData&&(e.macData=this.macData.toJSON()),e}async makeInternalValues(e={},t=q(!0)){if(ie.assert(e,"parameters","object"),!this.parsedValue)throw new Error('Please call "parseValues" function first in order to make "parsedValue" data');switch(Q.assertEmpty(this.parsedValue.integrityMode,"integrityMode","parsedValue"),Q.assertEmpty(this.parsedValue.authenticatedSafe,"authenticatedSafe","parsedValue"),this.parsedValue.integrityMode){case 0:{if(!("iterations"in e))throw new Q("iterations");Q.assertEmpty(e.pbkdf2HashAlgorithm,"pbkdf2HashAlgorithm"),Q.assertEmpty(e.hmacHashAlgorithm,"hmacHashAlgorithm"),Q.assertEmpty(e.password,"password");const s=new ArrayBuffer(64),n=new Uint8Array(s);t.getRandomValues(n);const i=this.parsedValue.authenticatedSafe.toSchema().toBER(!1);this.authSafe=new oe({contentType:oe.DATA,content:new I({valueHex:i})});const o=await t.stampDataWithPassword({password:e.password,hashAlgorithm:e.hmacHashAlgorithm,salt:s,iterationCount:e.iterations,contentToStamp:i});this.macData=new Ye({mac:new kt({digestAlgorithm:new v({algorithmId:t.getOIDByAlgorithm({name:e.hmacHashAlgorithm},!0,"hmacHashAlgorithm")}),digest:new I({valueHex:o})}),macSalt:new I({valueHex:s}),iterations:e.iterations})}break;case 1:{if(!("signingCertificate"in e))throw new Q("signingCertificate");Q.assertEmpty(e.privateKey,"privateKey"),Q.assertEmpty(e.hashAlgorithm,"hashAlgorithm");const s=this.parsedValue.authenticatedSafe.toSchema().toBER(!1),n=new Ue({version:1,encapContentInfo:new nt({eContentType:"1.2.840.113549.1.7.1",eContent:new I({valueHex:s})}),certificates:[e.signingCertificate]}),i=await t.digest({name:e.hashAlgorithm},new Uint8Array(s)),o=[];o.push(new le({type:"1.2.840.113549.1.9.3",values:[new T({value:"1.2.840.113549.1.7.1"})]})),o.push(new le({type:"1.2.840.113549.1.9.5",values:[new qa({valueDate:new Date})]})),o.push(new le({type:"1.2.840.113549.1.9.4",values:[new I({valueHex:i})]})),n.signerInfos.push(new Se({version:1,sid:new Be({issuer:e.signingCertificate.issuer,serialNumber:e.signingCertificate.serialNumber}),signedAttrs:new me({type:0,attributes:o})})),await n.sign(e.privateKey,0,e.hashAlgorithm,void 0,t),this.authSafe=new oe({contentType:"1.2.840.113549.1.7.2",content:n.toSchema(!0)})}break;default:throw new Error(`Parameter "integrityMode" has unknown value: ${this.parsedValue.integrityMode}`)}}async parseInternalValues(e,t=q(!0)){switch(ie.assert(e,"parameters","object"),e.checkIntegrity===void 0&&(e.checkIntegrity=!0),this.parsedValue={},this.authSafe.contentType){case oe.DATA:{Q.assertEmpty(e.password,"password"),this.parsedValue.integrityMode=0,ie.assert(this.authSafe.content,"authSafe.content",I);const s=this.authSafe.content.getValue();if(this.parsedValue.authenticatedSafe=er.fromBER(s),e.checkIntegrity){if(!this.macData)throw new Error('Absent "macData" value, can not check PKCS#12 data integrity');const n=t.getAlgorithmByOID(this.macData.mac.digestAlgorithm.algorithmId,!0,"digestAlgorithm");if(!await t.verifyDataStampedWithPassword({password:e.password,hashAlgorithm:n.name,salt:L.toArrayBuffer(this.macData.macSalt.valueBlock.valueHexView),iterationCount:this.macData.iterations||1,contentToVerify:s,signatureToVerify:L.toArrayBuffer(this.macData.mac.digest.valueBlock.valueHexView)}))throw new Error("Integrity for the PKCS#12 data is broken!")}}break;case oe.SIGNED_DATA:{this.parsedValue.integrityMode=1;const s=new Ue({schema:this.authSafe.content}),n=s.encapContentInfo.eContent;Q.assert(n,"eContent","cmsSigned.encapContentInfo"),ie.assert(n,"eContent",I);const i=n.getValue();if(this.parsedValue.authenticatedSafe=er.fromBER(i),!await s.verify({signer:0,checkChain:!1},t))throw new Error("Integrity for the PKCS#12 data is broken!")}break;default:throw new Error(`Incorrect value for "this.authSafe.contentType": ${this.authSafe.contentType}`)}}}vn.CLASS_NAME="PFX";const Va="status",mn="statusStrings",gn="failInfo",Gv=[Va,mn,gn];var yd;(function(r){r[r.granted=0]="granted",r[r.grantedWithMods=1]="grantedWithMods",r[r.rejection=2]="rejection",r[r.waiting=3]="waiting",r[r.revocationWarning=4]="revocationWarning",r[r.revocationNotification=5]="revocationNotification"})(yd||(yd={}));class bt extends k{constructor(e={}){super(),this.status=a(e,Va,bt.defaultValues(Va)),mn in e&&(this.statusStrings=a(e,mn,bt.defaultValues(mn))),gn in e&&(this.failInfo=a(e,gn,bt.defaultValues(gn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Va:return 2;case mn:return[];case gn:return new W;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Va:return t===bt.defaultValues(e);case mn:return t.length===0;case gn:return t.isEqual(bt.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||u,value:[new S({name:t.status||u}),new f({optional:!0,value:[new J({name:t.statusStrings||u,value:new Dt})]}),new W({name:t.failInfo||u,optional:!0})]})}fromSchema(e){C(e,Gv);const t=N(e,e,bt.schema({names:{status:Va,statusStrings:mn,failInfo:gn}}));p.assertSchema(t,this.className);const s=t.result.status;if(s.valueBlock.isHexOnly===!0||s.valueBlock.valueDec<0||s.valueBlock.valueDec>5)throw new Error('PKIStatusInfo "status" has invalid value');this.status=s.valueBlock.valueDec,mn in t.result&&(this.statusStrings=t.result.statusStrings),gn in t.result&&(this.failInfo=t.result.failInfo)}toSchema(){const e=[];return e.push(new S({value:this.status})),this.statusStrings&&e.push(new f({optional:!0,value:this.statusStrings})),this.failInfo&&e.push(this.failInfo),new f({value:e})}toJSON(){const e={status:this.status};return this.statusStrings&&(e.statusStrings=Array.from(this.statusStrings,t=>t.toJSON())),this.failInfo&&(e.failInfo=this.failInfo.toJSON()),e}}bt.CLASS_NAME="PKIStatusInfo";const cc="version",uc="messageImprint",xa="reqPolicy",Oa="nonce",os="certReq",Ra="extensions",ar="TimeStampReq",lf=`${ar}.${cc}`,cf=`${ar}.${uc}`,Vu=`${ar}.${xa}`,xu=`${ar}.${Oa}`,Ou=`${ar}.${os}`,Ru=`${ar}.${Ra}`,Yv=[lf,cf,Vu,xu,Ou,Ru];class it extends k{constructor(e={}){super(),this.version=a(e,cc,it.defaultValues(cc)),this.messageImprint=a(e,uc,it.defaultValues(uc)),xa in e&&(this.reqPolicy=a(e,xa,it.defaultValues(xa))),Oa in e&&(this.nonce=a(e,Oa,it.defaultValues(Oa))),os in e&&(this.certReq=a(e,os,it.defaultValues(os))),Ra in e&&(this.extensions=a(e,Ra,it.defaultValues(Ra))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case cc:return 0;case uc:return new He;case xa:return u;case Oa:return new S;case os:return!1;case Ra:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case cc:case xa:case os:return t===it.defaultValues(e);case uc:return He.compareWithDefault("hashAlgorithm",t.hashAlgorithm)&&He.compareWithDefault("hashedMessage",t.hashedMessage);case Oa:return t.isEqual(it.defaultValues(e));case Ra:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||ar,value:[new S({name:t.version||lf}),He.schema(t.messageImprint||{names:{blockName:cf}}),new T({name:t.reqPolicy||Vu,optional:!0}),new S({name:t.nonce||xu,optional:!0}),new Ft({name:t.certReq||Ou,optional:!0}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.extensions||Ru,value:Ve.schema()})]})]})}fromSchema(e){C(e,Yv);const t=N(e,e,it.schema());p.assertSchema(t,this.className),this.version=t.result[lf].valueBlock.valueDec,this.messageImprint=new He({schema:t.result[cf]}),Vu in t.result&&(this.reqPolicy=t.result[Vu].valueBlock.toString()),xu in t.result&&(this.nonce=t.result[xu]),Ou in t.result&&(this.certReq=t.result[Ou].valueBlock.value),Ru in t.result&&(this.extensions=Array.from(t.result[Ru],s=>new Ve({schema:s})))}toSchema(){const e=[];return e.push(new S({value:this.version})),e.push(this.messageImprint.toSchema()),this.reqPolicy&&e.push(new T({value:this.reqPolicy})),this.nonce&&e.push(this.nonce),os in this&&it.compareWithDefault(os,this.certReq)===!1&&e.push(new Ft({value:this.certReq})),this.extensions&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.extensions,t=>t.toSchema())})),new f({value:e})}toJSON(){const e={version:this.version,messageImprint:this.messageImprint.toJSON()};return this.reqPolicy!==void 0&&(e.reqPolicy=this.reqPolicy),this.nonce!==void 0&&(e.nonce=this.nonce.toJSON()),this.certReq!==void 0&&it.compareWithDefault(os,this.certReq)===!1&&(e.certReq=this.certReq),this.extensions&&(e.extensions=Array.from(this.extensions,t=>t.toJSON())),e}}it.CLASS_NAME="TimeStampReq";const Ta="status",Da="timeStampToken",Uf="TimeStampResp",uf=`${Uf}.${Ta}`,Tu=`${Uf}.${Da}`,Qv=[uf,Tu];class gc extends k{constructor(e={}){super(),this.status=a(e,Ta,gc.defaultValues(Ta)),Da in e&&(this.timeStampToken=a(e,Da,gc.defaultValues(Da))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ta:return new bt;case Da:return new oe;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ta:return bt.compareWithDefault(Ta,t.status)&&!("statusStrings"in t)&&!("failInfo"in t);case Da:return t.contentType===u&&t.content instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=a(e,"names",{});return new f({name:t.blockName||Uf,value:[bt.schema(t.status||{names:{blockName:uf}}),oe.schema(t.timeStampToken||{names:{blockName:Tu,optional:!0}})]})}fromSchema(e){C(e,Qv);const t=N(e,e,gc.schema());p.assertSchema(t,this.className),this.status=new bt({schema:t.result[uf]}),Tu in t.result&&(this.timeStampToken=new oe({schema:t.result[Tu]}))}toSchema(){const e=[];return e.push(this.status.toSchema()),this.timeStampToken&&e.push(this.timeStampToken.toSchema()),new f({value:e})}toJSON(){const e={status:this.status.toJSON()};return this.timeStampToken&&(e.timeStampToken=this.timeStampToken.toJSON()),e}async sign(e,t,s=q(!0)){return this.assertContentType(),new Ue({schema:this.timeStampToken.content}).sign(e,0,t,void 0,s)}async verify(e={signer:0,trustedCerts:[],data:be},t=q(!0)){return this.assertContentType(),new Ue({schema:this.timeStampToken.content}).verify(e,t)}assertContentType(){if(!this.timeStampToken)throw new Error("timeStampToken is absent in TSP response");if(this.timeStampToken.contentType!==Qm)throw new Error(`Wrong format of timeStampToken: ${this.timeStampToken.contentType}`)}}gc.CLASS_NAME="TimeStampResp";function Xv(){if(typeof globalThis<"u"&&"crypto"in globalThis){let r="webcrypto";"webkitSubtle"in globalThis.crypto&&(r="safari"),td(r,new Uu({name:r,crypto:globalThis.crypto}))}else if(typeof crypto<"u"&&"webcrypto"in crypto){const r="NodeJS ^15",e=crypto.webcrypto;td(r,new Uu({name:r,crypto:e}))}}Xv();function ag(r){let e="";for(const t of r)e+=String.fromCharCode(t);return typeof btoa=="function"?btoa(e):Buffer.from(r).toString("base64")}function og(r){if(typeof atob=="function"){const e=atob(r),t=new Uint8Array(e.length);for(let s=0;s{});t("begin");let s;try{({attestationChallenge:s}=await dg(r.code))}catch(c){throw Sd(c)}t("generating_key");let n,i,o;try{({publicKey:n,certificateChain:i}=await e.register({attestationChallenge:s,force:!0})),t("building_csr"),o=await sS(n,async c=>{const{signature:h}=await e.sign({challenge:ag(c)});return og(h)})}catch{throw new ji("Could not prepare the device key on this tablet. Restart the app and try again.","attestation")}t("requesting_cert");let l;try{l=await mg({code:r.code,csr:o,attestationChain:i,requestId:r.requestId})}catch(c){throw Sd(c)}t("storing_cert");try{await e.storeCertificate({certPem:l.certPem,chainPem:l.chainPem})}catch{throw new ji("The certificate was issued but could not be saved on this tablet. Restart the app and try again.","unknown")}return t("done"),l}function Sd(r){return r instanceof su?r.status===0?new ji("Network error — check the connection.","network"):r.code==="rate_limited"?new ji("Too many attempts — wait a minute and try again.","rate_limited"):new ji("Enrollment failed — check the code or request a new one.","code"):new ji(r instanceof Error?r.message:"Unknown error","unknown")}const or=r=>document.getElementById(r),Hf=or("code"),Gu=or("submit"),Ad=or("scan"),go=or("preview"),cg=or("steps"),pd=or("status"),iS=or("hint");function hc(r,e){pd.textContent=r,pd.className=e??""}function bd(r){const e=[...cg.querySelectorAll("li")];let t=!0;for(const s of e)s.dataset.step===r?(s.className="active",t=!1):s.className=t?"complete":""}fg()||(iS.textContent="This page must be opened inside the AngioAssist app on the tablet.",Gu.disabled=!0);let kd=lg(),Ed="";async function _f(){let r;try{r=Cd(Hf.value)}catch(e){hc(e instanceof Error?e.message:"Invalid code","err");return}r!==Ed&&(kd=lg(),Ed=r),Gu.disabled=!0,cg.hidden=!1,hc("");try{await nS({code:r,requestId:kd,onStep:bd}),hc("Device enrolled. Returning to AngioAssist…","ok"),bd("done"),location.assign("/enrolled")}catch(e){hc(e instanceof Error?e.message:"Enrollment failed","err"),Gu.disabled=!1}}Gu.addEventListener("click",_f);Hf.addEventListener("keydown",r=>{r.key==="Enter"&&_f()});const Nd=globalThis.BarcodeDetector;if(Nd&&navigator.mediaDevices?.getUserMedia){Ad.hidden=!1;let r=null;const e=new Nd({formats:["qr_code"]}),t=()=>{r?.getTracks().forEach(s=>s.stop()),r=null,go.hidden=!0};Ad.addEventListener("click",async()=>{try{r=await navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}}),go.srcObject=r,go.hidden=!1,await go.play();const s=async()=>{if(r){try{const i=(await e.detect(go)).map(o=>o.rawValue).find(o=>o.startsWith("angioassist-enroll:"));if(i){Hf.value=hg(i),t(),_f();return}}catch{}requestAnimationFrame(s)}};requestAnimationFrame(s)}catch{hc("Camera unavailable — enter the code manually.","err"),t()}})}