@pkistudio/pvkgadgets 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +245 -0
- package/dist/app.js +292 -0
- package/dist/chunks/modulepreload-polyfill-B5Qt9EMX.js +1 -0
- package/dist/chunks/pkcs12-lDYE488P.js +5 -0
- package/dist/chunks/pkistudio--jw2SR0V.js +1313 -0
- package/dist/core.js +5 -0
- package/dist/favicon.ico +0 -0
- package/dist/index.html +19 -0
- package/dist/main.js +1 -0
- package/dist/pkcs12.js +1 -0
- package/dist/styles.css +1 -0
- package/dist/types/app.d.ts +73 -0
- package/dist/types/core.d.ts +97 -0
- package/dist/types/pkcs12.d.ts +18 -0
- package/dist/types/pkistudio-types.d.ts +47 -0
- package/dist/types/pkistudio.d.ts +4 -0
- package/dist/viewer.html +15 -0
- package/dist/viewer.js +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const Gm="[object ArrayBuffer]";class L{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Gm}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<s.length;i++)if(s[i]!==n[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let s=0;for(const o of t)s+=o.byteLength;const n=new Uint8Array(s);let i=0;for(const o of t){const l=this.toUint8Array(o);n.set(l,i),i+=l.length}return e[e.length-1]instanceof Function?this.toView(n,e[e.length-1]):n.buffer}}const Qu="string",Ym=/^[0-9a-f\s]+$/i,Qm=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Xm=/^[a-zA-Z0-9-_]+$/;class Pf{static fromString(e){const t=unescape(encodeURIComponent(e)),s=new Uint8Array(t.length);for(let n=0;n<t.length;n++)s[n]=t.charCodeAt(n);return s.buffer}static toString(e){const t=L.toUint8Array(e);let s="";for(let i=0;i<t.length;i++)s+=String.fromCharCode(t[i]);return decodeURIComponent(escape(s))}}class Ut{static toString(e,t=!1){const s=L.toArrayBuffer(e),n=new DataView(s);let i="";for(let o=0;o<s.byteLength;o+=2){const l=n.getUint16(o,t);i+=String.fromCharCode(l)}return i}static fromString(e,t=!1){const s=new ArrayBuffer(e.length*2),n=new DataView(s);for(let i=0;i<e.length;i++)n.setUint16(i*2,e.charCodeAt(i),t);return s}}class H{static isHex(e){return typeof e===Qu&&Ym.test(e)}static isBase64(e){return typeof e===Qu&&Qm.test(e)}static isBase64Url(e){return typeof e===Qu&&Xm.test(e)}static ToString(e,t="utf8"){const s=L.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(s);case"binary":return this.ToBinary(s);case"hex":return this.ToHex(s);case"base64":return this.ToBase64(s);case"base64url":return this.ToBase64Url(s);case"utf16le":return Ut.toString(s,!0);case"utf16":case"utf16be":return Ut.toString(s);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Ut.fromString(e,!0);case"utf16":case"utf16be":return Ut.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const t=L.toUint8Array(e);if(typeof btoa<"u"){const s=this.ToString(t,"binary");return btoa(s)}else return Buffer.from(t).toString("base64")}static FromBase64(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!H.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!H.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=H.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return Pf.fromString(e);case"utf16":case"utf16be":return Ut.fromString(e);case"utf16le":case"usc2":return Ut.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=H.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return Pf.toString(e);case"utf16":case"utf16be":return Ut.toString(e);case"utf16le":case"usc2":return Ut.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){const t=e.length,s=new Uint8Array(t);for(let n=0;n<t;n++)s[n]=e.charCodeAt(n);return s.buffer}static ToBinary(e){const t=L.toUint8Array(e);let s="";for(let n=0;n<t.length;n++)s+=String.fromCharCode(t[n]);return s}static ToHex(e){const t=L.toUint8Array(e);let s="";const n=t.length;for(let i=0;i<n;i++){const o=t[i];o<16&&(s+="0"),s+=o.toString(16)}return s}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!H.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);const s=new Uint8Array(t.length/2);for(let n=0;n<t.length;n=n+2){const i=t.slice(n,n+2);s[n/2]=parseInt(i,16)}return s.buffer}static ToUtf16String(e,t=!1){return Ut.toString(e,t)}static FromUtf16String(e,t=!1){return Ut.fromString(e,t)}static Base64Padding(e){const t=4-e.length%4;if(t<4)for(let s=0;s<t;s++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}}H.DEFAULT_UTF8_ENCODING="utf8";function r(a,e,t){var s;return a instanceof Object&&(s=a[e])!==null&&s!==void 0?s:t}function Xu(a,e=0,t=a.byteLength-e,s=!1){let n="";for(const i of new Uint8Array(a,e,t)){const o=i.toString(16).toUpperCase();o.length===1&&(n+="0"),n+=o,s&&(n+=" ")}return n.trim()}function er(a,e){let t=0;if(a.length===1)return a[0];for(let s=a.length-1;s>=0;s--)t+=a[a.length-1-s]*Math.pow(2,e*s);return t}function ks(a,e,t=-1){const s=t;let n=a,i=0,o=Math.pow(2,e);for(let l=1;l<8;l++){if(a<o){let c;if(s<0)c=new ArrayBuffer(l),i=l;else{if(s<l)return new ArrayBuffer(0);c=new ArrayBuffer(s),i=s}const h=new Uint8Array(c);for(let f=l-1;f>=0;f--){const g=Math.pow(2,f*e);h[i-f-1]=Math.floor(n/g),n-=h[i-f-1]*g}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function La(...a){let e=0,t=0;for(const i of a)e+=i.byteLength;const s=new ArrayBuffer(e),n=new Uint8Array(s);for(const i of a)n.set(new Uint8Array(i),t),t+=i.byteLength;return s}function Rh(...a){let e=0,t=0;for(const i of a)e+=i.length;const s=new ArrayBuffer(e),n=new Uint8Array(s);for(const i of a)n.set(i,t),t+=i.length;return n}function dd(){const a=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const l=a[0]===255&&a[1]&128,c=a[0]===0&&(a[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<this.valueHex.byteLength;l++)t[l]=0;t[0]=a[0]&128;const s=er(t,8),n=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(n);for(let l=0;l<this.valueHex.byteLength;l++)i[l]=a[l];return i[0]&=127,er(i,8)-s}function Zm(a){const e=a<0?a*-1:a;let t=128;for(let s=1;s<8;s++){if(e<=t){if(a<0){const o=t-e,l=ks(o,8,s),c=new Uint8Array(l);return c[0]|=128,l}let n=ks(e,8,s),i=new Uint8Array(n);if(i[0]&128){const o=n.slice(0),l=new Uint8Array(o);n=new ArrayBuffer(n.byteLength+1),i=new Uint8Array(n);for(let c=0;c<o.byteLength;c++)i[c+1]=l[c];i[0]=0}return n}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ja(a,e){if(a.byteLength!==e.byteLength)return!1;const t=new Uint8Array(a),s=new Uint8Array(e);for(let n=0;n<t.length;n++)if(t[n]!==s[n])return!1;return!0}function lt(a,e){const t=a.toString(10);if(e<t.length)return"";const s=e-t.length,n=new Array(s);for(let o=0;o<s;o++)n[o]="0";return n.join("").concat(t)}const md="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",gd="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";function Th(a,e=!1,t=!1,s=!1){let n=0,i=0,o=0,l="";const c=e?gd:md;if(s){let h=0;for(let f=0;f<a.length;f++)if(a.charCodeAt(f)!==0){h=f;break}a=a.slice(h)}for(;n<a.length;){const h=a.charCodeAt(n++);n>=a.length&&(i=1);const f=a.charCodeAt(n++);n>=a.length&&(o=1);const g=a.charCodeAt(n++),m=h>>2,b=(h&3)<<4|f>>4;let A=(f&15)<<2|g>>6,E=g&63;i===1?A=E=64:o===1&&(E=64),t?A===64?l+=`${c.charAt(m)}${c.charAt(b)}`:E===64?l+=`${c.charAt(m)}${c.charAt(b)}${c.charAt(A)}`:l+=`${c.charAt(m)}${c.charAt(b)}${c.charAt(A)}${c.charAt(E)}`:l+=`${c.charAt(m)}${c.charAt(b)}${c.charAt(A)}${c.charAt(E)}`}return l}function mc(a,e=!1,t=!1){const s=e?gd:md;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<a.length;){const c=n(a.charAt(o++)),h=o>=a.length?0:n(a.charAt(o++)),f=o>=a.length?0:n(a.charAt(o++)),g=o>=a.length?0:n(a.charAt(o++)),m=i(c)<<2|i(h)>>4,b=(i(h)&15)<<4|i(f)>>2,A=(i(f)&3)<<6|i(g);l+=String.fromCharCode(m),f!==64&&(l+=String.fromCharCode(b)),g!==64&&(l+=String.fromCharCode(A))}if(t){const c=l.length;let h=-1;for(let f=c-1;f>=0;f--)if(l.charCodeAt(f)!==0){h=f;break}h!==-1?l=l.slice(0,h+1):l=""}return l}function xu(a){let e="";const t=new Uint8Array(a);for(const s of t)e+=String.fromCharCode(s);return e}function ja(a){const e=a.length,t=new ArrayBuffer(e),s=new Uint8Array(t);for(let n=0;n<e;n++)s[n]=a.charCodeAt(n);return t}const zm=Math.log(2);function eg(a){const e=Math.log(a)/zm,t=Math.floor(e),s=Math.round(e);return t===s?t:s}function C(a,e){for(const t of e)delete a[t]}function Ou(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function lf(a){let e=0,t=0;for(let n=0;n<a.length;n++){const i=a[n];e+=i.byteLength}const s=new Uint8Array(e);for(let n=0;n<a.length;n++){const i=a[n];s.set(new Uint8Array(i),t),t+=i.byteLength}return s.buffer}function Es(a,e,t,s){return e instanceof Uint8Array?e.byteLength?t<0?(a.error="Wrong parameter: inputOffset less than zero",!1):s<0?(a.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-s<0?(a.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(a.error="Wrong parameter: inputBuffer has zero length",!1):(a.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}class cf{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return lf(this.items)}}const Za=[new Uint8Array([1])],Lf="0123456789",Zu="name",Uf="valueHexView",tg="isHexOnly",sg="idBlock",ng="tagClass",ig="tagNumber",rg="isConstructed",ag="fromBER",og="toBER",lg="local",st="",Qt=new ArrayBuffer(0),ju=new Uint8Array(0),gc="EndOfContent",wd="OCTET STRING",yd="BIT STRING";function Ns(a){var e;return e=class extends a{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(s){this.valueHexView=new Uint8Array(s)}constructor(...s){var n;super(...s);const i=s[0]||{};this.isHexOnly=(n=i.isHexOnly)!==null&&n!==void 0?n:!1,this.valueHexView=i.valueHex?L.toUint8Array(i.valueHex):ju}fromBER(s,n,i,o){const l=s instanceof ArrayBuffer?new Uint8Array(s):s;if(!Es(this,l,n,i))return-1;const c=n+i;return this.valueHexView=l.subarray(n,c),this.valueHexView.length?(this.blockLength=i,c):(this.warnings.push("Zero buffer length"),n)}toBER(s=!1){return this.isHexOnly?s?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Qt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:H.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class nr{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=st,warnings:s=[],valueBeforeDecode:n=ju}={}){this.blockLength=e,this.error=t,this.warnings=s,this.valueBeforeDecodeView=L.toUint8Array(n)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:H.ToHex(this.valueBeforeDecodeView)}}}nr.NAME="baseBlock";class Ze extends nr{fromBER(e,t,s,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}Ze.NAME="valueBlock";class vd extends Ns(nr){constructor({idBlock:e={}}={}){var t,s,n,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?L.toUint8Array(e.valueHex):ju,this.tagClass=(s=e.tagClass)!==null&&s!==void 0?s:-1,this.tagNumber=(n=e.tagNumber)!==null&&n!==void 0?n:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",Qt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const n=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,n[0]=t}return n.buffer}if(!this.isHexOnly){const n=ks(this.tagNumber,7),i=new Uint8Array(n),o=n.byteLength,l=new Uint8Array(o+1);if(l[0]=t|31,!e){for(let c=0;c<o-1;c++)l[c+1]=i[c]|128;l[o]=i[o-1]}return l.buffer}const s=new Uint8Array(this.valueHexView.byteLength+1);if(s[0]=t|31,!e){const n=this.valueHexView;for(let i=0;i<n.length-1;i++)s[i+1]=n[i]|128;s[this.valueHexView.byteLength]=n[n.length-1]}return s.buffer}fromBER(e,t,s){const n=L.toUint8Array(e);if(!Es(this,n,t,s))return-1;const i=n.subarray(t,t+s);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;const l=i[0]&31;if(l!==31)this.tagNumber=l,this.blockLength=1;else{let c=0;for(;;){const f=c+1;if(f>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c++,(i[f]&128)===0)break}this.blockLength=c+1;const h=this.valueHexView=new Uint8Array(c);for(let f=0;f<c;f++)h[f]=i[f+1]&127;this.blockLength<=9?this.tagNumber=er(h,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}vd.NAME="identificationBlock";class Sd extends nr{constructor({lenBlock:e={}}={}){var t,s,n;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(s=e.longFormUsed)!==null&&s!==void 0?s:!1,this.length=(n=e.length)!==null&&n!==void 0?n:0}fromBER(e,t,s){const n=L.toUint8Array(e);if(!Es(this,n,t,s))return-1;const i=n.subarray(t,t+s);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;const o=i[0]&127;if(o>8)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=er(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=ks(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;o<n.byteLength;o++)s[o+1]=i[o];return t}return t=new ArrayBuffer(1),e===!1&&(s=new Uint8Array(t),s[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}Sd.NAME="lengthBlock";const D={};class je extends nr{constructor({name:e=st,optional:t=!1,primitiveSchema:s,...n}={},i){super(n),this.name=e,this.optional=t,s&&(this.primitiveSchema=s),this.idBlock=new vd(n),this.lenBlock=new Sd(n),this.valueBlock=i?new i(n):new Ze(n)}fromBER(e,t,s,n){const i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?s:this.lenBlock.length,n);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,t){const s=t||new cf;t||Ad(this);const n=this.idBlock.toBER(e);if(s.write(n),this.lenBlock.isIndefiniteForm)s.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,s),s.write(new ArrayBuffer(2));else{const i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;const o=this.lenBlock.toBER(e);s.write(o),s.write(i)}return t?Qt:s.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():H.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,t=H.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;const t=this.toBER(),s=e.toBER();return Ja(t,s)}}je.NAME="BaseBlock";function Ad(a){var e;if(a instanceof D.Constructed)for(const t of a.valueBlock.value)Ad(t)&&(a.lenBlock.isIndefiniteForm=!0);return!!(!((e=a.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class pd extends je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=st,...t}={},s){super(t,s),e&&this.fromString(e)}fromBER(e,t,s){const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?s:this.lenBlock.length);return n===-1?(this.error=this.valueBlock.error,n):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}pd.NAME="BaseStringBlock";class bd extends Ns(Ze){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}bd.NAME="PrimitiveValueBlock";var kd;class _ extends je{constructor(e={}){super(e,bd),this.idBlock.isConstructed=!1}}kd=_;D.Primitive=kd;_.NAME="PRIMITIVE";const cg=100,ug=1e4,hg=16*1024*1024,fg="Maximum ASN.1 nesting depth exceeded",dg="Maximum ASN.1 node count exceeded",mg="Maximum ASN.1 content length exceeded";function Ec(a={}){var e,t,s;return{depth:0,maxDepth:(e=a.maxDepth)!==null&&e!==void 0?e:cg,nodesCount:0,maxNodes:(t=a.maxNodes)!==null&&t!==void 0?t:ug,maxContentLength:(s=a.maxContentLength)!==null&&s!==void 0?s:hg}}function gg(a){const e=new je({},Ze);return e.error=a,{offset:-1,result:e}}function wg(a){if(a.nodesCount+=1,a.nodesCount>a.maxNodes)return dg}function yg(a,e){if(a>e.maxContentLength)return mg}function uf(a,e,t,s){const n=s.depth+1;if(n>s.maxDepth)return gg(fg);s.depth=n;try{return hf(a,e,t,s)}finally{s.depth-=1}}function vg(a,e){if(a instanceof e)return a;const t=new e;return t.idBlock=a.idBlock,t.lenBlock=a.lenBlock,t.warnings=a.warnings,t.valueBeforeDecodeView=a.valueBeforeDecodeView,t}function hf(a,e=0,t=a.length,s=Ec()){const n=e;let i=new je({},Ze);const o=new nr;if(!Es(o,a,e,t))return i.error=o.error,{offset:-1,result:i};if(!a.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};const c=wg(s);if(c)return i.error=c,{offset:-1,result:i};let h=i.idBlock.fromBER(a,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(a,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 f=i.lenBlock.isIndefiniteForm?t:i.lenBlock.length,g=yg(f,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 m=je;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};m=D.EndOfContent;break;case 1:m=D.Boolean;break;case 2:m=D.Integer;break;case 3:m=D.BitString;break;case 4:m=D.OctetString;break;case 5:m=D.Null;break;case 6:m=D.ObjectIdentifier;break;case 10:m=D.Enumerated;break;case 12:m=D.Utf8String;break;case 13:m=D.RelativeObjectIdentifier;break;case 14:m=D.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:m=D.Sequence;break;case 17:m=D.Set;break;case 18:m=D.NumericString;break;case 19:m=D.PrintableString;break;case 20:m=D.TeletexString;break;case 21:m=D.VideotexString;break;case 22:m=D.IA5String;break;case 23:m=D.UTCTime;break;case 24:m=D.GeneralizedTime;break;case 25:m=D.GraphicString;break;case 26:m=D.VisibleString;break;case 27:m=D.GeneralString;break;case 28:m=D.UniversalString;break;case 29:m=D.CharacterString;break;case 30:m=D.BmpString;break;case 31:m=D.DATE;break;case 32:m=D.TimeOfDay;break;case 33:m=D.DateTime;break;case 34:m=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:m=i.idBlock.isConstructed?D.Constructed:D.Primitive}return i=vg(i,m),h=i.fromBER(a,e,f,s),i.valueBeforeDecodeView=a.subarray(n,n+i.blockLength),{offset:h,result:i}}function Be(a,e={}){if(!a.byteLength){const t=new je({},Ze);return t.error="Input buffer has zero length",{offset:-1,result:t}}return hf(L.toUint8Array(a).slice(),0,a.byteLength,Ec(e))}function Sg(a,e){return a?1:e}class In 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??Ec();if(!Es(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(;Sg(this.isIndefiniteForm,s)>0;){const c=uf(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===gc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===gc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),l}toBER(e,t){const s=t||new cf;for(let n=0;n<this.value.length;n++)this.value[n].toBER(e,s);return t?Qt:s.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const t of this.value)e.value.push(t.toJSON());return e}}In.NAME="ConstructedValueBlock";var Ed;class w extends je{constructor(e={}){super(e,In),this.idBlock.isConstructed=!0}fromBER(e,t,s,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?s:this.lenBlock.length,n);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){const e=[];for(const s of this.valueBlock.value)e.push(s.toString("ascii").split(`
|
|
2
|
+
`).map(n=>` ${n}`).join(`
|
|
3
|
+
`));const t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
4
|
+
${e.join(`
|
|
5
|
+
`)}`:`${t} :`}}Ed=w;D.Constructed=Ed;w.NAME="CONSTRUCTED";class Nd extends Ze{fromBER(e,t,s){return t}toBER(e){return Qt}}Nd.override="EndOfContentValueBlock";var Cd;class Bd extends je{constructor(e={}){super(e,Nd),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Cd=Bd;D.EndOfContent=Cd;Bd.NAME=gc;var Id;class Ae extends je{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}`}}Id=Ae;D.Null=Id;Ae.NAME="NULL";class Vd extends Ns(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 Es(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,dd.call(this),this.blockLength=s,t+s):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}Vd.NAME="BooleanValueBlock";var xd;let Yt=class extends je{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Vd),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};xd=Yt;D.Boolean=xd;Yt.NAME="BOOLEAN";class Od extends Ns(In){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=In.prototype.fromBER.call(this,e,t,s,n),i===-1)return i;for(let o=0;o<this.value.length;o++){const l=this.value[o].constructor.NAME;if(l===gc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(l!==wd)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,t,s),this.blockLength=s;return i}toBER(e,t){return this.isConstructed?In.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}Od.NAME="OctetStringValueBlock";var ff;class B extends je{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},Od),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,s,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,s===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+s);try{if(o.byteLength){const l=n??Ec(),c=uf(o,0,o.byteLength,l);c.offset!==-1&&c.offset===s&&(this.valueBlock.value=[c.result])}}catch{}}return 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=this.constructor.NAME,t=H.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof ff&&e.push(t.valueBlock.valueHexView);return L.concat(e)}}ff=B;D.OctetString=ff;B.NAME=wd;class Rd extends Ns(In){constructor({unusedBits:e=0,isConstructed:t=!1,...s}={}){super(s),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,s,n){if(!s)return t;let i=-1;if(this.isConstructed){if(i=In.prototype.fromBER.call(this,e,t,s,n),i===-1)return i;for(const c of this.value){const h=c.constructor.NAME;if(h===gc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(h!==yd)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const f=c.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return i}const o=L.toUint8Array(e);if(!Es(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??Ec(),f=uf(c,0,c.byteLength,h);f.offset!==-1&&f.offset===s-1&&(this.value=[f.result])}}catch{}}return this.valueHexView=l.subarray(1),this.blockLength=l.length,t+s}toBER(e,t){if(this.isConstructed)return In.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}}}Rd.NAME="BitStringValueBlock";var Td;class G extends je{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},Rd),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}`}}}Td=G;D.BitString=Td;G.NAME=yd;var Dd;function Ag(a,e){const t=new Uint8Array([0]),s=new Uint8Array(a),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 f=c<o?o:c;let g=0;for(let m=f;m>=0;m--,g++)!0===g<l.length?h=i[o-g]+l[c-g]+t[0]:h=i[o-g]+t[0],t[0]=h/10,!0===g>=i.length?i=Rh(new Uint8Array([h%10]),i):i[o-g]=h%10;return t[0]>0&&(i=Rh(t,i)),i}function Hf(a){if(a>=Za.length)for(let e=Za.length;e<=a;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=Rh(t,s)),Za.push(s)}return Za[a]}function pg(a,e){let t=0;const s=new Uint8Array(a),n=new Uint8Array(e),i=s.slice(0),o=i.length-1,l=n.slice(0),c=l.length-1;let h,f=0;for(let g=c;g>=0;g--,f++)h=i[o-f]-l[c-f]-t,!0===h<0?(t=1,i[o-f]=h+10):(t=0,i[o-f]=h);if(t>0)for(let g=o-c+1;g>=0;g--,f++)if(h=i[o-f]-t,h<0)t=1,i[o-f]=h+10;else{t=0,i[o-f]=h;break}return i.slice()}class df extends Ns(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=dd.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(Zm(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.length<n&&(n-o.length>1&&(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=pg(Hf(s),t),o="-"):t=Ag(t,Hf(s))),s++,n>>=1}for(let c=0;c<t.length;c++)t[c]&&(l=!0),l&&(o+=Lf.charAt(t[c]));return l===!1&&(o+=Lf.charAt(0)),o}}Dd=df;df.NAME="IntegerValueBlock";Object.defineProperty(Dd.prototype,"valueHex",{set:function(a){this.valueHexView=new Uint8Array(a),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var cc;class S extends je{constructor(e={}){super(e,df),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Ou(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Ou();const t=BigInt(e),s=new cf,n=t.toString(16).replace(/^-/,""),i=new Uint8Array(H.FromHex(n));if(t<0){const l=new Uint8Array(i.length+(i[0]&128?1:0));l[0]|=128;const h=BigInt(`0x${H.ToHex(l)}`)+t,f=L.toUint8Array(H.FromHex(h.toString(16)));f[0]|=128,s.write(f)}else i[0]&128&&s.write(new Uint8Array([0])),s.write(i);return new cc({valueHex:s.final()})}convertToDER(){const e=new cc({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new cc({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}cc=S;D.Integer=cc;S.NAME="INTEGER";var Pd;class tr extends S{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}Pd=tr;D.Enumerated=Pd;tr.NAME="ENUMERATED";class Dh extends Ns(Ze){constructor({valueDec:e=-1,isFirstSid:t=!1,...s}={}){super(s),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,s){if(!s)return t;const n=L.toUint8Array(e);if(!Es(this,n,t,s))return-1;const i=n.subarray(t,t+s);this.valueHexView=new Uint8Array(s);for(let l=0;l<s&&(this.valueHexView[l]=i[l]&127,this.blockLength++,(i[l]&128)!==0);l++);const o=new Uint8Array(this.blockLength);for(let l=0;l<this.blockLength;l++)o[l]=this.valueHexView[l];return this.valueHexView=o,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=er(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Ou();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const s=new Uint8Array(t.length/7);for(let n=0;n<s.length;n++)s[n]=parseInt(t.slice(n*7,n*7+7),2)+(n+1<s.length?128:0);this.fromBER(s.buffer,0,s.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const n=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=n[o]|128;return i[this.blockLength-1]=n[this.blockLength-1],i.buffer}const t=ks(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Qt;const s=new Uint8Array(t.byteLength);if(!e){const n=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)s[o]=n[o]|128;s[i]=n[i]}return s}toString(){let e="";if(this.isHexOnly)e=H.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Dh.NAME="sidBlock";class Ld extends Ze{constructor({value:e=st,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,s){let n=t;for(;s>0;){const i=new Dh;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;s<this.value.length;s++){const n=this.value[s].toBER(e);if(n.byteLength===0)return this.error=this.value[s].error,Qt;t.push(n)}return lf(t)}fromString(e){this.value=[];let t=0,s=0,n="",i=!1;do if(s=e.indexOf(".",t),s===-1?n=e.substring(t):n=e.substring(t,s),t=s+1,i){const o=this.value[0];let l=0;switch(o.valueDec){case 0:break;case 1:l=40;break;case 2:l=80;break;default:this.value=[];return}const c=parseInt(n,10);if(isNaN(c))return;o.valueDec=c+l,i=!1}else{const o=new Dh;if(n>Number.MAX_SAFE_INTEGER){Ou();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;s<this.value.length;s++){t=this.value[s].isHexOnly;let n=this.value[s].toString();s!==0&&(e=`${e}.`),t?(n=`{${n}}`,this.value[s].isFirstSid?e=`2.{${n} - 80}`:e+=n):e+=n}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Ld.NAME="ObjectIdentifierValueBlock";var Ud;class T extends je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Ld),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Ud=T;D.ObjectIdentifier=Ud;T.NAME="OBJECT IDENTIFIER";class Ph extends Ns(nr){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,s){if(s===0)return t;const n=L.toUint8Array(e);if(!Es(this,n,t,s))return-1;const i=n.subarray(t,t+s);this.valueHexView=new Uint8Array(s);for(let l=0;l<s&&(this.valueHexView[l]=i[l]&127,this.blockLength++,(i[l]&128)!==0);l++);const o=new Uint8Array(this.blockLength);for(let l=0;l<this.blockLength;l++)o[l]=this.valueHexView[l];return this.valueHexView=o,(i[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=er(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const n=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=n[o]|128;return i[this.blockLength-1]=n[this.blockLength-1],i.buffer}const t=ks(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",Qt;const s=new Uint8Array(t.byteLength);if(!e){const n=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)s[o]=n[o]|128;s[i]=n[i]}return s.buffer}toString(){let e="";return this.isHexOnly?e=H.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Ph.NAME="relativeSidBlock";class Hd extends Ze{constructor({value:e=st,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,s){let n=t;for(;s>0;){const i=new Ph;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;n<this.value.length;n++){const i=this.value[n].toBER(e);if(i.byteLength===0)return this.error=this.value[n].error,Qt;s.push(i)}return lf(s)}fromString(e){this.value=[];let t=0,s=0,n="";do{s=e.indexOf(".",t),s===-1?n=e.substring(t):n=e.substring(t,s),t=s+1;const i=new Ph;if(i.valueDec=parseInt(n,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(s!==-1);return!0}toString(){let e="",t=!1;for(let s=0;s<this.value.length;s++){t=this.value[s].isHexOnly;let n=this.value[s].toString();s!==0&&(e=`${e}.`),t&&(n=`{${n}}`),e+=n}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Hd.NAME="RelativeObjectIdentifierValueBlock";var _d;class Md extends je{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Hd),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}_d=Md;D.RelativeObjectIdentifier=_d;Md.NAME="RelativeObjectIdentifier";var $d;class d extends w{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}$d=d;D.Sequence=$d;d.NAME="SEQUENCE";var Kd;class pe extends w{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}Kd=pe;D.Set=Kd;pe.NAME="SET";class Jd extends Ns(Ze){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=st}toJSON(){return{...super.toJSON(),value:this.value}}}Jd.NAME="StringValueBlock";class jd extends Jd{}jd.NAME="SimpleStringValueBlock";class dt extends pd{constructor({...e}={}){super(e,jd)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,L.toUint8Array(e))}fromString(e){const t=e.length,s=this.valueBlock.valueHexView=new Uint8Array(t);for(let n=0;n<t;n++)s[n]=e.charCodeAt(n);this.valueBlock.value=e}}dt.NAME="SIMPLE STRING";class Fd extends dt{fromBuffer(e){this.valueBlock.valueHexView=L.toUint8Array(e);try{this.valueBlock.value=H.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=H.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(H.FromUtf8String(e)),this.valueBlock.value=e}}Fd.NAME="Utf8StringValueBlock";var qd;class kt extends Fd{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}qd=kt;D.Utf8String=qd;kt.NAME="UTF8String";class Wd extends dt{fromBuffer(e){this.valueBlock.value=H.ToUtf16String(e),this.valueBlock.valueHexView=L.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(H.FromUtf16String(e))}}Wd.NAME="BmpStringValueBlock";var Gd;class sr extends Wd{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}Gd=sr;D.BmpString=Gd;sr.NAME="BMPString";class Yd extends dt{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),s=new Uint8Array(t);for(let n=0;n<s.length;n+=4)s[n]=s[n+3],s[n+1]=s[n+2],s[n+2]=0,s[n+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,s=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let n=0;n<t;n++){const i=ks(e.charCodeAt(n),8),o=new Uint8Array(i);if(o.length>4)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}}Yd.NAME="UniversalStringValueBlock";var Qd;class wc extends Yd{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}Qd=wc;D.UniversalString=Qd;wc.NAME="UniversalString";var Xd;class Ua extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}Xd=Ua;D.NumericString=Xd;Ua.NAME="NumericString";var Zd;class Rt extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}Zd=Rt;D.PrintableString=Zd;Rt.NAME="PrintableString";var zd;class yc extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}zd=yc;D.TeletexString=zd;yc.NAME="TeletexString";var em;class mf extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}em=mf;D.VideotexString=em;mf.NAME="VideotexString";var tm;class Fu extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}tm=Fu;D.IA5String=tm;Fu.NAME="IA5String";var sm;class gf extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}sm=gf;D.GraphicString=sm;gf.NAME="GraphicString";var nm;class qu extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}nm=qu;D.VisibleString=nm;qu.NAME="VisibleString";var im;class wf extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}im=wf;D.GeneralString=im;wf.NAME="GeneralString";var rm;class yf extends dt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}rm=yf;D.CharacterString=rm;yf.NAME="CharacterString";var am;class Fa extends qu{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<e.length;n++)this.valueBlock.valueHexView[n]=e.charCodeAt(n)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,L.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),s=new Uint8Array(t);for(let n=0;n<e.length;n++)s[n]=e.charCodeAt(n);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const s=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(s===null){this.error="Wrong input string for conversion";return}const n=parseInt(s[1],10);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]=lt(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=lt(this.month,2),t[2]=lt(this.day,2),t[3]=lt(this.hour,2),t[4]=lt(this.minute,2),t[5]=lt(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}}}am=Fa;D.UTCTime=am;Fa.NAME="UTCTime";var om;class ue extends Fa{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,m=s.indexOf("+"),b="";if(m===-1&&(m=s.indexOf("-"),g=-1),m!==-1){if(b=s.substring(m+1),s=s.substring(0,m),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 f=o.exec(n);if(f===null)throw new Error("Wrong input string for conversion");for(let g=1;g<f.length;g++)switch(g){case 1:this.year=parseInt(f[g],10);break;case 2:this.month=parseInt(f[g],10);break;case 3:this.day=parseInt(f[g],10);break;case 4:this.hour=parseInt(f[g],10)+l;break;case 5:this.minute=parseInt(f[g],10)+c;break;case 6:this.second=parseInt(f[g],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){const g=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=g.getUTCFullYear(),this.month=g.getUTCMonth(),this.day=g.getUTCDay(),this.hour=g.getUTCHours(),this.minute=g.getUTCMinutes(),this.second=g.getUTCSeconds(),this.millisecond=g.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){const t=[];return t.push(lt(this.year,4)),t.push(lt(this.month,2)),t.push(lt(this.day,2)),t.push(lt(this.hour,2)),t.push(lt(this.minute,2)),t.push(lt(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(lt(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}om=ue;D.GeneralizedTime=om;ue.NAME="GeneralizedTime";var lm;let cm=class extends kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};lm=cm;D.DATE=lm;cm.NAME="DATE";var um;class hm extends kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}um=hm;D.TimeOfDay=um;hm.NAME="TimeOfDay";var fm;class dm extends kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}fm=dm;D.DateTime=fm;dm.NAME="DateTime";var mm;class gm extends kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}mm=gm;D.Duration=mm;gm.NAME="Duration";var wm;class ym extends kt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}wm=ym;D.TIME=wm;ym.NAME="TIME";class K{constructor({name:e=st,optional:t=!1}={}){this.name=e,this.optional=t}}class he extends K{constructor({value:e=[],...t}={}){super(t),this.value=e}}class J extends K{constructor({value:e=new K,local:t=!1,...s}={}){super(s),this.value=e,this.local=t}}class Ru{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=L.toUint8Array(e)}constructor({data:e=ju}={}){this.dataView=L.toUint8Array(e)}fromBER(e,t,s){const n=t+s;return this.dataView=L.toUint8Array(e).subarray(t,n),n}toBER(e){return this.dataView.slice().buffer}}function N(a,e,t){if(t instanceof he){for(const i of t.value)if(N(a,e,i).verified)return{verified:!0,result:a};{const i={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(Zu)&&(i.name=t.name),i}}if(t instanceof K)return t.hasOwnProperty(Zu)&&(a[t.name]=e),{verified:!0,result:a};if(!(a instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(sg in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(ag in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(og in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const s=t.idBlock.toBER(!1);if(s.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(t.idBlock.fromBER(s,0,s.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(t.idBlock.hasOwnProperty(ng)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagClass!==e.idBlock.tagClass)return{verified:!1,result:a};if(t.idBlock.hasOwnProperty(ig)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagNumber!==e.idBlock.tagNumber)return{verified:!1,result:a};if(t.idBlock.hasOwnProperty(rg)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:a};if(!(tg in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:a};if(t.idBlock.isHexOnly){if(!(Uf in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const i=t.idBlock.valueHexView,o=e.idBlock.valueHexView;if(i.length!==o.length)return{verified:!1,result:a};for(let l=0;l<i.length;l++)if(i[l]!==o[1])return{verified:!1,result:a}}if(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&(a[t.name]=e)),t instanceof D.Constructed){let i=0,o={verified:!1,result:{error:"Unknown error"}},l=t.valueBlock.value.length;if(l>0&&t.valueBlock.value[0]instanceof J&&(l=e.valueBlock.value.length),l===0)return{verified:!0,result:a};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let c=!0;for(let h=0;h<t.valueBlock.value.length;h++)c=c&&(t.valueBlock.value[h].optional||!1);return c?{verified:!0,result:a}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&delete a[t.name]),a.error="Inconsistent object length",{verified:!1,result:a})}for(let c=0;c<l;c++)if(c-i>=e.valueBlock.value.length){if(t.valueBlock.value[c].optional===!1){const h={verified:!1,result:a};return a.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&(delete a[t.name],h.name=t.name)),h}}else if(t.valueBlock.value[0]instanceof J){if(o=N(a,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 a[t.name]),o;if(Zu in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let h={};lg in t.valueBlock.value[0]&&t.valueBlock.value[0].local?h=e:h=a,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(a,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 a[t.name]),o;if(o.verified===!1){const c={verified:!1,result:a};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,st),t.name&&(delete a[t.name],c.name=t.name)),c}return{verified:!0,result:a}}if(t.primitiveSchema&&Uf in e.valueBlock){const i=hf(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 a[t.name],o.name=t.name)),o}return N(a,i.result,t.primitiveSchema)}return{verified:!0,result:a}}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;t++)this._view[t]=e.stub}else this.length=0}set buffer(e){this._buffer=e,this._view=new Uint8Array(this._buffer)}get buffer(){return this._buffer}set view(e){this._buffer=new ArrayBuffer(e.length),this._view=new Uint8Array(this._buffer),this._view.set(e)}get view(){return this._view}get length(){return this.view.byteLength}set length(e){this._buffer=new ArrayBuffer(e),this._view=new Uint8Array(this._buffer)}clear(){this._buffer=new ArrayBuffer(0),this._view=new Uint8Array(this._buffer)}fromArrayBuffer(e){this._buffer=e,this._view=new Uint8Array(this._buffer)}fromUint8Array(e){this.fromArrayBuffer(new Uint8Array(e).buffer)}fromString(e){const t=e.length;this.length=t;for(let s=0;s<t;s++)this.view[s]=e.charCodeAt(s)}toString(e=0,t=this.view.length-e){let s="";(e>=this.view.length||e<0)&&(e=0),(t>=this.view.length||t<0)&&(t=this.view.length-e);for(let n=e;n<e+t;n++)s+=String.fromCharCode(this.view[n]);return s}fromHexString(e){const t=e.length;this.buffer=new ArrayBuffer(t>>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<t;o++)o%2?(i|=s.get(e.charAt(o)),this.view[n]=i,n++):i=s.get(e.charAt(o))<<4}toHexString(e=0,t=this.view.length-e){let s="";(e>=this.view.length||e<0)&&(e=0),(t>=this.view.length||t<0)&&(t=this.view.length-e);for(let n=e;n<e+t;n++){const i=this.view[n].toString(16).toUpperCase();s=s+(i.length==1?"0":"")+i}return s}copy(e=0,t=this.length-e){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,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;t<e.length;t++)if(this.view[t]!=e.view[t])return!1;return!0}isEqualView(e){if(e.length!=this.view.length)return!1;for(let t=0;t<e.length;t++)if(this.view[t]!=e[t])return!1;return!0}findPattern(e,t,s,n){const{start:i,length:o,backward:l}=this.prepareFindParameters(t,s,n),c=e.length;if(c>o)return-1;const h=[];for(let f=0;f<c;f++)h.push(e.view[f]);for(let f=0;f<=o-c;f++){let g=!0;const m=l?i-c-f:i+f;for(let b=0;b<c;b++)if(this.view[b+m]!=h[b]){g=!1;break}if(g)return l?i-c-f:i+c+f}return-1}findFirstIn(e,t,s,n){const{start:i,length:o,backward:l}=this.prepareFindParameters(t,s,n),c={id:-1,position:l?0:i+o,length:0};for(let h=0;h<e.length;h++){const f=this.findPattern(e[h],i,o,l);if(f!=-1){let g=!1;const m=e[h].length;l?f-m>=c.position-c.length&&(g=!0):f-m<=c.position-c.length&&(g=!0),g&&(c.position=f,c.id=h,c.length=m)}}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 f=!0;const g=n+h;for(let m=0;m<l;m++)if(this.view[m+g]!=c[m]){f=!1;break}f&&(o.push(n+l+h),h+=l-1)}return o}findFirstNotIn(e,t,s,n){let{start:i,length:o,backward:l}=this.prepareFindParameters(t,s,n);const c={left:{id:-1,position:i},right:{id:-1,position:0},value:new ge};let h=o;for(;h>0;){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 f=c.right;c.right=c.left,c.left=f}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 f=new ge({buffer:this._buffer.slice(i,i+o)});return{position:h,value:f}}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 f=this.findAllPatternIn(t,o,l);if(!Array.isArray(f)||f.length==0)return i;for(;c<h.length&&f.length!=0;){if(h[0]==f[0]){i.push({left:h[0],right:f[0]}),h.splice(0,1),f.splice(0,1);continue}if(h[c]>f[0])break;for(;h[c]<f[0]&&(c++,!(c>=h.length)););i.push({left:h[c-1],right:f[0]}),h.splice(c-1,1),f.splice(0,1),c=0}return i.sort((g,m)=>g.left-m.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 f=this.findAllIn(t,i,o);if(f.length==0)return l;for(;c<h.length&&f.length!=0;){if(h[0].position==f[0].position){l.push({left:h[0],right:f[0]}),h.splice(0,1),f.splice(0,1);continue}if(h[c].position>f[0].position)break;for(;h[c].position<f[0].position&&(c++,!(c>=h.length)););l.push({left:h[c-1],right:f[0]}),h.splice(c-1,1),f.splice(0,1),c=0}return l.sort((g,m)=>g.left.position-m.left.position),l}replacePattern(e,t,s,n,i=null){let o=[],l;const c={status:-1,searchPatternPositions:[],replacePatternPositions:[]},{start:h,length:f}=this.prepareFindParameters(s,n);if(i==null){if(o=this.findAllIn([e],h,f),o.length==0)return c}else o=i;c.searchPatternPositions.push(...Array.from(o,A=>A.position));const g=e.length-t.length,m=new ArrayBuffer(this.view.length-o.length*g),b=new Uint8Array(m);for(b.set(new Uint8Array(this.buffer,0,h)),l=0;l<o.length;l++){const A=l==0?h:o[l-1].position;b.set(new Uint8Array(this.buffer,A,o[l].position-e.length-A),A-l*g),b.set(t.view,o[l].position-e.length-l*g),c.replacePatternPositions.push(o[l].position-e.length-l*g)}return l--,b.set(new Uint8Array(this.buffer,o[l].position,this.length-o[l].position),o[l].position-e.length+t.length-l*g),this.buffer=m,this.view=new Uint8Array(this.buffer),c.status=1,c}skipPatterns(e,t,s,n){const{start:i,length:o,backward:l}=this.prepareFindParameters(t,s,n);let c=i;for(let h=0;h<e.length;h++){const f=e[h].length,g=l?c-f:c;let m=!0;for(let b=0;b<f;b++)if(this.view[b+g]!=e[h].view[b]){m=!1;break}if(m){if(h=-1,l){if(c-=f,c<=0)return c}else if(c+=f,c>=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;h<o;h++){for(let f=0;f<e.length;f++){const g=e[f].length,m=l?i-h-g:i+h;let b=!0;for(let A=0;A<g;A++)if(this.view[A+m]!=e[f].view[A]){b=!1;break}if(b){c=l?i-h:i+h;break}}if(c!=-1)break}return c}prepareFindParameters(e=null,t=null,s=!1){return e===null&&(e=s?this.length:0),e>this.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 bg=16777216;class Vn{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(s<this.start-e.length-t)return-1}else if(s>this.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.position<this.start-e[s.id].length-t)return{id:-1,position:this.backward?0:this.start+this.length}}else if(s.position>this.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.position<this._start-e[s.right.id].length-t)return{left:{id:-1,position:this._start},right:{id:-1,position:0},value:new ge}}else if(s.left.id!=-1&&s.left.position>this._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.position<this._start-n.value.length-s)return{position:-1,value:new ge}}else if(n.position>this._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].right<this.start-t.length-s)return[]}else if(i[0].left>this.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.position<this.start-t[i[0].right.id].length-s)return[]}else if(i[0].left.position>this.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._length<e&&(e=this._length);let s;if(this.backward){const n=this._stream.view.subarray(this._length-e,this._length);s=new Uint8Array(e);for(let i=0;i<e;i++)s[e-1-i]=n[i]}else s=this._stream.view.subarray(this._start,this._start+e);return t&&(this.start+=this.backward?-1*e:e),s}getUint16(e=!0){const t=this.getBlock(2,e);return t.length<2?0:t[0]<<8|t[1]}getInt16(e=!0){const t=this.getUint16(e),s=32768;return t&s?-(s-(t^s)):t}getUint24(e=!0){const t=this.getBlock(4,e);return t.length<3?0:t[0]<<16|t[1]<<8|t[2]}getUint32(e=!0){const t=this.getBlock(4,e);return t.length<4?0:t[0]*bg+(t[1]<<16)+(t[2]<<8)+t[3]}getInt32(e=!0){const t=this.getUint32(e),s=2147483648;return t&s?-(s-(t^s)):t}beforeAppend(e){this._start+e>this._stream.length&&(e>this.appendBlock&&(this.appendBlock=e+Vn.APPEND_BLOCK),this._stream.realloc(this._stream.length+this.appendBlock))}}Vn.APPEND_BLOCK=1e3;function kg(a){return a instanceof Uint8Array||a!=null&&typeof a=="object"&&a.constructor.name==="Uint8Array"}function vm(a,...e){if(!kg(a))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(a.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${a.length}`)}function _f(a,e=!0){if(a.destroyed)throw new Error("Hash instance has been destroyed");if(e&&a.finished)throw new Error("Hash#digest() has already been called")}function Eg(a,e){vm(a);const t=e.outputLen;if(a.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}const zu=a=>new DataView(a.buffer,a.byteOffset,a.byteLength),Ht=(a,e)=>a<<32-e|a>>>e,eh=(a,e)=>a<<e|a>>>32-e>>>0;new Uint8Array(new Uint32Array([287454020]).buffer)[0];function Ng(a){if(typeof a!="string")throw new Error(`utf8ToBytes expected string, got ${typeof a}`);return new Uint8Array(new TextEncoder().encode(a))}function Sm(a){return typeof a=="string"&&(a=Ng(a)),vm(a),a}class Cg{clone(){return this._cloneInto()}}function Wu(a){const e=s=>a().update(Sm(s)).digest(),t=a();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>a(),e}function Bg(a,e,t,s){if(typeof a.setBigUint64=="function")return a.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;a.setUint32(e+c,o,s),a.setUint32(e+h,l,s)}const Am=(a,e,t)=>a&e^~a&t,pm=(a,e,t)=>a&e^a&t^e&t;class vf extends Cg{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=zu(this.buffer)}update(e){_f(this);const{view:t,buffer:s,blockLen:n}=this;e=Sm(e);const i=e.length;for(let o=0;o<i;){const l=Math.min(n-this.pos,i-o);if(l===n){const c=zu(e);for(;n<=i-o;o+=n)this.process(c,o);continue}s.set(e.subarray(o,o+l),this.pos),this.pos+=l,o+=l,this.pos===n&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){_f(this),Eg(e,this),this.finished=!0;const{buffer:t,view:s,blockLen:n,isLE:i}=this;let{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(s,0),o=0);for(let g=o;g<n;g++)t[g]=0;Bg(s,n-8,BigInt(this.length*8),i),this.process(s,0);const l=zu(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const h=c/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let g=0;g<h;g++)l.setUint32(4*g,f[g],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const s=e.slice(0,t);return this.destroy(),s}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:s,length:n,finished:i,destroyed:o,pos:l}=this;return e.length=n,e.pos=l,e.finished=i,e.destroyed=o,n%t&&e.buffer.set(s),e}}const za=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),Vs=new Uint32Array(80);let Ig=class extends vf{constructor(){super(64,20,8,!1),this.A=za[0]|0,this.B=za[1]|0,this.C=za[2]|0,this.D=za[3]|0,this.E=za[4]|0}get(){const{A:e,B:t,C:s,D:n,E:i}=this;return[e,t,s,n,i]}set(e,t,s,n,i){this.A=e|0,this.B=t|0,this.C=s|0,this.D=n|0,this.E=i|0}process(e,t){for(let c=0;c<16;c++,t+=4)Vs[c]=e.getUint32(t,!1);for(let c=16;c<80;c++)Vs[c]=eh(Vs[c-3]^Vs[c-8]^Vs[c-14]^Vs[c-16],1);let{A:s,B:n,C:i,D:o,E:l}=this;for(let c=0;c<80;c++){let h,f;c<20?(h=Am(n,i,o),f=1518500249):c<40?(h=n^i^o,f=1859775393):c<60?(h=pm(n,i,o),f=2400959708):(h=n^i^o,f=3395469782);const g=eh(s,5)+h+l+f+Vs[c]|0;l=o,o=i,i=eh(n,30),n=s,s=g}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,this.set(s,n,i,o,l)}roundClean(){Vs.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}};const Vg=Wu(()=>new Ig),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]),xs=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Os=new Uint32Array(64);let Og=class extends vf{constructor(){super(64,32,8,!1),this.A=xs[0]|0,this.B=xs[1]|0,this.C=xs[2]|0,this.D=xs[3]|0,this.E=xs[4]|0,this.F=xs[5]|0,this.G=xs[6]|0,this.H=xs[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)Os[g]=e.getUint32(t,!1);for(let g=16;g<64;g++){const m=Os[g-15],b=Os[g-2],A=Ht(m,7)^Ht(m,18)^m>>>3,E=Ht(b,17)^Ht(b,19)^b>>>10;Os[g]=E+Os[g-7]+A+Os[g-16]|0}let{A:s,B:n,C:i,D:o,E:l,F:c,G:h,H:f}=this;for(let g=0;g<64;g++){const m=Ht(l,6)^Ht(l,11)^Ht(l,25),b=f+m+Am(l,c,h)+xg[g]+Os[g]|0,E=(Ht(s,2)^Ht(s,13)^Ht(s,22))+pm(s,n,i)|0;f=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,f=f+this.H|0,this.set(s,n,i,o,l,c,h,f)}roundClean(){Os.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Rg=Wu(()=>new Og),Cc=BigInt(2**32-1),Lh=BigInt(32);function bm(a,e=!1){return e?{h:Number(a&Cc),l:Number(a>>Lh&Cc)}:{h:Number(a>>Lh&Cc)|0,l:Number(a&Cc)|0}}function Tg(a,e=!1){let t=new Uint32Array(a.length),s=new Uint32Array(a.length);for(let n=0;n<a.length;n++){const{h:i,l:o}=bm(a[n],e);[t[n],s[n]]=[i,o]}return[t,s]}const Dg=(a,e)=>BigInt(a>>>0)<<Lh|BigInt(e>>>0),Pg=(a,e,t)=>a>>>t,Lg=(a,e,t)=>a<<32-t|e>>>t,Ug=(a,e,t)=>a>>>t|e<<32-t,Hg=(a,e,t)=>a<<32-t|e>>>t,_g=(a,e,t)=>a<<64-t|e>>>t-32,Mg=(a,e,t)=>a>>>t-32|e<<64-t,$g=(a,e)=>e,Kg=(a,e)=>a,Jg=(a,e,t)=>a<<t|e>>>32-t,jg=(a,e,t)=>e<<t|a>>>32-t,Fg=(a,e,t)=>e<<t-32|a>>>64-t,qg=(a,e,t)=>a<<t-32|e>>>64-t;function Wg(a,e,t,s){const n=(e>>>0)+(s>>>0);return{h:a+t+(n/2**32|0)|0,l:n|0}}const Gg=(a,e,t)=>(a>>>0)+(e>>>0)+(t>>>0),Yg=(a,e,t,s)=>e+t+s+(a/2**32|0)|0,Qg=(a,e,t,s)=>(a>>>0)+(e>>>0)+(t>>>0)+(s>>>0),Xg=(a,e,t,s,n)=>e+t+s+n+(a/2**32|0)|0,Zg=(a,e,t,s,n)=>(a>>>0)+(e>>>0)+(t>>>0)+(s>>>0)+(n>>>0),zg=(a,e,t,s,n,i)=>e+t+s+n+i+(a/2**32|0)|0,W={fromBig:bm,split:Tg,toBig:Dg,shrSH:Pg,shrSL:Lg,rotrSH:Ug,rotrSL:Hg,rotrBH:_g,rotrBL:Mg,rotr32H:$g,rotr32L:Kg,rotlSH:Jg,rotlSL:jg,rotlBH:Fg,rotlBL:qg,add:Wg,add3L:Gg,add3H:Yg,add4L:Qg,add4H:Xg,add5H:zg,add5L:Zg},[ew,tw]=W.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(a=>BigInt(a))),Rs=new Uint32Array(80),Ts=new Uint32Array(80);let km=class extends vf{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:f,Fh:g,Fl:m,Gh:b,Gl:A,Hh:E,Hl:y}=this;return[e,t,s,n,i,o,l,c,h,f,g,m,b,A,E,y]}set(e,t,s,n,i,o,l,c,h,f,g,m,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=f|0,this.Fh=g|0,this.Fl=m|0,this.Gh=b|0,this.Gl=A|0,this.Hh=E|0,this.Hl=y|0}process(e,t){for(let I=0;I<16;I++,t+=4)Rs[I]=e.getUint32(t),Ts[I]=e.getUint32(t+=4);for(let I=16;I<80;I++){const V=Rs[I-15]|0,R=Ts[I-15]|0,M=W.rotrSH(V,R,1)^W.rotrSH(V,R,8)^W.shrSH(V,R,7),te=W.rotrSL(V,R,1)^W.rotrSL(V,R,8)^W.shrSL(V,R,7),j=Rs[I-2]|0,z=Ts[I-2]|0,ye=W.rotrSH(j,z,19)^W.rotrBH(j,z,61)^W.shrSH(j,z,6),se=W.rotrSL(j,z,19)^W.rotrBL(j,z,61)^W.shrSL(j,z,6),ae=W.add4L(te,se,Ts[I-7],Ts[I-16]),Xt=W.add4H(ae,M,ye,Rs[I-7],Rs[I-16]);Rs[I]=Xt|0,Ts[I]=ae|0}let{Ah:s,Al:n,Bh:i,Bl:o,Ch:l,Cl:c,Dh:h,Dl:f,Eh:g,El:m,Fh:b,Fl:A,Gh:E,Gl:y,Hh:O,Hl:x}=this;for(let I=0;I<80;I++){const V=W.rotrSH(g,m,14)^W.rotrSH(g,m,18)^W.rotrBH(g,m,41),R=W.rotrSL(g,m,14)^W.rotrSL(g,m,18)^W.rotrBL(g,m,41),M=g&b^~g&E,te=m&A^~m&y,j=W.add5L(x,R,te,tw[I],Ts[I]),z=W.add5H(j,O,V,M,ew[I],Rs[I]),ye=j|0,se=W.rotrSH(s,n,28)^W.rotrBH(s,n,34)^W.rotrBH(s,n,39),ae=W.rotrSL(s,n,28)^W.rotrBL(s,n,34)^W.rotrBL(s,n,39),Xt=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=m|0,{h:g,l:m}=W.add(h|0,f|0,z|0,ye|0),h=l|0,f=c|0,l=i|0,c=o|0,i=s|0,o=n|0;const fe=W.add3L(ye,ae,_e);s=W.add3H(fe,z,se,Xt),n=fe|0}({h:s,l:n}=W.add(this.Ah|0,this.Al|0,s|0,n|0)),{h:i,l:o}=W.add(this.Bh|0,this.Bl|0,i|0,o|0),{h:l,l:c}=W.add(this.Ch|0,this.Cl|0,l|0,c|0),{h,l:f}=W.add(this.Dh|0,this.Dl|0,h|0,f|0),{h:g,l:m}=W.add(this.Eh|0,this.El|0,g|0,m|0),{h:b,l:A}=W.add(this.Fh|0,this.Fl|0,b|0,A|0),{h:E,l:y}=W.add(this.Gh|0,this.Gl|0,E|0,y|0),{h:O,l:x}=W.add(this.Hh|0,this.Hl|0,O|0,x|0),this.set(s,n,i,o,l,c,h,f,g,m,b,A,E,y,O,x)}roundClean(){Rs.fill(0),Ts.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)}},sw=class extends km{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 nw=Wu(()=>new km),iw=Wu(()=>new sw);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=Be(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 An(a){let e=!1,t=u;const s=a.trim();for(let n=0;n<s.length;n++)s.charCodeAt(n)===32?e===!1&&(e=!0):(e&&(t+=" ",e=!1),t+=s[n]);return t.toLowerCase()}const eo="type",th="value";class kn extends k{constructor(e={}){super(),this.type=r(e,eo,kn.defaultValues(eo)),this.value=r(e,th,kn.defaultValues(th)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case eo:return u;case th:return{};default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.type||u}),new K({name:t.value||u})]})}fromSchema(e){C(e,[eo,"typeValue"]);const t=N(e,e,kn.schema({names:{type:eo,value:"typeValue"}}));p.assertSchema(t,this.className),this.type=t.result.type.valueBlock.toString(),this.value=t.result.typeValue}toSchema(){return new d({value:[new T({value:this.type}),this.value]})}toJSON(){const e={type:this.type};return Object.keys(this.value).length!==0?e.value=this.value.toJSON():e.value=this.value,e}isEqual(e){const t=[kt.blockName(),sr.blockName(),wc.blockName(),Ua.blockName(),Rt.blockName(),yc.blockName(),mf.blockName(),Fu.blockName(),gf.blockName(),qu.blockName(),wf.blockName(),yf.blockName()];if(e instanceof ArrayBuffer)return L.isEqual(this.value.valueBeforeDecodeView,e);if(e.constructor.blockName()===kn.blockName()){if(this.type!==e.type)return!1;const s=[!1,!1],n=this.value.constructor.blockName();for(const o of t)n===o&&(s[0]=!0),e.value.constructor.blockName()===o&&(s[1]=!0);if(s[0]!==s[1])return!1;if(s[0]&&s[1]){const o=An(this.value.valueBlock.value),l=An(e.value.valueBlock.value);if(o.localeCompare(l)!==0)return!1}else if(!L.isEqual(this.value.valueBeforeDecodeView,e.value.valueBeforeDecodeView))return!1;return!0}return!1}}kn.CLASS_NAME="AttributeTypeAndValue";const Ln="typesAndValues",Bc="valueBeforeDecode",Mf="RDN";class re extends k{constructor(e={}){super(),this.typesAndValues=r(e,Ln,re.defaultValues(Ln)),this.valueBeforeDecode=r(e,Bc,re.defaultValues(Bc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ln:return[];case Bc:return be;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ln:return t.length===0;case Bc:return t.byteLength===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.repeatedSequence||u,value:new pe({value:[new J({name:t.repeatedSet||u,value:kn.schema(t.typeAndValue||{})})]})})]})}fromSchema(e){C(e,[Mf,Ln]);const t=N(e,e,re.schema({names:{blockName:Mf,repeatedSet:Ln}}));p.assertSchema(t,this.className),Ln in t.result&&(this.typesAndValues=Array.from(t.result.typesAndValues,s=>new kn({schema:s}))),this.valueBeforeDecode=t.result.RDN.valueBeforeDecodeView.slice().buffer}toSchema(){if(this.valueBeforeDecode.byteLength===0)return new d({value:[new pe({value:Array.from(this.typesAndValues,t=>t.toSchema())})]});const e=Be(this.valueBeforeDecode);if(p.assert(e,"RelativeDistinguishedNames"),!(e.result instanceof d))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 mo="type",go="value";function rw(a={},e=!1){const t=r(a,"names",{});return new d({optional:e,value:[new w({optional:!0,idBlock:{tagClass:2,tagNumber:1},name:t.country_name||u,value:[new he({value:[new Ua,new Rt]})]}),new w({optional:!0,idBlock:{tagClass:2,tagNumber:2},name:t.administration_domain_name||u,value:[new he({value:[new Ua,new Rt]})]}),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 Ua,new Rt]})]}),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 Rt})]})]})}function aw(a=!1){return new d({optional:a,value:[new Rt,new Rt]})}function ow(a=!1){return new pe({optional:a,value:[new _({optional:!0,idBlock:{tagClass:3,tagNumber:0},isHexOnly:!0}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new K]})]})}class Z extends k{constructor(e={}){super(),this.type=r(e,mo,Z.defaultValues(mo)),this.value=r(e,go,Z.defaultValues(go)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case mo:return 9;case go:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case mo:return t===Z.defaultValues(e);case go:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(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:[rw(t.builtInStandardAttributes||{},!1),aw(!0),ow(!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 yc,new Rt,new wc,new kt,new sr]})]}),new w({idBlock:{tagClass:3,tagNumber:1},value:[new he({value:[new yc,new Rt,new wc,new kt,new sr]})]})]}),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,Z.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=Be(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 B({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=Be(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 Fu({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 Z.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}}Z.CLASS_NAME="GeneralName";const wo="accessMethod",yo="accessLocation",lw=[wo,yo];class Fi extends k{constructor(e={}){super(),this.accessMethod=r(e,wo,Fi.defaultValues(wo)),this.accessLocation=r(e,yo,Fi.defaultValues(yo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case wo:return u;case yo:return new Z;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.accessMethod||u}),Z.schema(t.accessLocation||{})]})}fromSchema(e){C(e,lw);const t=N(e,e,Fi.schema({names:{accessMethod:wo,accessLocation:{names:{blockName:yo}}}}));p.assertSchema(t,this.className),this.accessMethod=t.result.accessMethod.valueBlock.toString(),this.accessLocation=new Z({schema:t.result.accessLocation})}toSchema(){return new d({value:[new T({value:this.accessMethod}),this.accessLocation.toSchema()]})}toJSON(){return{accessMethod:this.accessMethod,accessLocation:this.accessLocation.toJSON()}}}Fi.CLASS_NAME="AccessDescription";const Ps="seconds",Ls="millis",Us="micros";class ct extends k{constructor(e={}){super(),Ps in e&&(this.seconds=r(e,Ps,ct.defaultValues(Ps))),Ls in e&&(this.millis=r(e,Ls,ct.defaultValues(Ls))),Us in e&&(this.micros=r(e,Us,ct.defaultValues(Us))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ps:case Ls:case Us:return 0;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ps:case Ls:case Us:return t===ct.defaultValues(e);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,[Ps,Ls,Us]);const t=N(e,e,ct.schema({names:{seconds:Ps,millis:Ls,micros:Us}}));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 d({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}}ct.CLASS_NAME="Accuracy";const Ic="algorithmId",to="algorithmParams",Em="algorithm",Uh="params",cw=[Em,Uh];class v extends k{constructor(e={}){super(),this.algorithmId=r(e,Ic,v.defaultValues(Ic)),to in e&&(this.algorithmParams=r(e,to,v.defaultValues(to))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ic:return u;case to:return new K;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ic:return t===u;case to:return t instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,cw);const t=N(e,e,v.schema({names:{algorithmIdentifier:Em,algorithmParams:Uh}}));p.assertSchema(t,this.className),this.algorithmId=t.result.algorithm.valueBlock.toString(),Uh 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 d({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 mr="altNames",uw=[mr];class qa extends k{constructor(e={}){super(),this.altNames=r(e,mr,qa.defaultValues(mr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===mr?[]:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.altNames||u,value:Z.schema()})]})}fromSchema(e){C(e,uw);const t=N(e,e,qa.schema({names:{altNames:mr}}));p.assertSchema(t,this.className),mr in t.result&&(this.altNames=Array.from(t.result.altNames,s=>new Z({schema:s})))}toSchema(){return new d({value:Array.from(this.altNames,e=>e.toSchema())})}toJSON(){return{altNames:Array.from(this.altNames,e=>e.toJSON())}}}qa.CLASS_NAME="AltName";const gr="type",wr="values",hw=[gr,wr];class oe extends k{constructor(e={}){super(),this.type=r(e,gr,oe.defaultValues(gr)),this.values=r(e,wr,oe.defaultValues(wr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case gr:return u;case wr:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case gr:return t===u;case wr:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,hw);const t=N(e,e,oe.schema({names:{type:gr,values:wr}}));p.assertSchema(t,this.className),this.type=t.result.type.valueBlock.toString(),this.values=t.result.values}toSchema(){return new d({value:[new T({value:this.type}),new pe({value:this.values})]})}toJSON(){return{type:this.type,values:Array.from(this.values,e=>e.toJSON())}}}oe.CLASS_NAME="Attribute";const vo="notBeforeTime",So="notAfterTime",fw=[vo,So];class Dt extends k{constructor(e={}){super(),this.notBeforeTime=r(e,vo,Dt.defaultValues(vo)),this.notAfterTime=r(e,So,Dt.defaultValues(So)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case vo:case So:return new Date(0,0,0);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new ue({name:t.notBeforeTime||u}),new ue({name:t.notAfterTime||u})]})}fromSchema(e){C(e,fw);const t=N(e,e,Dt.schema({names:{notBeforeTime:vo,notAfterTime:So}}));p.assertSchema(t,this.className),this.notBeforeTime=t.result.notBeforeTime.toDate(),this.notAfterTime=t.result.notAfterTime.toDate()}toSchema(){return new d({value:[new ue({valueDate:this.notBeforeTime}),new ue({valueDate:this.notAfterTime})]})}toJSON(){return{notBeforeTime:this.notBeforeTime,notAfterTime:this.notAfterTime}}}Dt.CLASS_NAME="AttCertValidityPeriod";const so="names",$f="generalNames";class Oe extends k{constructor(e={}){super(),this.names=r(e,so,Oe.defaultValues(so)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e==="names"?[]:super.defaultValues(e)}static schema(e={},t=!1){const s=r(e,so,{});return new d({optional:t,name:s.blockName||u,value:[new J({name:s.generalNames||u,value:Z.schema()})]})}fromSchema(e){C(e,[so,$f]);const t=N(e,e,Oe.schema({names:{blockName:so,generalNames:$f}}));p.assertSchema(t,this.className),this.names=Array.from(t.result.generalNames,s=>new Z({schema:s}))}toSchema(){return new d({value:Array.from(this.names,e=>e.toSchema())})}toJSON(){return{names:Array.from(this.names,e=>e.toJSON())}}}Oe.CLASS_NAME="GeneralNames";const dw="2.5.29.9",mw="2.5.29.14",gw="2.5.29.15",ww="2.5.29.16",Nm="2.5.29.17",Cm="2.5.29.18",Sf="2.5.29.19",yw="2.5.29.20",vw="2.5.29.27",Sw="2.5.29.21",Aw="2.5.29.24",Bm="2.5.29.28",Im="2.5.29.29",Vm="2.5.29.30",xm="2.5.29.31",Af="2.5.29.46",Om="2.5.29.32",wt="2.5.29.32.0",pw="1.3.6.1.4.1.311.21.10",Rm="2.5.29.33",pf="2.5.29.35",Tm="2.5.29.36",bw="2.5.29.37",kw="2.5.29.54",bf="1.3.6.1.5.5.7.1.1",Ew="1.3.6.1.5.5.7.1.11",Nw="1.3.6.1.4.1.11129.2.4.2",Cw="1.3.6.1.4.1.311.21.7",Bw="1.3.6.1.4.1.311.21.1",Iw="1.3.6.1.5.5.7.1.3",kf="1.2.840.113549.1.7.1",Dm="1.2.840.113549.1.7.2",Pm="1.2.840.113549.1.7.3",Lm="1.2.840.113549.1.7.6",Vw="1.2.840.113549.1.9.16.1.4",Hh="1.2.840.113549.1.9.22.1",xw="1.2.840.113549.1.9.22.2",Kf="1.2.840.113549.1.9.22.3",Jf="1.2.840.113549.1.9.23.1",Ow="1.3.6.1.5.5.7",Rw=`${Ow}.48`,zc=`${Rw}.1.1`,Mn="keyIdentifier",$n="authorityCertIssuer",Kn="authorityCertSerialNumber",Tw=[Mn,$n,Kn];class En extends k{constructor(e={}){super(),Mn in e&&(this.keyIdentifier=r(e,Mn,En.defaultValues(Mn))),$n in e&&(this.authorityCertIssuer=r(e,$n,En.defaultValues($n))),Kn in e&&(this.authorityCertSerialNumber=r(e,Kn,En.defaultValues(Kn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Mn:return new B;case $n:return[];case Kn:return new S;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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:Z.schema()})]}),new _({name:t.authorityCertSerialNumber||u,optional:!0,idBlock:{tagClass:3,tagNumber:2}})]})}fromSchema(e){C(e,Tw);const t=N(e,e,En.schema({names:{keyIdentifier:Mn,authorityCertIssuer:$n,authorityCertSerialNumber:Kn}}));p.assertSchema(t,this.className),Mn in t.result&&(this.keyIdentifier=new B({valueHex:t.result.keyIdentifier.valueBlock.valueHex})),$n in t.result&&(this.authorityCertIssuer=Array.from(t.result.authorityCertIssuer,s=>new Z({schema:s}))),Kn 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 d({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}}En.CLASS_NAME="AuthorityKeyIdentifier";const Un="pathLenConstraint",Hn="cA";class qi extends k{constructor(e={}){super(),this.cA=r(e,Hn,!1),Un in e&&(this.pathLenConstraint=r(e,Un,0)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Hn?!1:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new Yt({optional:!0,name:t.cA||u}),new S({optional:!0,name:t.pathLenConstraint||u})]})}fromSchema(e){C(e,[Hn,Un]);const t=N(e,e,qi.schema({names:{cA:Hn,pathLenConstraint:Un}}));p.assertSchema(t,this.className),Hn in t.result&&(this.cA=t.result.cA.valueBlock.value),Un 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(Hn)&&e.push(new Yt({value:this.cA})),Un in this&&(this.pathLenConstraint instanceof S?e.push(this.pathLenConstraint):e.push(new S({value:this.pathLenConstraint}))),new d({value:e})}toJSON(){const e={};return this.cA!==qi.defaultValues(Hn)&&(e.cA=this.cA),Un in this&&(this.pathLenConstraint instanceof S?e.pathLenConstraint=this.pathLenConstraint.toJSON():e.pathLenConstraint=this.pathLenConstraint),e}}qi.CLASS_NAME="BasicConstraints";const sh="certificateIndex",nh="keyIndex";class vc extends k{constructor(e={}){super(),this.certificateIndex=r(e,sh,vc.defaultValues(sh)),this.keyIndex=r(e,nh,vc.defaultValues(nh)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case sh:case nh: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 f=new Uint16Array(c);this.certificateIndex=f[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:La(i,e)})}toJSON(){return{certificateIndex:this.certificateIndex,keyIndex:this.keyIndex}}}vc.CLASS_NAME="CAVersion";const Ao="policyQualifierId",po="qualifier",Dw=[Ao,po];class Wi extends k{constructor(e={}){super(),this.policyQualifierId=r(e,Ao,Wi.defaultValues(Ao)),this.qualifier=r(e,po,Wi.defaultValues(po)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ao:return u;case po:return new K;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.policyQualifierId||u}),new K({name:t.qualifier||u})]})}fromSchema(e){C(e,Dw);const t=N(e,e,Wi.schema({names:{policyQualifierId:Ao,qualifier:po}}));p.assertSchema(t,this.className),this.policyQualifierId=t.result.policyQualifierId.valueBlock.toString(),this.qualifier=t.result.qualifier}toSchema(){return new d({value:[new T({value:this.policyQualifierId}),this.qualifier]})}toJSON(){return{policyQualifierId:this.policyQualifierId,qualifier:this.qualifier.toJSON()}}}Wi.CLASS_NAME="PolicyQualifierInfo";const bo="policyIdentifier",Jn="policyQualifiers",Pw=[bo,Jn];class Gi extends k{constructor(e={}){super(),this.policyIdentifier=r(e,bo,Gi.defaultValues(bo)),Jn in e&&(this.policyQualifiers=r(e,Jn,Gi.defaultValues(Jn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case bo:return u;case Jn:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.policyIdentifier||u}),new d({optional:!0,value:[new J({name:t.policyQualifiers||u,value:Wi.schema()})]})]})}fromSchema(e){C(e,Pw);const t=N(e,e,Gi.schema({names:{policyIdentifier:bo,policyQualifiers:Jn}}));p.assertSchema(t,this.className),this.policyIdentifier=t.result.policyIdentifier.valueBlock.toString(),Jn 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 d({value:Array.from(this.policyQualifiers,t=>t.toSchema())})),new d({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 ko="certificatePolicies",Lw=[ko];class Wa extends k{constructor(e={}){super(),this.certificatePolicies=r(e,ko,Wa.defaultValues(ko)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===ko?[]:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.certificatePolicies||u,value:Gi.schema()})]})}fromSchema(e){C(e,Lw);const t=N(e,e,Wa.schema({names:{certificatePolicies:ko}}));p.assertSchema(t,this.className),this.certificatePolicies=Array.from(t.result.certificatePolicies,s=>new Gi({schema:s}))}toSchema(){return new d({value:Array.from(this.certificatePolicies,e=>e.toSchema())})}toJSON(){return{certificatePolicies:Array.from(this.certificatePolicies,e=>e.toJSON())}}}Wa.CLASS_NAME="CertificatePolicies";const Eo="templateID",es="templateMajorVersion",ts="templateMinorVersion",Uw=[Eo,es,ts];class Da extends k{constructor(e={}){super(),this.templateID=r(e,Eo,Da.defaultValues(Eo)),es in e&&(this.templateMajorVersion=r(e,es,Da.defaultValues(es))),ts in e&&(this.templateMinorVersion=r(e,ts,Da.defaultValues(ts))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Eo:return u;case es:case ts:return 0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,Uw);const t=N(e,e,Da.schema({names:{templateID:Eo,templateMajorVersion:es,templateMinorVersion:ts}}));p.assertSchema(t,this.className),this.templateID=t.result.templateID.valueBlock.toString(),es in t.result&&(this.templateMajorVersion=t.result.templateMajorVersion.valueBlock.valueDec),ts in t.result&&(this.templateMinorVersion=t.result.templateMinorVersion.valueBlock.valueDec)}toSchema(){const e=[];return e.push(new T({value:this.templateID})),es in this&&e.push(new S({value:this.templateMajorVersion})),ts in this&&e.push(new S({value:this.templateMinorVersion})),new d({value:e})}toJSON(){const e={templateID:this.templateID};return es in this&&(e.templateMajorVersion=this.templateMajorVersion),ts in this&&(e.templateMinorVersion=this.templateMinorVersion),e}}const jn="distributionPoint",Um="distributionPointNames",Fn="reasons",qn="cRLIssuer",Hm="cRLIssuerNames",Hw=[jn,Um,Fn,qn,Hm];class Nn extends k{constructor(e={}){super(),jn in e&&(this.distributionPoint=r(e,jn,Nn.defaultValues(jn))),Fn in e&&(this.reasons=r(e,Fn,Nn.defaultValues(Fn))),qn in e&&(this.cRLIssuer=r(e,qn,Nn.defaultValues(qn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case jn:return[];case Fn:return new G;case qn:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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:Z.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:Z.schema()})]})]})}fromSchema(e){C(e,Hw);const t=N(e,e,Nn.schema({names:{distributionPoint:jn,distributionPointNames:Um,reasons:Fn,cRLIssuer:qn,cRLIssuerNames:Hm}}));p.assertSchema(t,this.className),jn in t.result&&(t.result.distributionPoint.idBlock.tagNumber===0&&(this.distributionPoint=Array.from(t.result.distributionPointNames,s=>new Z({schema:s}))),t.result.distributionPoint.idBlock.tagNumber===1&&(this.distributionPoint=new re({schema:new d({value:t.result.distributionPoint.valueBlock.value})}))),Fn in t.result&&(this.reasons=new G({valueHex:t.result.reasons.valueBlock.valueHex})),qn in t.result&&(this.cRLIssuer=Array.from(t.result.cRLIssuerNames,s=>new Z({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 d({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}}Nn.CLASS_NAME="DistributionPoint";const No="distributionPoints",_w=[No];class Ga extends k{constructor(e={}){super(),this.distributionPoints=r(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=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.distributionPoints||u,value:Nn.schema()})]})}fromSchema(e){C(e,_w);const t=N(e,e,Ga.schema({names:{distributionPoints:No}}));p.assertSchema(t,this.className),this.distributionPoints=Array.from(t.result.distributionPoints,s=>new Nn({schema:s}))}toSchema(){return new d({value:Array.from(this.distributionPoints,e=>e.toSchema())})}toJSON(){return{distributionPoints:Array.from(this.distributionPoints,e=>e.toJSON())}}}Ga.CLASS_NAME="CRLDistributionPoints";const Co="keyPurposes",Mw=[Co];class Sc extends k{constructor(e={}){super(),this.keyPurposes=r(e,Co,Sc.defaultValues(Co)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Co?[]:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.keyPurposes||u,value:new T})]})}fromSchema(e){C(e,Mw);const t=N(e,e,Sc.schema({names:{keyPurposes:Co}}));p.assertSchema(t,this.className),this.keyPurposes=Array.from(t.result.keyPurposes,s=>s.valueBlock.toString())}toSchema(){return new d({value:Array.from(this.keyPurposes,e=>new T({value:e}))})}toJSON(){return{keyPurposes:Array.from(this.keyPurposes)}}}Sc.CLASS_NAME="ExtKeyUsage";const no="accessDescriptions";class Ya extends k{constructor(e={}){super(),this.accessDescriptions=r(e,no,Ya.defaultValues(no)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===no?[]:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.accessDescriptions||u,value:Fi.schema()})]})}fromSchema(e){C(e,[no]);const t=N(e,e,Ya.schema({names:{accessDescriptions:no}}));p.assertSchema(t,this.className),this.accessDescriptions=Array.from(t.result.accessDescriptions,s=>new Fi({schema:s}))}toSchema(){return new d({value:Array.from(this.accessDescriptions,e=>e.toSchema())})}toJSON(){return{accessDescriptions:Array.from(this.accessDescriptions,e=>e.toJSON())}}}Ya.CLASS_NAME="InfoAccess";const Wn="distributionPoint",_m="distributionPointNames",Hs="onlyContainsUserCerts",_s="onlyContainsCACerts",Ms="onlySomeReasons",$s="indirectCRL",Ks="onlyContainsAttributeCerts",$w=[Wn,_m,Hs,_s,Ms,$s,Ks];class De extends k{constructor(e={}){super(),Wn in e&&(this.distributionPoint=r(e,Wn,De.defaultValues(Wn))),this.onlyContainsUserCerts=r(e,Hs,De.defaultValues(Hs)),this.onlyContainsCACerts=r(e,_s,De.defaultValues(_s)),Ms in e&&(this.onlySomeReasons=r(e,Ms,De.defaultValues(Ms))),this.indirectCRL=r(e,$s,De.defaultValues($s)),this.onlyContainsAttributeCerts=r(e,Ks,De.defaultValues(Ks)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Wn:return[];case Hs:return!1;case _s:return!1;case Ms:return 0;case $s:return!1;case Ks:return!1;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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:Z.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,$w);const t=N(e,e,De.schema({names:{distributionPoint:Wn,distributionPointNames:_m,onlyContainsUserCerts:Hs,onlyContainsCACerts:_s,onlySomeReasons:Ms,indirectCRL:$s,onlyContainsAttributeCerts:Ks}}));if(p.assertSchema(t,this.className),Wn in t.result)switch(!0){case t.result.distributionPoint.idBlock.tagNumber===0:this.distributionPoint=Array.from(t.result.distributionPointNames,s=>new Z({schema:s}));break;case t.result.distributionPoint.idBlock.tagNumber===1:this.distributionPoint=new re({schema:new d({value:t.result.distributionPoint.valueBlock.value})});break;default:throw new Error("Unknown tagNumber for distributionPoint: {$asn1.result.distributionPoint.idBlock.tagNumber}")}if(Hs in t.result){const s=new Uint8Array(t.result.onlyContainsUserCerts.valueBlock.valueHex);this.onlyContainsUserCerts=s[0]!==0}if(_s in t.result){const s=new Uint8Array(t.result.onlyContainsCACerts.valueBlock.valueHex);this.onlyContainsCACerts=s[0]!==0}if(Ms in t.result){const s=new Uint8Array(t.result.onlySomeReasons.valueBlock.valueHex);this.onlySomeReasons=s[0]}if($s in t.result){const s=new Uint8Array(t.result.indirectCRL.valueBlock.valueHex);this.indirectCRL=s[0]!==0}if(Ks 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(Hs)&&e.push(new _({idBlock:{tagClass:3,tagNumber:1},valueHex:new Uint8Array([255]).buffer})),this.onlyContainsCACerts!==De.defaultValues(_s)&&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($s)&&e.push(new _({idBlock:{tagClass:3,tagNumber:4},valueHex:new Uint8Array([255]).buffer})),this.onlyContainsAttributeCerts!==De.defaultValues(Ks)&&e.push(new _({idBlock:{tagClass:3,tagNumber:5},valueHex:new Uint8Array([255]).buffer})),new d({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(Hs)&&(e.onlyContainsUserCerts=this.onlyContainsUserCerts),this.onlyContainsCACerts!==De.defaultValues(_s)&&(e.onlyContainsCACerts=this.onlyContainsCACerts),Ms in this&&(e.onlySomeReasons=this.onlySomeReasons),this.indirectCRL!==De.defaultValues($s)&&(e.indirectCRL=this.indirectCRL),this.onlyContainsAttributeCerts!==De.defaultValues(Ks)&&(e.onlyContainsAttributeCerts=this.onlyContainsAttributeCerts),e}}De.CLASS_NAME="IssuingDistributionPoint";const Bo="base",yr="minimum",Js="maximum",Kw=[Bo,yr,Js];class jt extends k{constructor(e={}){super(),this.base=r(e,Bo,jt.defaultValues(Bo)),this.minimum=r(e,yr,jt.defaultValues(yr)),Js in e&&(this.maximum=r(e,Js,jt.defaultValues(Js))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Bo:return new Z;case yr:return 0;case Js:return 0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[Z.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,Kw);const t=N(e,e,jt.schema({names:{base:{names:{blockName:Bo}},minimum:yr,maximum:Js}}));p.assertSchema(t,this.className),this.base=new Z({schema:t.result.base}),yr in t.result&&(t.result.minimum.valueBlock.isHexOnly?this.minimum=t.result.minimum:this.minimum=t.result.minimum.valueBlock.valueDec),Js 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(Js 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 d({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}}jt.CLASS_NAME="GeneralSubtree";const Gn="permittedSubtrees",Yn="excludedSubtrees",Jw=[Gn,Yn];class Ha extends k{constructor(e={}){super(),Gn in e&&(this.permittedSubtrees=r(e,Gn,Ha.defaultValues(Gn))),Yn in e&&(this.excludedSubtrees=r(e,Yn,Ha.defaultValues(Yn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Gn:case Yn:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.permittedSubtrees||u,value:jt.schema()})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.excludedSubtrees||u,value:jt.schema()})]})]})}fromSchema(e){C(e,Jw);const t=N(e,e,Ha.schema({names:{permittedSubtrees:Gn,excludedSubtrees:Yn}}));p.assertSchema(t,this.className),Gn in t.result&&(this.permittedSubtrees=Array.from(t.result.permittedSubtrees,s=>new jt({schema:s}))),Yn in t.result&&(this.excludedSubtrees=Array.from(t.result.excludedSubtrees,s=>new jt({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 d({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}}Ha.CLASS_NAME="NameConstraints";const ss="requireExplicitPolicy",ns="inhibitPolicyMapping",jw=[ss,ns];class _a extends k{constructor(e={}){super(),ss in e&&(this.requireExplicitPolicy=r(e,ss,_a.defaultValues(ss))),ns in e&&(this.inhibitPolicyMapping=r(e,ns,_a.defaultValues(ns))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ss:return 0;case ns:return 0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,jw);const t=N(e,e,_a.schema({names:{requireExplicitPolicy:ss,inhibitPolicyMapping:ns}}));if(p.assertSchema(t,this.className),ss in t.result){const s=t.result.requireExplicitPolicy;s.idBlock.tagClass=1,s.idBlock.tagNumber=2;const n=s.toBER(!1),i=Be(n);p.assert(i,"Integer"),this.requireExplicitPolicy=i.result.valueBlock.valueDec}if(ns in t.result){const s=t.result.inhibitPolicyMapping;s.idBlock.tagClass=1,s.idBlock.tagNumber=2;const n=s.toBER(!1),i=Be(n);p.assert(i,"Integer"),this.inhibitPolicyMapping=i.result.valueBlock.valueDec}}toSchema(){const e=[];if(ss in this){const t=new S({value:this.requireExplicitPolicy});t.idBlock.tagClass=3,t.idBlock.tagNumber=0,e.push(t)}if(ns in this){const t=new S({value:this.inhibitPolicyMapping});t.idBlock.tagClass=3,t.idBlock.tagNumber=1,e.push(t)}return new d({value:e})}toJSON(){const e={};return ss in this&&(e.requireExplicitPolicy=this.requireExplicitPolicy),ns in this&&(e.inhibitPolicyMapping=this.inhibitPolicyMapping),e}}_a.CLASS_NAME="PolicyConstraints";const Io="issuerDomainPolicy",Vo="subjectDomainPolicy",Fw=[Io,Vo];class Yi extends k{constructor(e={}){super(),this.issuerDomainPolicy=r(e,Io,Yi.defaultValues(Io)),this.subjectDomainPolicy=r(e,Vo,Yi.defaultValues(Vo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Io:return u;case Vo:return u;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.issuerDomainPolicy||u}),new T({name:t.subjectDomainPolicy||u})]})}fromSchema(e){C(e,Fw);const t=N(e,e,Yi.schema({names:{issuerDomainPolicy:Io,subjectDomainPolicy:Vo}}));p.assertSchema(t,this.className),this.issuerDomainPolicy=t.result.issuerDomainPolicy.valueBlock.toString(),this.subjectDomainPolicy=t.result.subjectDomainPolicy.valueBlock.toString()}toSchema(){return new d({value:[new T({value:this.issuerDomainPolicy}),new T({value:this.subjectDomainPolicy})]})}toJSON(){return{issuerDomainPolicy:this.issuerDomainPolicy,subjectDomainPolicy:this.subjectDomainPolicy}}}Yi.CLASS_NAME="PolicyMapping";const xo="mappings",qw=[xo];class Ac extends k{constructor(e={}){super(),this.mappings=r(e,xo,Ac.defaultValues(xo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===xo?[]:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.mappings||u,value:Yi.schema()})]})}fromSchema(e){C(e,qw);const t=N(e,e,Ac.schema({names:{mappings:xo}}));p.assertSchema(t,this.className),this.mappings=Array.from(t.result.mappings,s=>new Yi({schema:s}))}toSchema(){return new d({value:Array.from(this.mappings,e=>e.toSchema())})}toJSON(){return{mappings:Array.from(this.mappings,e=>e.toJSON())}}}Ac.CLASS_NAME="PolicyMappings";const js="notBefore",Fs="notAfter",Ww=[js,Fs];class Ma extends k{constructor(e={}){super(),js in e&&(this.notBefore=r(e,js,Ma.defaultValues(js))),Fs in e&&(this.notAfter=r(e,Fs,Ma.defaultValues(Fs))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case js:return new Date;case Fs:return new Date;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,Ww);const t=N(e,e,Ma.schema({names:{notBefore:js,notAfter:Fs}}));if(p.assertSchema(t,this.className),js in t.result){const s=new ue;s.fromBuffer(t.result.notBefore.valueBlock.valueHex),this.notBefore=s.toDate()}if(Fs 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 js in this&&e.push(new _({idBlock:{tagClass:3,tagNumber:0},valueHex:new ue({valueDate:this.notBefore}).valueBlock.valueHexView})),Fs in this&&e.push(new _({idBlock:{tagClass:3,tagNumber:1},valueHex:new ue({valueDate:this.notAfter}).valueBlock.valueHexView})),new d({value:e})}toJSON(){const e={};return this.notBefore&&(e.notBefore=this.notBefore),this.notAfter&&(e.notAfter=this.notAfter),e}}Ma.CLASS_NAME="PrivateKeyUsagePeriod";const vr="id",is="type",Sr="values",Gw=[vr,is],Yw=[Sr];class Qi extends k{constructor(e={}){super(),this.id=r(e,vr,Qi.defaultValues(vr)),is in e&&(this.type=r(e,is,Qi.defaultValues(is))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case vr:return u;case is:return new Ae;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case vr:return t===u;case is:return t instanceof Ae;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.id||u}),new K({name:t.type||u,optional:!0})]})}fromSchema(e){C(e,Gw);const t=N(e,e,Qi.schema({names:{id:vr,type:is}}));p.assertSchema(t,this.className),this.id=t.result.id.valueBlock.toString(),is in t.result&&(this.type=t.result.type)}toSchema(){const e=[new T({value:this.id})];return is in this&&e.push(this.type),new d({value:e})}toJSON(){const e={id:this.id};return this.type&&(e.type=this.type.toJSON()),e}}Qi.CLASS_NAME="QCStatement";class pc extends k{constructor(e={}){super(),this.values=r(e,Sr,pc.defaultValues(Sr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Sr?[]:super.defaultValues(e)}static compareWithDefault(e,t){return e===Sr?t.length===0:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.values||u,value:Qi.schema(t.value||{})})]})}fromSchema(e){C(e,Yw);const t=N(e,e,pc.schema({names:{values:Sr}}));p.assertSchema(t,this.className),this.values=Array.from(t.result.values,s=>new Qi({schema:s}))}toSchema(){return new d({value:Array.from(this.values,e=>e.toSchema())})}toJSON(){return{values:Array.from(this.values,e=>e.toJSON())}}}pc.CLASS_NAME="QCStatements";var Qn;class xn{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}}Qn=xn;xn.namedCurves={};Qn.register("P-256","1.2.840.10045.3.1.7",32),Qn.register("P-384","1.3.132.0.34",48),Qn.register("P-521","1.3.132.0.35",66),Qn.register("brainpoolP256r1","1.3.36.3.3.2.8.1.1.7",32),Qn.register("brainpoolP384r1","1.3.36.3.3.2.8.1.1.11",48),Qn.register("brainpoolP512r1","1.3.36.3.3.2.8.1.1.13",64);const Vc="x",xc="y",Oc="namedCurve";class Ye extends k{constructor(e={}){super(),this.x=r(e,Vc,Ye.defaultValues(Vc)),this.y=r(e,xc,Ye.defaultValues(xc)),this.namedCurve=r(e,Oc,Ye.defaultValues(Oc)),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Vc:case xc:return be;case Oc:return u;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Vc:case xc:return t instanceof ArrayBuffer&&Ja(t,Ye.defaultValues(e));case Oc:return typeof t=="string"&&t===Ye.defaultValues(e);default:return super.defaultValues(e)}}static schema(){return new Ru}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=xn.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 Ru({data:La(new Uint8Array([4]).buffer,this.x,this.y)})}toJSON(){const e=xn.find(this.namedCurve);return{crv:e?e.name:this.namedCurve,x:Th(xu(this.x),!0,!0,!1),y:Th(xu(this.y),!0,!0,!1)}}fromJSON(e){Q.assert("json",e,"crv","x","y");let t=0;const s=xn.find(e.crv);s&&(this.namedCurve=s.id,t=s.size);const n=ja(mc(e.x,!0));if(n.byteLength<t){this.x=new ArrayBuffer(t);const o=new Uint8Array(this.x),l=new Uint8Array(n);o.set(l,1)}else this.x=n.slice(0,t);const i=ja(mc(e.y,!0));if(i.byteLength<t){this.y=new ArrayBuffer(t);const o=new Uint8Array(this.y),l=new Uint8Array(i);o.set(l,1)}else this.y=i.slice(0,t)}}Ye.CLASS_NAME="ECPublicKey";const Oo="modulus",Ro="publicExponent",Qw=[Oo,Ro];class Xi extends k{constructor(e={}){super(),this.modulus=r(e,Oo,Xi.defaultValues(Oo)),this.publicExponent=r(e,Ro,Xi.defaultValues(Ro)),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Oo:return new S;case Ro:return new S;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.modulus||u}),new S({name:t.publicExponent||u})]})}fromSchema(e){C(e,Qw);const t=N(e,e,Xi.schema({names:{modulus:Oo,publicExponent:Ro}}));p.assertSchema(t,this.className),this.modulus=t.result.modulus.convertFromDER(256),this.publicExponent=t.result.publicExponent}toSchema(){return new d({value:[this.modulus.convertToDER(),this.publicExponent]})}toJSON(){return{n:H.ToBase64Url(this.modulus.valueBlock.valueHexView),e:H.ToBase64Url(this.publicExponent.valueBlock.valueHexView)}}fromJSON(e){Q.assert("json",e,"n","e");const t=ja(mc(e.n,!0));this.modulus=new S({valueHex:t.slice(0,Math.pow(2,eg(t.byteLength)))}),this.publicExponent=new S({valueHex:ja(mc(e.e,!0)).slice(0,3)})}}Xi.CLASS_NAME="RSAPublicKey";const To="algorithm",Do="subjectPublicKey",Xw=[To,Do];class Xe extends k{get parsedKey(){if(this._parsedKey===void 0){switch(this.algorithm.algorithmId){case"1.2.840.10045.2.1":if("algorithmParams"in this.algorithm&&this.algorithm.algorithmParams.constructor.blockName()===T.blockName())try{this._parsedKey=new Ye({namedCurve:this.algorithm.algorithmParams.valueBlock.toString(),schema:this.subjectPublicKey.valueBlock.valueHexView})}catch{}break;case"1.2.840.113549.1.1.1":case"1.2.840.113549.1.1.10":{const e=Be(this.subjectPublicKey.valueBlock.valueHexView);if(e.offset!==-1)try{this._parsedKey=new Xi({schema:e.result})}catch{}}break}this._parsedKey||(this._parsedKey=null)}return this._parsedKey||void 0}set parsedKey(e){this._parsedKey=e}constructor(e={}){super(),this.algorithm=r(e,To,Xe.defaultValues(To)),this.subjectPublicKey=r(e,Do,Xe.defaultValues(Do));const t=r(e,"parsedKey",null);t&&(this.parsedKey=t),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case To:return new v;case Do:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.algorithm||{}),new G({name:t.subjectPublicKey||u})]})}fromSchema(e){C(e,Xw);const t=N(e,e,Xe.schema({names:{algorithm:{names:{blockName:To}},subjectPublicKey:Do}}));p.assertSchema(t,this.className),this.algorithm=new v({schema:t.result.algorithm}),this.subjectPublicKey=t.result.subjectPublicKey}toSchema(){return new d({value:[this.algorithm.toSchema(),this.subjectPublicKey]})}toJSON(){if(!this.parsedKey)return{algorithm:this.algorithm.toJSON(),subjectPublicKey:this.subjectPublicKey.toJSON()};const e={};switch(this.algorithm.algorithmId){case"1.2.840.10045.2.1":e.kty="EC";break;case"1.2.840.113549.1.1.1":case"1.2.840.113549.1.1.10":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 Ye({json:e}),this.algorithm=new v({algorithmId:"1.2.840.10045.2.1",algorithmParams:new T({value:this.parsedKey.namedCurve})});break;case"RSA":this.parsedKey=new Xi({json:e}),this.algorithm=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.subjectPublicKey=new G({valueHex:this.parsedKey.toSchema().toBER(!1)})}}async importKey(e,t=q(!0)){try{if(!e)throw new Error("Need to provide publicKey input parameter");const s=await t.exportKey("spki",e),n=Be(s);try{this.fromSchema(n.result)}catch{throw new Error("Error during initializing object from schema")}}catch(s){const n=s instanceof Error?s.message:`${s}`;throw new Error(`Error during exporting public key: ${n}`)}}}Xe.CLASS_NAME="PublicKeyInfo";const Ar="version",pr="privateKey",Et="namedCurve",qs="publicKey",Zw=[Ar,pr,Et,qs];class yt extends k{constructor(e={}){super(),this.version=r(e,Ar,yt.defaultValues(Ar)),this.privateKey=r(e,pr,yt.defaultValues(pr)),Et in e&&(this.namedCurve=r(e,Et,yt.defaultValues(Et))),qs in e&&(this.publicKey=r(e,qs,yt.defaultValues(qs))),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ar:return 1;case pr:return new B;case Et:return u;case qs:return new Ye;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ar:return t===yt.defaultValues(e);case pr:return t.isEqual(yt.defaultValues(e));case Et:return t===u;case qs:return Ye.compareWithDefault(Et,t.namedCurve)&&Ye.compareWithDefault("x",t.x)&&Ye.compareWithDefault("y",t.y);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||u}),new B({name:t.privateKey||u}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new T({name:t.namedCurve||u})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new G({name:t.publicKey||u})]})]})}fromSchema(e){C(e,Zw);const t=N(e,e,yt.schema({names:{version:Ar,privateKey:pr,namedCurve:Et,publicKey:qs}}));if(p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.privateKey=t.result.privateKey,Et in t.result&&(this.namedCurve=t.result.namedCurve.valueBlock.toString()),qs in t.result){const s={schema:t.result.publicKey.valueBlock.valueHex};Et in this&&(s.namedCurve=this.namedCurve),this.publicKey=new Ye(s)}}toSchema(){const e=[new S({value:this.version}),this.privateKey];return this.namedCurve&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[new T({value:this.namedCurve})]})),this.publicKey&&e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[new G({valueHex:this.publicKey.toSchema().toBER(!1)})]})),new d({value:e})}toJSON(){if(!this.namedCurve||yt.compareWithDefault(Et,this.namedCurve))throw new Error('Not enough information for making JSON: absent "namedCurve" value');const e=xn.find(this.namedCurve),t={crv:e?e.name:this.namedCurve,d:H.ToBase64Url(this.privateKey.valueBlock.valueHexView)};if(this.publicKey){const s=this.publicKey.toJSON();t.x=s.x,t.y=s.y}return t}fromJSON(e){Q.assert("json",e,"crv","d");let t=0;const s=xn.find(e.crv);s&&(this.namedCurve=s.id,t=s.size);const n=H.FromBase64Url(e.d);if(n.byteLength<t){const i=new ArrayBuffer(t),o=new Uint8Array(i),l=new Uint8Array(n);o.set(l,1),this.privateKey=new B({valueHex:i})}else this.privateKey=new B({valueHex:n.slice(0,t)});e.x&&e.y&&(this.publicKey=new Ye({json:e}))}}yt.CLASS_NAME="ECPrivateKey";const Po="prime",Lo="exponent",Uo="coefficient",zw=[Po,Lo,Uo];class ds extends k{constructor(e={}){super(),this.prime=r(e,Po,ds.defaultValues(Po)),this.exponent=r(e,Lo,ds.defaultValues(Lo)),this.coefficient=r(e,Uo,ds.defaultValues(Uo)),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Po:return new S;case Lo:return new S;case Uo:return new S;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.prime||u}),new S({name:t.exponent||u}),new S({name:t.coefficient||u})]})}fromSchema(e){C(e,zw);const t=N(e,e,ds.schema({names:{prime:Po,exponent:Lo,coefficient:Uo}}));p.assertSchema(t,this.className),this.prime=t.result.prime.convertFromDER(),this.exponent=t.result.exponent.convertFromDER(),this.coefficient=t.result.coefficient.convertFromDER()}toSchema(){return new d({value:[this.prime.convertToDER(),this.exponent.convertToDER(),this.coefficient.convertToDER()]})}toJSON(){return{r:H.ToBase64Url(this.prime.valueBlock.valueHexView),d:H.ToBase64Url(this.exponent.valueBlock.valueHexView),t:H.ToBase64Url(this.coefficient.valueBlock.valueHexView)}}fromJSON(e){Q.assert("json",e,"r","d","r"),this.prime=new S({valueHex:H.FromBase64Url(e.r)}),this.exponent=new S({valueHex:H.FromBase64Url(e.d)}),this.coefficient=new S({valueHex:H.FromBase64Url(e.t)})}}ds.CLASS_NAME="OtherPrimeInfo";const Ho="version",_o="modulus",Mo="publicExponent",$o="privateExponent",Ko="prime1",Jo="prime2",jo="exponent1",Fo="exponent2",qo="coefficient",Xn="otherPrimeInfos",ey=[Ho,_o,Mo,$o,Ko,Jo,jo,Fo,qo,Xn];class Fe extends k{constructor(e={}){super(),this.version=r(e,Ho,Fe.defaultValues(Ho)),this.modulus=r(e,_o,Fe.defaultValues(_o)),this.publicExponent=r(e,Mo,Fe.defaultValues(Mo)),this.privateExponent=r(e,$o,Fe.defaultValues($o)),this.prime1=r(e,Ko,Fe.defaultValues(Ko)),this.prime2=r(e,Jo,Fe.defaultValues(Jo)),this.exponent1=r(e,jo,Fe.defaultValues(jo)),this.exponent2=r(e,Fo,Fe.defaultValues(Fo)),this.coefficient=r(e,qo,Fe.defaultValues(qo)),Xn in e&&(this.otherPrimeInfos=r(e,Xn,Fe.defaultValues(Xn))),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ho:return 0;case _o:return new S;case Mo:return new S;case $o:return new S;case Ko:return new S;case Jo:return new S;case jo:return new S;case Fo:return new S;case qo:return new S;case Xn:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||u}),new S({name:t.modulus||u}),new S({name:t.publicExponent||u}),new S({name:t.privateExponent||u}),new S({name:t.prime1||u}),new S({name:t.prime2||u}),new S({name:t.exponent1||u}),new S({name:t.exponent2||u}),new S({name:t.coefficient||u}),new d({optional:!0,value:[new J({name:t.otherPrimeInfosName||u,value:ds.schema(t.otherPrimeInfo||{})})]})]})}fromSchema(e){C(e,ey);const t=N(e,e,Fe.schema({names:{version:Ho,modulus:_o,publicExponent:Mo,privateExponent:$o,prime1:Ko,prime2:Jo,exponent1:jo,exponent2:Fo,coefficient:qo,otherPrimeInfo:{names:{blockName:Xn}}}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.modulus=t.result.modulus.convertFromDER(256),this.publicExponent=t.result.publicExponent,this.privateExponent=t.result.privateExponent.convertFromDER(256),this.prime1=t.result.prime1.convertFromDER(128),this.prime2=t.result.prime2.convertFromDER(128),this.exponent1=t.result.exponent1.convertFromDER(128),this.exponent2=t.result.exponent2.convertFromDER(128),this.coefficient=t.result.coefficient.convertFromDER(128),Xn in t.result&&(this.otherPrimeInfos=Array.from(t.result.otherPrimeInfos,s=>new ds({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 d({value:Array.from(this.otherPrimeInfos,t=>t.toSchema())})),new d({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 ds({json:t})))}}Fe.CLASS_NAME="RSAPrivateKey";const Wo="version",Go="privateKeyAlgorithm",Yo="privateKey",Zn="attributes",Rc="parsedKey",ty=[Wo,Go,Yo,Zn];class nt extends k{constructor(e={}){super(),this.version=r(e,Wo,nt.defaultValues(Wo)),this.privateKeyAlgorithm=r(e,Go,nt.defaultValues(Go)),this.privateKey=r(e,Yo,nt.defaultValues(Yo)),Zn in e&&(this.attributes=r(e,Zn,nt.defaultValues(Zn))),Rc in e&&(this.parsedKey=r(e,Rc,nt.defaultValues(Rc))),e.json&&this.fromJSON(e.json),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Wo:return 0;case Go:return new v;case Yo:return new B;case Zn:return[];case Rc:return{};default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||u}),v.schema(t.privateKeyAlgorithm||{}),new B({name:t.privateKey||u}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.attributes||u,value:oe.schema()})]})]})}fromSchema(e){C(e,ty);const t=N(e,e,nt.schema({names:{version:Wo,privateKeyAlgorithm:{names:{blockName:Go}},privateKey:Yo,attributes:Zn}}));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,Zn in t.result&&(this.attributes=Array.from(t.result.attributes,s=>new oe({schema:s}))),this.privateKeyAlgorithm.algorithmId){case"1.2.840.113549.1.1.1":{const s=Be(this.privateKey.valueBlock.valueHexView);s.offset!==-1&&(this.parsedKey=new Fe({schema:s.result}))}break;case"1.2.840.10045.2.1":if("algorithmParams"in this.privateKeyAlgorithm&&this.privateKeyAlgorithm.algorithmParams instanceof T){const s=Be(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 d({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 Fe({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 B({valueHex:this.parsedKey.toSchema().toBER(!1)})}}}nt.CLASS_NAME="PrivateKeyInfo";const br="contentType",kr="contentEncryptionAlgorithm",zn="encryptedContent",sy=[br,kr,zn],jf=1024;class Ee extends k{constructor(e={}){if(super(),this.contentType=r(e,br,Ee.defaultValues(br)),this.contentEncryptionAlgorithm=r(e,kr,Ee.defaultValues(kr)),zn 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 B({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+jf>n.byteLength?n.byteLength-s:jf),l=new ArrayBuffer(o.length),c=new Uint8Array(l);for(let h=0;h<c.length;h++)c[h]=o[h];t.valueBlock.value.push(new B({valueHex:l})),i-=o.length,s+=o.length}this.encryptedContent=t}e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case br:return u;case kr:return new v;case zn:return new B;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case br:return t===u;case kr:return t.algorithmId===u&&!("algorithmParams"in t);case zn:return t.isEqual(Ee.defaultValues(zn));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.contentType||u}),v.schema(t.contentEncryptionAlgorithm||{}),new he({value:[new w({name:t.encryptedContent||u,idBlock:{tagClass:3,tagNumber:0},value:[new J({value:new B})]}),new _({name:t.encryptedContent||u,idBlock:{tagClass:3,tagNumber:0}})]})]})}fromSchema(e){C(e,sy);const t=N(e,e,Ee.schema({names:{contentType:br,contentEncryptionAlgorithm:{names:{blockName:kr}},encryptedContent:zn}}));p.assertSchema(t,this.className),this.contentType=t.result.contentType.valueBlock.toString(),this.contentEncryptionAlgorithm=new v({schema:t.result.contentEncryptionAlgorithm}),zn in t.result&&(this.encryptedContent=t.result.encryptedContent,this.encryptedContent.idBlock.tagClass=1,this.encryptedContent.idBlock.tagNumber=4)}toSchema(){const e={isIndefiniteForm:!1},t=[];if(t.push(new T({value:this.contentType})),t.push(this.contentEncryptionAlgorithm.toSchema()),this.encryptedContent){e.isIndefiniteForm=this.encryptedContent.idBlock.isConstructed;const s=this.encryptedContent;s.idBlock.tagClass=3,s.idBlock.tagNumber=0,s.lenBlock.isIndefiniteForm=this.encryptedContent.idBlock.isConstructed,t.push(s)}return new d({lenBlock:e,value:t})}toJSON(){const e={contentType:this.contentType,contentEncryptionAlgorithm:this.contentEncryptionAlgorithm.toJSON()};return this.encryptedContent&&(e.encryptedContent=this.encryptedContent.toJSON()),e}getEncryptedContent(){if(!this.encryptedContent)throw new Error("Parameter 'encryptedContent' is undefined");return B.prototype.getValue.call(this.encryptedContent)}}Ee.CLASS_NAME="EncryptedContentInfo";const Ws="hashAlgorithm",Gs="maskGenAlgorithm",Ys="saltLength",Qs="trailerField",ny=[Ws,Gs,Ys,Qs];class Pe extends k{constructor(e={}){super(),this.hashAlgorithm=r(e,Ws,Pe.defaultValues(Ws)),this.maskGenAlgorithm=r(e,Gs,Pe.defaultValues(Gs)),this.saltLength=r(e,Ys,Pe.defaultValues(Ys)),this.trailerField=r(e,Qs,Pe.defaultValues(Qs)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ws:return new v({algorithmId:"1.3.14.3.2.26",algorithmParams:new Ae});case Gs: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 Ys:return 20;case Qs:return 1;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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:[new S({name:t.saltLength||u})]}),new w({idBlock:{tagClass:3,tagNumber:3},optional:!0,value:[new S({name:t.trailerField||u})]})]})}fromSchema(e){C(e,ny);const t=N(e,e,Pe.schema({names:{hashAlgorithm:{names:{blockName:Ws}},maskGenAlgorithm:{names:{blockName:Gs}},saltLength:Ys,trailerField:Qs}}));p.assertSchema(t,this.className),Ws in t.result&&(this.hashAlgorithm=new v({schema:t.result.hashAlgorithm})),Gs in t.result&&(this.maskGenAlgorithm=new v({schema:t.result.maskGenAlgorithm})),Ys in t.result&&(this.saltLength=t.result.saltLength.valueBlock.valueDec),Qs in t.result&&(this.trailerField=t.result.trailerField.valueBlock.valueDec)}toSchema(){const e=[];return this.hashAlgorithm.isEqual(Pe.defaultValues(Ws))||e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[this.hashAlgorithm.toSchema()]})),this.maskGenAlgorithm.isEqual(Pe.defaultValues(Gs))||e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[this.maskGenAlgorithm.toSchema()]})),this.saltLength!==Pe.defaultValues(Ys)&&e.push(new w({idBlock:{tagClass:3,tagNumber:2},value:[new S({value:this.saltLength})]})),this.trailerField!==Pe.defaultValues(Qs)&&e.push(new w({idBlock:{tagClass:3,tagNumber:3},value:[new S({value:this.trailerField})]})),new d({value:e})}toJSON(){const e={};return this.hashAlgorithm.isEqual(Pe.defaultValues(Ws))||(e.hashAlgorithm=this.hashAlgorithm.toJSON()),this.maskGenAlgorithm.isEqual(Pe.defaultValues(Gs))||(e.maskGenAlgorithm=this.maskGenAlgorithm.toJSON()),this.saltLength!==Pe.defaultValues(Ys)&&(e.saltLength=this.saltLength),this.trailerField!==Pe.defaultValues(Qs)&&(e.trailerField=this.trailerField),e}}Pe.CLASS_NAME="RSASSAPSSParams";const Er="salt",Qo="iterationCount",Nt="keyLength",rs="prf",iy=[Er,Qo,Nt,rs];class Je extends k{constructor(e={}){super(),this.salt=r(e,Er,Je.defaultValues(Er)),this.iterationCount=r(e,Qo,Je.defaultValues(Qo)),Nt in e&&(this.keyLength=r(e,Nt,Je.defaultValues(Nt))),rs in e&&(this.prf=r(e,rs,Je.defaultValues(rs))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Er:return{};case Qo:return-1;case Nt:return 0;case rs:return new v({algorithmId:"1.3.14.3.2.26",algorithmParams:new Ae});default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new he({value:[new B({name:t.saltPrimitive||u}),v.schema(t.saltConstructed||{})]}),new S({name:t.iterationCount||u}),new S({name:t.keyLength||u,optional:!0}),v.schema(t.prf||{names:{optional:!0}})]})}fromSchema(e){C(e,iy);const t=N(e,e,Je.schema({names:{saltPrimitive:Er,saltConstructed:{names:{blockName:Er}},iterationCount:Qo,keyLength:Nt,prf:{names:{blockName:rs,optional:!0}}}}));p.assertSchema(t,this.className),this.salt=t.result.salt,this.iterationCount=t.result.iterationCount.valueBlock.valueDec,Nt in t.result&&(this.keyLength=t.result.keyLength.valueBlock.valueDec),rs in t.result&&(this.prf=new v({schema:t.result.prf}))}toSchema(){const e=[];return e.push(this.salt),e.push(new S({value:this.iterationCount})),Nt in this&&Je.defaultValues(Nt)!==this.keyLength&&e.push(new S({value:this.keyLength})),this.prf&&Je.defaultValues(rs).isEqual(this.prf)===!1&&e.push(this.prf.toSchema()),new d({value:e})}toJSON(){const e={salt:this.salt.toJSON(),iterationCount:this.iterationCount};return Nt in this&&Je.defaultValues(Nt)!==this.keyLength&&(e.keyLength=this.keyLength),this.prf&&Je.defaultValues(rs).isEqual(this.prf)===!1&&(e.prf=this.prf.toJSON()),e}}Je.CLASS_NAME="PBKDF2Params";const Xo="keyDerivationFunc",Zo="encryptionScheme",ry=[Xo,Zo];class Zi extends k{constructor(e={}){super(),this.keyDerivationFunc=r(e,Xo,Zi.defaultValues(Xo)),this.encryptionScheme=r(e,Zo,Zi.defaultValues(Zo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Xo:return new v;case Zo:return new v;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.keyDerivationFunc||{}),v.schema(t.encryptionScheme||{})]})}fromSchema(e){C(e,ry);const t=N(e,e,Zi.schema({names:{keyDerivationFunc:{names:{blockName:Xo}},encryptionScheme:{names:{blockName:Zo}}}}));p.assertSchema(t,this.className),this.keyDerivationFunc=new v({schema:t.result.keyDerivationFunc}),this.encryptionScheme=new v({schema:t.result.encryptionScheme})}toSchema(){return new d({value:[this.keyDerivationFunc.toSchema(),this.encryptionScheme.toSchema()]})}toJSON(){return{keyDerivationFunc:this.keyDerivationFunc.toJSON(),encryptionScheme:this.encryptionScheme.toJSON()}}}Zi.CLASS_NAME="PBES2Params";class ay{constructor(e){this.crypto=e.crypto,this.subtle="webkitSubtle"in e.crypto?e.crypto.webkitSubtle:e.crypto.subtle,this.name=r(e,"name",u)}async encrypt(...e){return this.subtle.encrypt(...e)}async decrypt(...e){return this.subtle.decrypt(...e)}sign(...e){return this.subtle.sign(...e)}async verify(...e){return this.subtle.verify(...e)}async digest(...e){return this.subtle.digest(...e)}async generateKey(...e){return this.subtle.generateKey(...e)}async deriveKey(...e){return this.subtle.deriveKey(...e)}async deriveBits(...e){return this.subtle.deriveBits(...e)}async wrapKey(...e){return this.subtle.wrapKey(...e)}async unwrapKey(...e){return this.subtle.unwrapKey(...e)}exportKey(...e){return this.subtle.exportKey(...e)}importKey(...e){return this.subtle.importKey(...e)}getRandomValues(e){if(e===null)throw new Error('Argument "array" must not be null');return this.crypto.getRandomValues(e)}}async function Ff(a,e,t,s,n){let i,o,l;switch(a.toUpperCase()){case"SHA-1":i=20,o=64,l=Vg;break;case"SHA-256":i=32,o=64,l=Rg;break;case"SHA-384":i=48,o=128,l=iw;break;case"SHA-512":i=64,o=128,l=nw;break;default:throw new Error("Unsupported hashing algorithm")}const c=new Uint8Array(t);let h=new TextDecoder().decode(t);new TextEncoder().encode(h).some((V,R)=>V!==c[R])&&(h=String.fromCharCode(...c));const g=new Uint8Array(h.length*2+2),m=new DataView(g.buffer);for(let V=0;V<h.length;V++)m.setUint16(V*2,h.charCodeAt(V),!1);m.setUint16(h.length*2,0,!1);const b=new Uint8Array(o).fill(3),A=new Uint8Array(s),E=new Uint8Array(o*Math.ceil(A.length/o)).map((V,R)=>A[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),I=[];for(let V=0;V<x;V++){let R=new Uint8Array(b.length+O.length);R.set(b),R.set(O,b.length);for(let z=0;z<n;z++)R=l(R);const M=new Uint8Array(o).map((z,ye)=>R[ye%R.length]),te=Math.ceil(A.length/o)+Math.ceil(g.length/o),j=[];for(let z=0;z<te;z++){const ye=Array.from(O.slice(z*o,(z+1)*o));let se=511;for(let ae=M.length-1;ae>=0;ae--)se>>=8,se+=M[ae]+(ye[ae]||0),ye[ae]=se&255;j.push(...ye)}O=new Uint8Array(j),I.push(...R)}return new Uint8Array(I.slice(0,e>>3)).buffer}function Mm(a){const e=typeof a=="string"?{name:a}:a;return"hash"in e?{...e,hash:Mm(e.hash)}:e}class Tu extends ay{async importKey(e,t,s,n,i){var o,l,c,h,f,g;let m={};const b=Mm(s);switch(e.toLowerCase()){case"raw":return this.subtle.importKey("raw",t,s,n,i);case"spki":{const A=Be(L.toArrayBuffer(t));p.assert(A,"keyData");const E=new Xe;try{E.fromSchema(A.result)}catch{throw new ie("Incorrect keyData")}switch(b.name.toUpperCase()){case"RSA-PSS":{if(i=["verify"],m.kty="RSA",m.ext=n,m.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":m.alg="PS1";break;case"SHA-256":m.alg="PS256";break;case"SHA-384":m.alg="PS384";break;case"SHA-512":m.alg="PS512";break;default:throw new Error(`Incorrect hash algorithm: ${b.hash.name.toUpperCase()}`)}const y=E.toJSON();Object.assign(m,y)}break;case"RSASSA-PKCS1-V1_5":{if(i=["verify"],m.kty="RSA",m.ext=n,m.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":m.alg="RS1";break;case"SHA-256":m.alg="RS256";break;case"SHA-384":m.alg="RS384";break;case"SHA-512":m.alg="RS512";break;default:throw new Error(`Incorrect hash algorithm: ${b.hash.name.toUpperCase()}`)}const y=E.toJSON();Object.assign(m,y)}break;case"ECDSA":i=["verify"];case"ECDH":{if(m={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(m,y)}break;case"RSA-OAEP":{if(m.kty="RSA",m.ext=n,m.key_ops=i,this.name.toLowerCase()==="safari")m.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":m.alg="RSA-OAEP";break;case"SHA-256":m.alg="RSA-OAEP-256";break;case"SHA-384":m.alg="RSA-OAEP-384";break;case"SHA-512":m.alg="RSA-OAEP-512";break;default:throw new Error(`Incorrect hash algorithm: ${b.hash.name.toUpperCase()}`)}}const y=E.toJSON();Object.assign(m,y)}break;case"RSAES-PKCS1-V1_5":{m.kty="RSA",m.ext=n,m.key_ops=i,m.alg="PS1";const y=E.toJSON();Object.assign(m,y)}break;default:throw new Error(`Incorrect algorithm name: ${b.name.toUpperCase()}`)}}break;case"pkcs8":{const A=new nt,E=Be(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":m.alg="PS1";break;case"SHA-256":m.alg="PS256";break;case"SHA-384":m.alg="PS384";break;case"SHA-512":m.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"],m.kty="RSA",m.ext=n,m.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 m))switch((c=b.hash)===null||c===void 0?void 0:c.name.toUpperCase()){case"SHA-1":m.alg="RS1";break;case"SHA-256":m.alg="RS256";break;case"SHA-384":m.alg="RS384";break;case"SHA-512":m.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(m,y)}break;case"ECDSA":i=["sign"];case"ECDH":{if(m={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(m,y)}break;case"RSA-OAEP":{if(m.kty="RSA",m.ext=n,m.key_ops=i,this.name.toLowerCase()==="safari")m.alg="RSA-OAEP";else switch((f=b.hash)===null||f===void 0?void 0:f.name.toUpperCase()){case"SHA-1":m.alg="RSA-OAEP";break;case"SHA-256":m.alg="RSA-OAEP-256";break;case"SHA-384":m.alg="RSA-OAEP-384";break;case"SHA-512":m.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(m,y)}break;case"RSAES-PKCS1-V1_5":{i=["decrypt"],m.kty="RSA",m.ext=n,m.key_ops=i,m.alg="PS1";const y=A.toJSON();Object.assign(m,y)}break;default:throw new Error(`Incorrect algorithm name: ${b.name.toUpperCase()}`)}}break;case"jwk":m=t;break;default:throw new Error(`Incorrect format: ${e}`)}if(this.name.toLowerCase()==="safari")try{return this.subtle.importKey("jwk",ja(JSON.stringify(m)),s,n,i)}catch{return this.subtle.importKey("jwk",m,s,n,i)}return this.subtle.importKey("jwk",m,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(xu(s))),e.toLowerCase()){case"raw":return this.subtle.exportKey("raw",t);case"spki":{const n=new Xe;try{n.fromJSON(s)}catch{throw new Error("Incorrect key data")}return n.toSchema().toBER(!1)}case"pkcs8":{const n=new nt;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),f=new Je({salt:new B({valueHex:l}),iterationCount:e.iterationCount,prf:new v({algorithmId:n,algorithmParams:new Ae})}),g=new Uint8Array(e.password),m=await this.importKey("raw",g,"PBKDF2",!1,["deriveKey"]),b=await this.deriveKey({name:"PBKDF2",hash:{name:e.hmacHashAlgorithm},salt:c,iterations:e.iterationCount},m,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:f.toSchema()}),encryptionScheme:new v({algorithmId:t,algorithmParams:new B({valueHex:i})})});return new Ee({contentType:e.contentType,contentEncryptionAlgorithm:new v({algorithmId:"1.2.840.113549.1.5.13",algorithmParams:E.toSchema()}),encryptedContent:new B({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 f="SHA-1";s.prf&&(f=this.getAlgorithmByOID(s.prf.algorithmId,!0).hash.name);const g=await this.importKey("raw",e.password,"PBKDF2",!1,["deriveKey"]),m=await this.deriveKey({name:"PBKDF2",hash:{name:f},salt:c,iterations:h},g,n,!1,["decrypt"]),b=e.encryptedContentInfo.getEncryptedContent();return this.decrypt({name:n.name,iv:o},m,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 Ff(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 Ff(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"?ly(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 f;n.algorithmId==="1.2.840.113549.1.1.10"?f=n.algorithmId:f=s.algorithm.algorithmId;const g=this.getAlgorithmByOID(f,!0);if(h.algorithm=this.getAlgorithmParameters(g.name,"importKey"),"hash"in h.algorithm.algorithm&&(h.algorithm.algorithm.hash.name=i),g.name==="ECDSA"){let m=!1;if("algorithmParams"in s.algorithm&&"idBlock"in s.algorithm.algorithmParams&&s.algorithm.algorithmParams.idBlock.tagClass===1&&s.algorithm.algorithmParams.idBlock.tagNumber===6&&(m=!0),m===!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=xn.find(o.algorithm.namedCurve);if(!h)throw new Error("Unsupported named curve in use");const f=Be(c);p.assert(f,"Signature value"),c=cy(f.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 f="SHA-1";"hashAlgorithm"in h&&(f=this.getAlgorithmByOID(h.hashAlgorithm.algorithmId,!0).name),l.algorithm.hash.name=f}return this.verify(l.algorithm,o,c,e)}}let $m={name:"none",crypto:null};function qf(a){return!!(a&&typeof a=="object"&&"crypto"in a)}function Wf(a,...e){let t=null;if(e.length<2)e.length?t=e[0]:t=typeof self<"u"&&self.crypto?new Tu({name:"browser",crypto:self.crypto}):null;else{const s=e[0],n=e[1];qf(n)?t=n:qf(s)?t=s:"subtle"in s&&"getRandomValues"in s&&(t=new Tu({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:a,crypto:t}}else $m={name:a,crypto:t}}function oy(){if(typeof process<"u"&&"pid"in process&&typeof global<"u"&&typeof window>"u"){let a;try{a=global[process.pid].pkijs.engine}catch{throw new Error("Please call 'setEngine' before call to 'getEngine'")}return a}return $m}function q(a=!1){const e=oy();if(!e.crypto&&a)throw new Error("Unable to create WebCrypto object");return e.crypto}function ly(a){if(a.byteLength%2!==0)return be;const e=a.byteLength/2,t=new ArrayBuffer(e);new Uint8Array(t).set(new Uint8Array(a,0,e));const n=new S({valueHex:t}),i=new ArrayBuffer(e);new Uint8Array(i).set(new Uint8Array(a,e,e));const l=new S({valueHex:i});return new d({value:[n.convertToDER(),l.convertToDER()]}).toBER(!1)}function cy(a,e){if(!(a instanceof d&&a.valueBlock.value.length===2&&a.valueBlock.value[0]instanceof S&&a.valueBlock.value[1]instanceof S))return be;const t=a.valueBlock.value[0].convertFromDER().valueBlock.valueHexView,s=a.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 uy(a,e,t,s,n){switch(a.toUpperCase()){case"SHA-1":case"SHA-256":case"SHA-384":case"SHA-512":break;default:throw new ie(`Unknown hash function: ${a}`)}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=La(l,e),l=La(l,i),l=La(l,s);const c=await n.digest({name:a},l);return{counter:t,result:c}}async function Gf(a,e,t,s,n=q(!0)){let i=0,o=1;switch(a.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: ${a}`)}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 m=1;m<=o;m++)c.push(await uy(a,e,m,s,n));let h=be,f=1,g=!0;for(;g;){g=!1;for(const m of c)if(m.counter===f){h=La(h,m.result),g=!0;break}f++}if(t>>=3,h.byteLength>t){const m=new ArrayBuffer(t),b=new Uint8Array(m),A=new Uint8Array(h);for(let E=0;E<t;E++)b[E]=A[E];return m}return h}const ih="version",rh="logID",ah="extensions",oh="timestamp",lh="hashAlgorithm",ch="signatureAlgorithm",uh="signature",Yf="none",Qf="md5",Xf="sha1",Zf="sha224",zf="sha256",ed="sha384",td="sha512",sd="anonymous",nd="rsa",id="dsa",rd="ecdsa";class Mt extends k{constructor(e={}){super(),this.version=r(e,ih,Mt.defaultValues(ih)),this.logID=r(e,rh,Mt.defaultValues(rh)),this.timestamp=r(e,oh,Mt.defaultValues(oh)),this.extensions=r(e,ah,Mt.defaultValues(ah)),this.hashAlgorithm=r(e,lh,Mt.defaultValues(lh)),this.signatureAlgorithm=r(e,ch,Mt.defaultValues(ch)),this.signature=r(e,uh,Mt.defaultValues(uh)),"stream"in e&&e.stream&&this.fromStream(e.stream),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ih:return 0;case rh:case ah:return be;case oh:return new Date(0);case lh:case ch:return u;case uh:return be;default:return super.defaultValues(e)}}fromSchema(e){if(!(e instanceof Ru))throw new Error("Object's schema was not verified against input data for SignedCertificateTimestamp");const t=new Vn({stream:new ge({buffer:e.data})});this.fromStream(t)}fromStream(e){const t=e.getUint16();if(this.version=e.getBlock(1)[0],this.version===0){this.logID=new Uint8Array(e.getBlock(32)).buffer.slice(0),this.timestamp=new Date(er(new Uint8Array(e.getBlock(8)),8));const s=e.getUint16();switch(this.extensions=new Uint8Array(e.getBlock(s)).buffer.slice(0),e.getBlock(1)[0]){case 0:this.hashAlgorithm=Yf;break;case 1:this.hashAlgorithm=Qf;break;case 2:this.hashAlgorithm=Xf;break;case 3:this.hashAlgorithm=Zf;break;case 4:this.hashAlgorithm=zf;break;case 5:this.hashAlgorithm=ed;break;case 6:this.hashAlgorithm=td;break;default:throw new Error("Object's stream was not correct for SignedCertificateTimestamp")}switch(e.getBlock(1)[0]){case 0:this.signatureAlgorithm=sd;break;case 1:this.signatureAlgorithm=nd;break;case 2:this.signatureAlgorithm=id;break;case 3:this.signatureAlgorithm=rd;break;default:throw new Error("Object's stream was not correct for SignedCertificateTimestamp")}const n=e.getUint16();if(this.signature=new Uint8Array(e.getBlock(n)).buffer.slice(0),t!==47+s+n)throw new Error("Object's stream was not correct for SignedCertificateTimestamp")}}toSchema(){const e=this.toStream();return new Ru({data:e.stream.buffer})}toStream(){const e=new Vn;e.appendUint16(47+this.extensions.byteLength+this.signature.byteLength),e.appendChar(this.version),e.appendView(new Uint8Array(this.logID));const t=new ArrayBuffer(8),s=new Uint8Array(t),n=ks(this.timestamp.valueOf(),8);s.set(new Uint8Array(n),8-n.byteLength),e.appendView(s),e.appendUint16(this.extensions.byteLength),this.extensions.byteLength&&e.appendView(new Uint8Array(this.extensions));let i;switch(this.hashAlgorithm.toLowerCase()){case Yf:i=0;break;case Qf:i=1;break;case Xf:i=2;break;case Zf:i=3;break;case zf:i=4;break;case ed:i=5;break;case td:i=6;break;default:throw new Error(`Incorrect data for hashAlgorithm: ${this.hashAlgorithm}`)}e.appendChar(i);let o;switch(this.signatureAlgorithm.toLowerCase()){case sd:o=0;break;case nd:o=1;break;case id:o=2;break;case rd:o=3;break;default:throw new Error(`Incorrect data for signatureAlgorithm: ${this.signatureAlgorithm}`)}return e.appendChar(o),e.appendUint16(this.signature.byteLength),e.appendView(new Uint8Array(this.signature)),e}toJSON(){return{version:this.version,logID:Xu(this.logID),timestamp:this.timestamp,extensions:Xu(this.extensions),hashAlgorithm:this.hashAlgorithm,signatureAlgorithm:this.signatureAlgorithm,signature:Xu(this.signature)}}async verify(e,t,s=0,n=q(!0)){const i=Th(xu(this.logID));let o=null;const l=new Vn;for(const b of e)if(b.log_id===i){o=b.key;break}if(!o)throw new Error(`Public key not found for CT with logId: ${i}`);const c=ja(mc(o)),h=Xe.fromBER(c);l.appendChar(0),l.appendChar(0);const f=new ArrayBuffer(8),g=new Uint8Array(f),m=ks(this.timestamp.valueOf(),8);return g.set(new Uint8Array(m),8-m.byteLength),l.appendView(g),l.appendUint16(s),s===0&&l.appendUint24(t.byteLength),l.appendView(new Uint8Array(t)),l.appendUint16(this.extensions.byteLength),this.extensions.byteLength!==0&&l.appendView(new Uint8Array(this.extensions)),n.verifyWithPublicKey(l.buffer.slice(0,l.length),new B({valueHex:this.signature}),h,{algorithmId:u},"SHA-256")}}Mt.CLASS_NAME="SignedCertificateTimestamp";const Tc="timestamps";class Gu extends k{constructor(e={}){super(),this.timestamps=r(e,Tc,Gu.defaultValues(Tc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Tc?[]:super.defaultValues(e)}static compareWithDefault(e,t){return e===Tc?t.length===0:super.defaultValues(e)}static schema(e={}){var t;const s=r(e,"names",{});return(t=s.optional)!==null&&t!==void 0||(s.optional=!1),new B({name:s.blockName||"SignedCertificateTimestampList",optional:s.optional})}fromSchema(e){if(!(e instanceof B))throw new Error("Object's schema was not verified against input data for SignedCertificateTimestampList");const t=new Vn({stream:new ge({buffer:e.valueBlock.valueHex})});if(t.getUint16()!==t.length)throw new Error("Object's schema was not verified against input data for SignedCertificateTimestampList");for(;t.length;)this.timestamps.push(new Mt({stream:t}))}toSchema(){const e=new Vn;let t=0;const s=[];for(const n of this.timestamps){const i=n.toStream();s.push(i),t+=i.stream.buffer.byteLength}e.appendUint16(t);for(const n of s)e.appendView(n.stream.view);return new B({valueHex:e.stream.buffer.slice(0)})}toJSON(){return{timestamps:Array.from(this.timestamps,e=>e.toJSON())}}}Gu.CLASS_NAME="SignedCertificateTimestampList";const zo="attributes",hy=[zo];class bc extends k{constructor(e={}){super(),this.attributes=r(e,zo,bc.defaultValues(zo)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===zo?[]:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.attributes||u,value:oe.schema()})]})}fromSchema(e){C(e,hy);const t=N(e,e,bc.schema({names:{attributes:zo}}));p.assertSchema(t,this.className),this.attributes=Array.from(t.result.attributes,s=>new oe({schema:s}))}toSchema(){return new d({value:Array.from(this.attributes,e=>e.toSchema())})}toJSON(){return{attributes:Array.from(this.attributes,e=>e.toJSON())}}}bc.CLASS_NAME="SubjectDirectoryAttributes";class de{static getItems(){return this.types||(this.types={},de.register(Nm,"SubjectAltName",qa),de.register(Cm,"IssuerAltName",qa),de.register(pf,"AuthorityKeyIdentifier",En),de.register(Sf,"BasicConstraints",qi),de.register(Bw,"MicrosoftCaVersion",vc),de.register(Om,"CertificatePolicies",Wa),de.register(pw,"CertificatePoliciesMicrosoft",Wa),de.register(Cw,"MicrosoftCertTemplateV2",Da),de.register(xm,"CRLDistributionPoints",Ga),de.register(Af,"FreshestCRL",Ga),de.register(bw,"ExtKeyUsage",Sc),de.register(Im,"CertificateIssuer",Oe),de.register(bf,"AuthorityInfoAccess",Ya),de.register(Ew,"SubjectInfoAccess",Ya),de.register(Bm,"IssuingDistributionPoint",De),de.register(Vm,"NameConstraints",Ha),de.register(Tm,"PolicyConstraints",_a),de.register(Rm,"PolicyMappings",Ac),de.register(ww,"PrivateKeyUsagePeriod",Ma),de.register(Iw,"QCStatements",pc),de.register(Nw,"SignedCertificateTimestampList",Gu),de.register(dw,"SubjectDirectoryAttributes",bc)),this.types}static fromBER(e,t){const s=Be(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 el="extnID",Xs="critical",tl="extnValue",Dc="parsedValue",fy=[el,Xs,tl];class xe 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=r(e,el,xe.defaultValues(el)),this.critical=r(e,Xs,xe.defaultValues(Xs)),tl in e?this.extnValue=new B({valueHex:e.extnValue}):this.extnValue=xe.defaultValues(tl),Dc in e&&(this.parsedValue=r(e,Dc,xe.defaultValues(Dc))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case el:return u;case Xs:return!1;case tl:return new B;case Dc:return{};default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.extnID||u}),new Yt({name:t.critical||u,optional:!0}),new B({name:t.extnValue||u})]})}fromSchema(e){C(e,fy);const t=N(e,e,xe.schema({names:{extnID:el,critical:Xs,extnValue:tl}}));p.assertSchema(t,this.className),this.extnID=t.result.extnID.valueBlock.toString(),Xs 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!==xe.defaultValues(Xs)&&e.push(new Yt({value:this.critical})),e.push(this.extnValue),new d({value:e})}toJSON(){const e={extnID:this.extnID,extnValue:this.extnValue.toJSON()};return this.critical!==xe.defaultValues(Xs)&&(e.critical=this.critical),this.parsedValue&&this.parsedValue.toJSON&&(e.parsedValue=this.parsedValue.toJSON()),e}}xe.CLASS_NAME="Extension";const sl="extensions",dy=[sl];class ke extends k{constructor(e={}){super(),this.extensions=r(e,sl,ke.defaultValues(sl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===sl?[]:super.defaultValues(e)}static schema(e={},t=!1){const s=r(e,"names",{});return new d({optional:t,name:s.blockName||u,value:[new J({name:s.extensions||u,value:xe.schema(s.extension||{})})]})}fromSchema(e){C(e,dy);const t=N(e,e,ke.schema({names:{extensions:sl}}));p.assertSchema(t,this.className),this.extensions=Array.from(t.result.extensions,s=>new xe({schema:s}))}toSchema(){return new d({value:Array.from(this.extensions,e=>e.toSchema())})}toJSON(){return{extensions:this.extensions.map(e=>e.toJSON())}}}ke.CLASS_NAME="Extensions";const nl="issuer",il="serialNumber",ei="issuerUID",my=[nl,il,ei];class Qe extends k{constructor(e={}){super(),this.issuer=r(e,nl,Qe.defaultValues(nl)),this.serialNumber=r(e,il,Qe.defaultValues(il)),ei in e&&(this.issuerUID=r(e,ei,Qe.defaultValues(ei))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case nl:return new Oe;case il:return new S;case ei:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[Oe.schema(t.issuer||{}),new S({name:t.serialNumber||u}),new G({optional:!0,name:t.issuerUID||u})]})}fromSchema(e){C(e,my);const t=N(e,e,Qe.schema({names:{issuer:{names:{blockName:nl}},serialNumber:il,issuerUID:ei}}));p.assertSchema(t,this.className),this.issuer=new Oe({schema:t.result.issuer}),this.serialNumber=t.result.serialNumber,ei in t.result&&(this.issuerUID=t.result.issuerUID)}toSchema(){const e=new d({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}}Qe.CLASS_NAME="IssuerSerial";const rl="version",ti="baseCertificateID",si="subjectName",al="issuer",ol="signature",ll="serialNumber",cl="attrCertValidityPeriod",ul="attributes",ni="issuerUniqueID",ii="extensions",gy=[rl,ti,si,al,ol,ll,cl,ul,ni,ii];class Ke extends k{constructor(e={}){super(),this.version=r(e,rl,Ke.defaultValues(rl)),ti in e&&(this.baseCertificateID=r(e,ti,Ke.defaultValues(ti))),si in e&&(this.subjectName=r(e,si,Ke.defaultValues(si))),this.issuer=r(e,al,Ke.defaultValues(al)),this.signature=r(e,ol,Ke.defaultValues(ol)),this.serialNumber=r(e,ll,Ke.defaultValues(ll)),this.attrCertValidityPeriod=r(e,cl,Ke.defaultValues(cl)),this.attributes=r(e,ul,Ke.defaultValues(ul)),ni in e&&(this.issuerUniqueID=r(e,ni,Ke.defaultValues(ni))),ii in e&&(this.extensions=r(e,ii,Ke.defaultValues(ii))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case rl:return 0;case ti:return new Qe;case si:return new Oe;case al:return new Oe;case ol:return new v;case ll:return new S;case cl:return new Dt;case ul:return[];case ni:return new G;case ii:return new ke;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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:Qe.schema().valueBlock.value}),new w({name:t.subjectName||u,idBlock:{tagClass:3,tagNumber:1},value:Oe.schema().valueBlock.value})]}),Oe.schema({names:{blockName:t.issuer||u}}),v.schema(t.signature||{}),new S({name:t.serialNumber||u}),Dt.schema(t.attrCertValidityPeriod||{}),new d({name:t.attributes||u,value:[new J({value:oe.schema()})]}),new G({optional:!0,name:t.issuerUniqueID||u}),ke.schema(t.extensions||{},!0)]})}fromSchema(e){C(e,gy);const t=N(e,e,Ke.schema({names:{version:rl,baseCertificateID:ti,subjectName:si,issuer:al,signature:{names:{blockName:ol}},serialNumber:ll,attrCertValidityPeriod:{names:{blockName:cl}},attributes:ul,issuerUniqueID:ni,extensions:{names:{blockName:ii}}}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,ti in t.result&&(this.baseCertificateID=new Qe({schema:new d({value:t.result.baseCertificateID.valueBlock.value})})),si in t.result&&(this.subjectName=new Oe({schema:new d({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 Dt({schema:t.result.attrCertValidityPeriod}),this.attributes=Array.from(t.result.attributes.valueBlock.value,s=>new oe({schema:s})),ni in t.result&&(this.issuerUniqueID=t.result.issuerUniqueID),ii in t.result&&(this.extensions=new ke({schema:t.result.extensions}))}toSchema(){const e=new d({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 d({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 hl="acinfo",fl="signatureAlgorithm",dl="signatureValue",wy=[hl,dl,fl];class ms extends k{constructor(e={}){super(),this.acinfo=r(e,hl,ms.defaultValues(hl)),this.signatureAlgorithm=r(e,fl,ms.defaultValues(fl)),this.signatureValue=r(e,dl,ms.defaultValues(dl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case hl:return new Ke;case fl:return new v;case dl:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[Ke.schema(t.acinfo||{}),v.schema(t.signatureAlgorithm||{}),new G({name:t.signatureValue||u})]})}fromSchema(e){C(e,wy);const t=N(e,e,ms.schema({names:{acinfo:{names:{blockName:hl}},signatureAlgorithm:{names:{blockName:fl}},signatureValue:dl}}));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 d({value:[this.acinfo.toSchema(),this.signatureAlgorithm.toSchema(),this.signatureValue]})}toJSON(){return{acinfo:this.acinfo.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signatureValue:this.signatureValue.toJSON()}}}ms.CLASS_NAME="AttributeCertificateV1";const ml="digestedObjectType",ri="otherObjectTypeID",gl="digestAlgorithm",wl="objectDigest",yy=[ml,ri,gl,wl];class ht extends k{constructor(e={}){super(),this.digestedObjectType=r(e,ml,ht.defaultValues(ml)),ri in e&&(this.otherObjectTypeID=r(e,ri,ht.defaultValues(ri))),this.digestAlgorithm=r(e,gl,ht.defaultValues(gl)),this.objectDigest=r(e,wl,ht.defaultValues(wl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ml:return new tr;case ri:return new T;case gl:return new v;case wl:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new tr({name:t.digestedObjectType||u}),new T({optional:!0,name:t.otherObjectTypeID||u}),v.schema(t.digestAlgorithm||{}),new G({name:t.objectDigest||u})]})}fromSchema(e){C(e,yy);const t=N(e,e,ht.schema({names:{digestedObjectType:ml,otherObjectTypeID:ri,digestAlgorithm:{names:{blockName:gl}},objectDigest:wl}}));p.assertSchema(t,this.className),this.digestedObjectType=t.result.digestedObjectType,ri 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 d({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}}ht.CLASS_NAME="ObjectDigestInfo";const ai="issuerName",oi="baseCertificateID",li="objectDigestInfo",vy=[ai,oi,li];class Cn extends k{constructor(e={}){super(),ai in e&&(this.issuerName=r(e,ai,Cn.defaultValues(ai))),oi in e&&(this.baseCertificateID=r(e,oi,Cn.defaultValues(oi))),li in e&&(this.objectDigestInfo=r(e,li,Cn.defaultValues(li))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ai:return new Oe;case oi:return new Qe;case li:return new ht;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[Oe.schema({names:{blockName:t.issuerName}},!0),new w({optional:!0,name:t.baseCertificateID||u,idBlock:{tagClass:3,tagNumber:0},value:Qe.schema().valueBlock.value}),new w({optional:!0,name:t.objectDigestInfo||u,idBlock:{tagClass:3,tagNumber:1},value:ht.schema().valueBlock.value})]})}fromSchema(e){C(e,vy);const t=N(e,e,Cn.schema({names:{issuerName:ai,baseCertificateID:oi,objectDigestInfo:li}}));p.assertSchema(t,this.className),ai in t.result&&(this.issuerName=new Oe({schema:t.result.issuerName})),oi in t.result&&(this.baseCertificateID=new Qe({schema:new d({value:t.result.baseCertificateID.valueBlock.value})})),li in t.result&&(this.objectDigestInfo=new ht({schema:new d({value:t.result.objectDigestInfo.valueBlock.value})}))}toSchema(){const e=new d;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}}Cn.CLASS_NAME="V2Form";const ci="baseCertificateID",ui="entityName",hi="objectDigestInfo",Sy=[ci,ui,hi];class gs extends k{constructor(e={}){super(),ci in e&&(this.baseCertificateID=r(e,ci,gs.defaultValues(ci))),ui in e&&(this.entityName=r(e,ui,gs.defaultValues(ui))),hi in e&&(this.objectDigestInfo=r(e,hi,gs.defaultValues(hi))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ci:return new Qe;case ui:return new Oe;case hi:return new ht;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new w({optional:!0,name:t.baseCertificateID||u,idBlock:{tagClass:3,tagNumber:0},value:Qe.schema().valueBlock.value}),new w({optional:!0,name:t.entityName||u,idBlock:{tagClass:3,tagNumber:1},value:Oe.schema().valueBlock.value}),new w({optional:!0,name:t.objectDigestInfo||u,idBlock:{tagClass:3,tagNumber:2},value:ht.schema().valueBlock.value})]})}fromSchema(e){C(e,Sy);const t=N(e,e,gs.schema({names:{baseCertificateID:ci,entityName:ui,objectDigestInfo:hi}}));p.assertSchema(t,this.className),ci in t.result&&(this.baseCertificateID=new Qe({schema:new d({value:t.result.baseCertificateID.valueBlock.value})})),ui in t.result&&(this.entityName=new Oe({schema:new d({value:t.result.entityName.valueBlock.value})})),hi in t.result&&(this.objectDigestInfo=new ht({schema:new d({value:t.result.objectDigestInfo.valueBlock.value})}))}toSchema(){const e=new d;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}}gs.CLASS_NAME="Holder";const yl="version",vl="holder",Sl="issuer",Al="signature",pl="serialNumber",bl="attrCertValidityPeriod",kl="attributes",fi="issuerUniqueID",di="extensions",Ay=[yl,vl,Sl,Al,pl,bl,kl,fi,di];class qe extends k{constructor(e={}){super(),this.version=r(e,yl,qe.defaultValues(yl)),this.holder=r(e,vl,qe.defaultValues(vl)),this.issuer=r(e,Sl,qe.defaultValues(Sl)),this.signature=r(e,Al,qe.defaultValues(Al)),this.serialNumber=r(e,pl,qe.defaultValues(pl)),this.attrCertValidityPeriod=r(e,bl,qe.defaultValues(bl)),this.attributes=r(e,kl,qe.defaultValues(kl)),fi in e&&(this.issuerUniqueID=r(e,fi,qe.defaultValues(fi))),di in e&&(this.extensions=r(e,di,qe.defaultValues(di))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case yl:return 1;case vl:return new gs;case Sl:return{};case Al:return new v;case pl:return new S;case bl:return new Dt;case kl:return[];case fi:return new G;case di:return new ke;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||u}),gs.schema(t.holder||{}),new he({value:[Oe.schema({names:{blockName:t.issuer||u}}),new w({name:t.issuer||u,idBlock:{tagClass:3,tagNumber:0},value:Cn.schema().valueBlock.value})]}),v.schema(t.signature||{}),new S({name:t.serialNumber||u}),Dt.schema(t.attrCertValidityPeriod||{}),new d({name:t.attributes||u,value:[new J({value:oe.schema()})]}),new G({optional:!0,name:t.issuerUniqueID||u}),ke.schema(t.extensions||{},!0)]})}fromSchema(e){C(e,Ay);const t=N(e,e,qe.schema({names:{version:yl,holder:{names:{blockName:vl}},issuer:Sl,signature:{names:{blockName:Al}},serialNumber:pl,attrCertValidityPeriod:{names:{blockName:bl}},attributes:kl,issuerUniqueID:fi,extensions:{names:{blockName:di}}}}));if(p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.holder=new gs({schema:t.result.holder}),t.result.issuer.idBlock.tagClass===3)this.issuer=new Cn({schema:new d({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 Dt({schema:t.result.attrCertValidityPeriod}),this.attributes=Array.from(t.result.attributes.valueBlock.value,s=>new oe({schema:s})),fi in t.result&&(this.issuerUniqueID=t.result.issuerUniqueID),di in t.result&&(this.extensions=new ke({schema:t.result.extensions}))}toSchema(){const e=new d({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 d({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}}qe.CLASS_NAME="AttributeCertificateInfoV2";const El="acinfo",Nl="signatureAlgorithm",Cl="signatureValue",py=[El,Nl,Cl];class ft extends k{constructor(e={}){super(),this.acinfo=r(e,El,ft.defaultValues(El)),this.signatureAlgorithm=r(e,Nl,ft.defaultValues(Nl)),this.signatureValue=r(e,Cl,ft.defaultValues(Cl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case El:return new qe;case Nl:return new v;case Cl:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[qe.schema(t.acinfo||{}),v.schema(t.signatureAlgorithm||{}),new G({name:t.signatureValue||u})]})}fromSchema(e){C(e,py);const t=N(e,e,ft.schema({names:{acinfo:{names:{blockName:El}},signatureAlgorithm:{names:{blockName:Nl}},signatureValue:Cl}}));p.assertSchema(t,this.className),this.acinfo=new qe({schema:t.result.acinfo}),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}toSchema(){return new d({value:[this.acinfo.toSchema(),this.signatureAlgorithm.toSchema(),this.signatureValue]})}toJSON(){return{acinfo:this.acinfo.toJSON(),signatureAlgorithm:this.signatureAlgorithm.toJSON(),signatureValue:this.signatureValue.toJSON()}}}ft.CLASS_NAME="AttributeCertificateV2";const mi="contentType",Nr="content",by=[mi,Nr];class le extends k{constructor(e={}){super(),this.contentType=r(e,mi,le.defaultValues(mi)),this.content=r(e,Nr,le.defaultValues(Nr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case mi:return u;case Nr:return new K;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case mi:return typeof t=="string"&&t===this.defaultValues(mi);case Nr:return t instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return"optional"in t||(t.optional=!1),new d({name:t.blockName||"ContentInfo",optional:t.optional,value:[new T({name:t.contentType||mi}),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.content||Nr})]})]})}fromSchema(e){C(e,by);const t=N(e,e,le.schema());p.assertSchema(t,this.className),this.contentType=t.result.contentType.valueBlock.toString(),this.content=t.result.content}toSchema(){return new d({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}}le.CLASS_NAME="ContentInfo";le.DATA=kf;le.SIGNED_DATA=Dm;le.ENVELOPED_DATA=Pm;le.ENCRYPTED_DATA=Lm;const hh="type",fh="value",_h="utcTimeName",Mh="generalTimeName",ky=[_h,Mh];var ad;(function(a){a[a.UTCTime=0]="UTCTime",a[a.GeneralizedTime=1]="GeneralizedTime",a[a.empty=2]="empty"})(ad||(ad={}));class Ce extends k{constructor(e={}){super(),this.type=r(e,hh,Ce.defaultValues(hh)),this.value=r(e,fh,Ce.defaultValues(fh)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case hh:return 0;case fh:return new Date(0,0,0);default:return super.defaultValues(e)}}static schema(e={},t=!1){const s=r(e,"names",{});return new he({optional:t,value:[new Fa({name:s.utcTimeName||u}),new ue({name:s.generalTimeName||u})]})}fromSchema(e){C(e,ky);const t=N(e,e,Ce.schema({names:{utcTimeName:_h,generalTimeName:Mh}}));p.assertSchema(t,this.className),_h in t.result&&(this.type=0,this.value=t.result.utcTimeName.toDate()),Mh in t.result&&(this.type=1,this.value=t.result.generalTimeName.toDate())}toSchema(){return this.type===0?new Fa({valueDate:this.value}):this.type===1?new ue({valueDate:this.value}):{}}toJSON(){return{type:this.type,value:this.value}}}Ce.CLASS_NAME="Time";const dh="tbs",Zs="version",eu="serialNumber",tu="signature",su="issuer",nu="notBefore",iu="notAfter",ru="subject",au="subjectPublicKeyInfo",Bl="issuerUniqueID",Il="subjectUniqueID",Vl="extensions",xl="signatureAlgorithm",Ol="signatureValue",mt="tbsCertificate",Du=`${mt}.${Zs}`,Ef=`${mt}.${eu}`,Nf=`${mt}.${tu}`,Cf=`${mt}.${su}`,Pu=`${mt}.${nu}`,Lu=`${mt}.${iu}`,Bf=`${mt}.${ru}`,If=`${mt}.${au}`,Uu=`${mt}.${Bl}`,Hu=`${mt}.${Il}`,uc=`${mt}.${Vl}`,Ey=[mt,Du,Ef,Nf,Cf,Pu,Lu,Bf,If,Uu,Hu,uc,xl,Ol];function Ny(a={}){const e=r(a,"names",{});return new d({name:e.blockName||mt,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({name:e.tbsCertificateVersion||Du})]}),new S({name:e.tbsCertificateSerialNumber||Ef}),v.schema(e.signature||{names:{blockName:Nf}}),re.schema(e.issuer||{names:{blockName:Cf}}),new d({name:e.tbsCertificateValidity||"tbsCertificate.validity",value:[Ce.schema(e.notBefore||{names:{utcTimeName:Pu,generalTimeName:Pu}}),Ce.schema(e.notAfter||{names:{utcTimeName:Lu,generalTimeName:Lu}})]}),re.schema(e.subject||{names:{blockName:Bf}}),Xe.schema(e.subjectPublicKeyInfo||{names:{blockName:If}}),new _({name:e.tbsCertificateIssuerUniqueID||Uu,optional:!0,idBlock:{tagClass:3,tagNumber:1}}),new _({name:e.tbsCertificateSubjectUniqueID||Hu,optional:!0,idBlock:{tagClass:3,tagNumber:2}}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:3},value:[ke.schema(e.extensions||{names:{blockName:uc}})]})]})}class X extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(r(e,dh,X.defaultValues(dh))),this.version=r(e,Zs,X.defaultValues(Zs)),this.serialNumber=r(e,eu,X.defaultValues(eu)),this.signature=r(e,tu,X.defaultValues(tu)),this.issuer=r(e,su,X.defaultValues(su)),this.notBefore=r(e,nu,X.defaultValues(nu)),this.notAfter=r(e,iu,X.defaultValues(iu)),this.subject=r(e,ru,X.defaultValues(ru)),this.subjectPublicKeyInfo=r(e,au,X.defaultValues(au)),Bl in e&&(this.issuerUniqueID=r(e,Bl,X.defaultValues(Bl))),Il in e&&(this.subjectUniqueID=r(e,Il,X.defaultValues(Il))),Vl in e&&(this.extensions=r(e,Vl,X.defaultValues(Vl))),this.signatureAlgorithm=r(e,xl,X.defaultValues(xl)),this.signatureValue=r(e,Ol,X.defaultValues(Ol)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case dh:return be;case Zs:return 0;case eu:return new S;case tu:return new v;case su:return new re;case nu:return new Ce;case iu:return new Ce;case ru:return new re;case au:return new Xe;case Bl:return be;case Il:return be;case Vl:return[];case xl:return new v;case Ol:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[Ny(t.tbsCertificate),v.schema(t.signatureAlgorithm||{names:{blockName:xl}}),new G({name:t.signatureValue||Ol})]})}fromSchema(e){C(e,Ey);const t=N(e,e,X.schema({names:{tbsCertificate:{names:{extensions:{names:{extensions:uc}}}}}}));p.assertSchema(t,this.className),this.tbsView=t.result.tbsCertificate.valueBeforeDecodeView,Du in t.result&&(this.version=t.result[Du].valueBlock.valueDec),this.serialNumber=t.result[Ef],this.signature=new v({schema:t.result[Nf]}),this.issuer=new re({schema:t.result[Cf]}),this.notBefore=new Ce({schema:t.result[Pu]}),this.notAfter=new Ce({schema:t.result[Lu]}),this.subject=new re({schema:t.result[Bf]}),this.subjectPublicKeyInfo=new Xe({schema:t.result[If]}),Uu in t.result&&(this.issuerUniqueID=t.result[Uu].valueBlock.valueHex),Hu in t.result&&(this.subjectUniqueID=t.result[Hu].valueBlock.valueHex),uc in t.result&&(this.extensions=Array.from(t.result[uc],s=>new xe({schema:s}))),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}encodeTBS(){const e=[];return Zs in this&&this.version!==X.defaultValues(Zs)&&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 d({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 d({value:Array.from(this.extensions,t=>t.toSchema())})]})),new d({value:e})}toSchema(e=!1){let t;if(e===!1){if(!this.tbsView.byteLength)return X.schema().value[0];const s=Be(this.tbsView);p.assert(s,"TBS Certificate"),t=s.result}else t=this.encodeTBS();return new d({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 Zs in this&&this.version!==X.defaultValues(Zs)&&(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 G({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 Xe))throw new Error("Please provide issuer certificate as a parameter");return t.verifyWithPublicKey(this.tbsView,this.signatureValue,s,this.signatureAlgorithm)}}X.CLASS_NAME="Certificate";function Km(a,e=null){if(e&&a.issuer.isEqual(e.issuer)&&a.serialNumber.isEqual(e.serialNumber))return null;let t=!1;if(a.extensions){for(const s of a.extensions)if(s.extnID===Sf&&s.parsedValue instanceof qi&&s.parsedValue.cA){t=!0;break}}return t?a:null}const Cr="certId",Br="certValue",or="parsedValue",Cy=[Cr,Br];class ws extends k{constructor(e={}){super(),this.certId=r(e,Cr,ws.defaultValues(Cr)),this.certValue=r(e,Br,ws.defaultValues(Br)),or in e&&(this.parsedValue=r(e,or,ws.defaultValues(or))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Cr:return u;case Br:return new K;case or:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Cr:return t===u;case Br:return t instanceof K;case or:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,Cy);const t=N(e,e,ws.schema({names:{id:Cr,value:Br}}));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 Hh:try{this.parsedValue=X.fromBER(s)}catch{ft.fromBER(s)}break;case Kf:this.parsedValue=ft.fromBER(s);break;case xw:default:throw new Error(`Incorrect CERT_ID value in CertBag: ${this.certId}`)}}toSchema(){return or in this&&("acinfo"in this.parsedValue?this.certId=Kf:this.certId=Hh,this.certValue=new B({valueHex:this.parsedValue.toSchema().toBER(!1)})),new d({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()}}}ws.CLASS_NAME="CertBag";const Rl="userCertificate",Ir="revocationDate",gi="crlEntryExtensions",By=[Rl,Ir,gi];class Ji extends k{constructor(e={}){super(),this.userCertificate=r(e,Rl,Ji.defaultValues(Rl)),this.revocationDate=r(e,Ir,Ji.defaultValues(Ir)),gi in e&&(this.crlEntryExtensions=r(e,gi,Ji.defaultValues(gi))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Rl:return new S;case Ir:return new Ce;case gi:return new ke;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.userCertificate||Rl}),Ce.schema({names:{utcTimeName:t.revocationDate||Ir,generalTimeName:t.revocationDate||Ir}}),ke.schema({names:{blockName:t.crlEntryExtensions||gi}},!0)]})}fromSchema(e){C(e,By);const t=N(e,e,Ji.schema());p.assertSchema(t,this.className),this.userCertificate=t.result.userCertificate,this.revocationDate=new Ce({schema:t.result.revocationDate}),gi 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 d({value:e})}toJSON(){const e={userCertificate:this.userCertificate.toJSON(),revocationDate:this.revocationDate.toJSON()};return this.crlEntryExtensions&&(e.crlEntryExtensions=this.crlEntryExtensions.toJSON()),e}}Ji.CLASS_NAME="RevokedCertificate";const mh="tbs",io="version",gh="signature",wh="issuer",yh="thisUpdate",Pc="nextUpdate",Lc="revokedCertificates",Uc="crlExtensions",Tl="signatureAlgorithm",Dl="signatureValue",Cs="tbsCertList",_u=`${Cs}.version`,Vf=`${Cs}.signature`,xf=`${Cs}.issuer`,Mu=`${Cs}.thisUpdate`,kc=`${Cs}.nextUpdate`,$u=`${Cs}.revokedCertificates`,Ku=`${Cs}.extensions`,Iy=[Cs,_u,Vf,xf,Mu,kc,$u,Ku,Tl,Dl];function Vy(a={}){const e=r(a,"names",{});return new d({name:e.blockName||Cs,value:[new S({optional:!0,name:e.tbsCertListVersion||_u,value:2}),v.schema(e.signature||{names:{blockName:Vf}}),re.schema(e.issuer||{names:{blockName:xf}}),Ce.schema(e.tbsCertListThisUpdate||{names:{utcTimeName:Mu,generalTimeName:Mu}}),Ce.schema(e.tbsCertListNextUpdate||{names:{utcTimeName:kc,generalTimeName:kc}},!0),new d({optional:!0,value:[new J({name:e.tbsCertListRevokedCertificates||$u,value:new d({value:[new S,Ce.schema(),ke.schema({},!0)]})})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[ke.schema(e.crlExtensions||{names:{blockName:Ku}})]})]})}const xy=[pf,Cm,yw,vw,Bm,Af,bf,Sw,Aw,Im];class Ve extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(r(e,mh,Ve.defaultValues(mh))),this.version=r(e,io,Ve.defaultValues(io)),this.signature=r(e,gh,Ve.defaultValues(gh)),this.issuer=r(e,wh,Ve.defaultValues(wh)),this.thisUpdate=r(e,yh,Ve.defaultValues(yh)),Pc in e&&(this.nextUpdate=r(e,Pc,Ve.defaultValues(Pc))),Lc in e&&(this.revokedCertificates=r(e,Lc,Ve.defaultValues(Lc))),Uc in e&&(this.crlExtensions=r(e,Uc,Ve.defaultValues(Uc))),this.signatureAlgorithm=r(e,Tl,Ve.defaultValues(Tl)),this.signatureValue=r(e,Dl,Ve.defaultValues(Dl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case mh:return be;case io:return 0;case gh:return new v;case wh:return new re;case yh:return new Ce;case Pc:return new Ce;case Lc:return[];case Uc:return new ke;case Tl:return new v;case Dl:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||"CertificateList",value:[Vy(e),v.schema(t.signatureAlgorithm||{names:{blockName:Tl}}),new G({name:t.signatureValue||Dl})]})}fromSchema(e){C(e,Iy);const t=N(e,e,Ve.schema());p.assertSchema(t,this.className),this.tbsView=t.result.tbsCertList.valueBeforeDecodeView,_u in t.result&&(this.version=t.result[_u].valueBlock.valueDec),this.signature=new v({schema:t.result[Vf]}),this.issuer=new re({schema:t.result[xf]}),this.thisUpdate=new Ce({schema:t.result[Mu]}),kc in t.result&&(this.nextUpdate=new Ce({schema:t.result[kc]})),$u in t.result&&(this.revokedCertificates=Array.from(t.result[$u],s=>new Ji({schema:s}))),Ku in t.result&&(this.crlExtensions=new ke({schema:t.result[Ku]})),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signatureValue=t.result.signatureValue}encodeTBS(){const e=[];return this.version!==Ve.defaultValues(io)&&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 d({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 d({value:e})}toSchema(e=!1){let t;if(e)t=this.encodeTBS();else{if(!this.tbsView.byteLength)return Ve.schema();const s=Be(this.tbsView);p.assert(s,"TBS Certificate Revocation List"),t=s.result}return new d({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!==Ve.defaultValues(io)&&(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 G({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)}}Ve.CLASS_NAME="CertificateRevocationList";const Vr="crlId",xr="crlValue",ro="parsedValue",Oy=[Vr,xr];class ji extends k{constructor(e={}){super(),this.crlId=r(e,Vr,ji.defaultValues(Vr)),this.crlValue=r(e,xr,ji.defaultValues(xr)),ro in e&&(this.parsedValue=r(e,ro,ji.defaultValues(ro))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Vr:return u;case xr:return new K;case ro:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Vr:return t===u;case xr:return t instanceof K;case ro:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,Oy);const t=N(e,e,ji.schema({names:{id:Vr,value:xr}}));if(p.assertSchema(t,this.className),this.crlId=t.result.crlId.valueBlock.toString(),this.crlValue=t.result.crlValue,this.crlId===Jf)this.parsedValue=Ve.fromBER(this.certValue.valueBlock.valueHex);else throw new Error(`Incorrect CRL_ID value in CRLBag: ${this.crlId}`)}toSchema(){return this.parsedValue&&(this.crlId=Jf,this.crlValue=new B({valueHex:this.parsedValue.toSchema().toBER(!1)})),new d({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 Or="version",Rr="encryptedContentInfo",zs="unprotectedAttrs",Ry=[Or,Rr,zs];class Ft extends k{constructor(e={}){super(),this.version=r(e,Or,Ft.defaultValues(Or)),this.encryptedContentInfo=r(e,Rr,Ft.defaultValues(Rr)),zs in e&&(this.unprotectedAttrs=r(e,zs,Ft.defaultValues(zs))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Or:return 0;case Rr:return new Ee;case zs:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Or:return t===0;case Rr:return Ee.compareWithDefault("contentType",t.contentType)&&Ee.compareWithDefault("contentEncryptionAlgorithm",t.contentEncryptionAlgorithm)&&Ee.compareWithDefault("encryptedContent",t.encryptedContent);case zs:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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:oe.schema()})]})]})}fromSchema(e){C(e,Ry);const t=N(e,e,Ft.schema({names:{version:Or,encryptedContentInfo:{names:{blockName:Rr}},unprotectedAttrs:zs}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.encryptedContentInfo=new Ee({schema:t.result.encryptedContentInfo}),zs in t.result&&(this.unprotectedAttrs=Array.from(t.result.unprotectedAttrs,s=>new oe({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 d({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)}}Ft.CLASS_NAME="EncryptedData";const wi="encryptionAlgorithm",en="encryptedData",ao="parsedValue",Ty=[wi,en];class Kt extends k{constructor(e={}){super(),this.encryptionAlgorithm=r(e,wi,Kt.defaultValues(wi)),this.encryptedData=r(e,en,Kt.defaultValues(en)),ao in e&&(this.parsedValue=r(e,ao,Kt.defaultValues(ao))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case wi:return new v;case en:return new B;case ao:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case wi:return v.compareWithDefault("algorithmId",t.algorithmId)&&!("algorithmParams"in t);case en:return t.isEqual(Kt.defaultValues(e));case ao:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.encryptionAlgorithm||{names:{blockName:wi}}),new he({value:[new B({name:t.encryptedData||en}),new B({idBlock:{isConstructed:!0},name:t.encryptedData||en})]})]})}fromSchema(e){C(e,Ty);const t=N(e,e,Kt.schema({names:{encryptionAlgorithm:{names:{blockName:wi}},encryptedData:en}}));p.assertSchema(t,this.className),this.encryptionAlgorithm=new v({schema:t.result.encryptionAlgorithm}),this.encryptedData=t.result.encryptedData}toSchema(){return new d({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 Ft({encryptedContentInfo:new Ee({contentEncryptionAlgorithm:this.encryptionAlgorithm,encryptedContent:this.encryptedData})}).decrypt(e,t);this.parsedValue=nt.fromBER(n)}async makeInternalValues(e,t=q(!0)){if(!this.parsedValue)throw new Error('Please initialize "parsedValue" first');const s=new Ft,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}}Kt.CLASS_NAME="PKCS8ShroudedKeyBag";const Tr="secretTypeId",Dr="secretValue",Dy=[Tr,Dr];class $a extends k{constructor(e={}){super(),this.secretTypeId=r(e,Tr,$a.defaultValues(Tr)),this.secretValue=r(e,Dr,$a.defaultValues(Dr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Tr:return u;case Dr:return new K;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Tr:return t===u;case Dr:return t instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,Dy);const t=N(e,e,$a.schema({names:{id:Tr,value:Dr}}));p.assertSchema(t,this.className),this.secretTypeId=t.result.secretTypeId.valueBlock.toString(),this.secretValue=t.result.secretValue}toSchema(){return new d({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()}}}$a.CLASS_NAME="SecretBag";class pn{static getItems(){return this.items||(this.items={},pn.register("1.2.840.113549.1.12.10.1.1",nt),pn.register("1.2.840.113549.1.12.10.1.2",Kt),pn.register("1.2.840.113549.1.12.10.1.3",ws),pn.register("1.2.840.113549.1.12.10.1.4",ji),pn.register("1.2.840.113549.1.12.10.1.5",$a),pn.register("1.2.840.113549.1.12.10.1.6",Tt)),this.items}static register(e,t){this.getItems()[e]=t}static find(e){return this.getItems()[e]||null}}const yi="bagId",vi="bagValue",as="bagAttributes",Py=[yi,vi,as];class qt extends k{constructor(e={}){super(),this.bagId=r(e,yi,qt.defaultValues(yi)),this.bagValue=r(e,vi,qt.defaultValues(vi)),as in e&&(this.bagAttributes=r(e,as,qt.defaultValues(as))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case yi:return u;case vi:return new K;case as:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case yi:return t===u;case vi:return t instanceof K;case as:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.bagId||yi}),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.bagValue||vi})]}),new pe({optional:!0,value:[new J({name:t.bagAttributes||as,value:oe.schema()})]})]})}fromSchema(e){C(e,Py);const t=N(e,e,qt.schema({names:{bagId:yi,bagValue:vi,bagAttributes:as}}));p.assertSchema(t,this.className),this.bagId=t.result.bagId.valueBlock.toString();const s=pn.find(this.bagId);if(!s)throw new Error(`Invalid BAG_ID for SafeBag: ${this.bagId}`);this.bagValue=new s({schema:t.result.bagValue}),as in t.result&&(this.bagAttributes=Array.from(t.result.bagAttributes,n=>new oe({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 d({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}}qt.CLASS_NAME="SafeBag";const lr="safeBags";class Tt extends k{constructor(e={}){super(),this.safeBags=r(e,lr,Tt.defaultValues(lr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===lr?[]:super.defaultValues(e)}static compareWithDefault(e,t){return e===lr?t.length===0:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.safeBags||u,value:qt.schema()})]})}fromSchema(e){C(e,[lr]);const t=N(e,e,Tt.schema({names:{safeBags:lr}}));p.assertSchema(t,this.className),this.safeBags=Array.from(t.result.safeBags,s=>new qt({schema:s}))}toSchema(){return new d({value:Array.from(this.safeBags,e=>e.toSchema())})}toJSON(){return{safeBags:Array.from(this.safeBags,e=>e.toJSON())}}}Tt.CLASS_NAME="SafeContents";const Pl="otherCertFormat",Ll="otherCert",Ly=[Pl,Ll];class On extends k{constructor(e={}){super(),this.otherCertFormat=r(e,Pl,On.defaultValues(Pl)),this.otherCert=r(e,Ll,On.defaultValues(Ll)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Pl:return u;case Ll:return new K;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.otherCertFormat||Pl}),new K({name:t.otherCert||Ll})]})}fromSchema(e){C(e,Ly);const t=N(e,e,On.schema());p.assertSchema(t,this.className),this.otherCertFormat=t.result.otherCertFormat.valueBlock.toString(),this.otherCert=t.result.otherCert}toSchema(){return new d({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 Ul="certificates",Uy=[Ul];class Wt extends k{constructor(e={}){super(),this.certificates=r(e,Ul,Wt.defaultValues(Ul)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Ul?[]:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new pe({name:t.blockName||u,value:[new J({name:t.certificates||Ul,value:new he({value:[X.schema(),new w({idBlock:{tagClass:3,tagNumber:0},value:[new K]}),new w({idBlock:{tagClass:3,tagNumber:1},value:[new d]}),new w({idBlock:{tagClass:3,tagNumber:2},value:ft.schema().valueBlock.value}),new w({idBlock:{tagClass:3,tagNumber:3},value:On.schema().valueBlock.value})]})})]})}fromSchema(e){C(e,Uy);const t=N(e,e,Wt.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 X({schema:s});const i=new d({value:s.valueBlock.value});switch(n){case 1:return i.valueBlock.value[0].valueBlock.value[0].valueBlock.valueDec===1?new ft({schema:i}):new ms({schema:i});case 2:return new ft({schema:i});case 3:return new On({schema:i})}return s})}toSchema(){return new pe({value:Array.from(this.certificates,e=>{switch(!0){case e instanceof X:return e.toSchema();case e instanceof ms:return new w({idBlock:{tagClass:3,tagNumber:1},value:e.toSchema().valueBlock.value});case e instanceof ft:return new w({idBlock:{tagClass:3,tagNumber:2},value:e.toSchema().valueBlock.value});case e instanceof On: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())}}}Wt.CLASS_NAME="CertificateSet";const Hl="otherRevInfoFormat",_l="otherRevInfo",Hy=[Hl,_l];class As extends k{constructor(e={}){super(),this.otherRevInfoFormat=r(e,Hl,As.defaultValues(Hl)),this.otherRevInfo=r(e,_l,As.defaultValues(_l)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Hl:return u;case _l:return new K;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.otherRevInfoFormat||Hl}),new K({name:t.otherRevInfo||_l})]})}fromSchema(e){C(e,Hy);const t=N(e,e,As.schema());p.assertSchema(t,this.className),this.otherRevInfoFormat=t.result.otherRevInfoFormat.valueBlock.toString(),this.otherRevInfo=t.result.otherRevInfo}toSchema(){return new d({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}}As.CLASS_NAME="OtherRevocationInfoFormat";const Ml="crls",vh="otherRevocationInfos",_y=[Ml];class ps extends k{constructor(e={}){super(),this.crls=r(e,Ml,ps.defaultValues(Ml)),this.otherRevocationInfos=r(e,vh,ps.defaultValues(vh)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ml:return[];case vh:return[];default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new pe({name:t.blockName||u,value:[new J({name:t.crls||u,value:new he({value:[Ve.schema(),new w({idBlock:{tagClass:3,tagNumber:1},value:[new T,new K]})]})})]})}fromSchema(e){C(e,_y);const t=N(e,e,ps.schema({names:{crls:Ml}}));if(p.assertSchema(t,this.className),t.result.crls)for(const s of t.result.crls)s.idBlock.tagClass===1?this.crls.push(new Ve({schema:s})):this.otherRevocationInfos.push(new As({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())}}}ps.CLASS_NAME="RevocationInfoChoices";const $l="certs",Si="crls",My=[$l,Si];class zi extends k{constructor(e={}){super(),this.crls=r(e,Si,zi.defaultValues(Si)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case $l:return new Wt;case Si:return new ps;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case $l:return t.certificates.length===0;case Si:return t.crls.length===0&&t.otherRevocationInfos.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new w({name:t.certs||u,optional:!0,idBlock:{tagClass:3,tagNumber:0},value:Wt.schema().valueBlock.value}),new w({name:t.crls||u,optional:!0,idBlock:{tagClass:3,tagNumber:1},value:ps.schema().valueBlock.value})]})}fromSchema(e){C(e,My);const t=N(e,e,zi.schema({names:{certs:$l,crls:Si}}));p.assertSchema(t,this.className),$l in t.result&&(this.certs=new Wt({schema:new pe({value:t.result.certs.valueBlock.value})})),Si in t.result&&(this.crls=new ps({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 d({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 Kl="issuer",Jl="serialNumber",$y=[Kl,Jl];class Ie extends k{constructor(e={}){super(),this.issuer=r(e,Kl,Ie.defaultValues(Kl)),this.serialNumber=r(e,Jl,Ie.defaultValues(Jl)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Kl:return new re;case Jl:return new S;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[re.schema(t.issuer||{}),new S({name:t.serialNumber||u})]})}fromSchema(e){C(e,$y);const t=N(e,e,Ie.schema({names:{issuer:{names:{blockName:Kl}},serialNumber:Jl}}));p.assertSchema(t,this.className),this.issuer=new re({schema:t.result.issuer}),this.serialNumber=t.result.serialNumber}toSchema(){return new d({value:[this.issuer.toSchema(),this.serialNumber]})}toJSON(){return{issuer:this.issuer.toJSON(),serialNumber:this.serialNumber.toJSON()}}}Ie.CLASS_NAME="IssuerAndSerialNumber";const Hc="variant",oo="value",Ky=["blockName"];class Ka extends k{constructor(e={}){super(),this.variant=r(e,Hc,Ka.defaultValues(Hc)),oo in e&&(this.value=r(e,oo,Ka.defaultValues(oo))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Hc:return-1;case oo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Hc:return t===-1;case oo:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new he({value:[Ie.schema({names:{blockName:t.blockName||u}}),new _({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:0}})]})}fromSchema(e){C(e,Ky);const t=N(e,e,Ka.schema({names:{blockName:"blockName"}}));p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1?(this.variant=1,this.value=new Ie({schema:t.result.blockName})):(this.variant=2,this.value=new B({valueHex:t.result.blockName.valueBlock.valueHex}))}toSchema(){switch(this.variant){case 1:if(!(this.value instanceof Ie))throw new Error("Incorrect type of RecipientIdentifier.value. It should be IssuerAndSerialNumber.");return this.value.toSchema();case 2:if(!(this.value instanceof B))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}}Ka.CLASS_NAME="RecipientIdentifier";const Ai="version",Pr="rid",Lr="keyEncryptionAlgorithm",Ur="encryptedKey",_c="recipientCertificate",Jy=[Ai,Pr,Lr,Ur];class at extends k{constructor(e={}){super(),this.version=r(e,Ai,at.defaultValues(Ai)),this.rid=r(e,Pr,at.defaultValues(Pr)),this.keyEncryptionAlgorithm=r(e,Lr,at.defaultValues(Lr)),this.encryptedKey=r(e,Ur,at.defaultValues(Ur)),this.recipientCertificate=r(e,_c,at.defaultValues(_c)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ai:return-1;case Pr:return{};case Lr:return new v;case Ur:return new B;case _c:return new X;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ai:return t===at.defaultValues(Ai);case Pr:return Object.keys(t).length===0;case Lr:case Ur:return t.isEqual(at.defaultValues(e));case _c:return!1;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||u}),Ka.schema(t.rid||{}),v.schema(t.keyEncryptionAlgorithm||{}),new B({name:t.encryptedKey||u})]})}fromSchema(e){C(e,Jy);const t=N(e,e,at.schema({names:{version:Ai,rid:{names:{blockName:Pr}},keyEncryptionAlgorithm:{names:{blockName:Lr}},encryptedKey:Ur}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,t.result.rid.idBlock.tagClass===3?this.rid=new B({valueHex:t.result.rid.valueBlock.valueHex}):this.rid=new Ie({schema:t.result.rid}),this.keyEncryptionAlgorithm=new v({schema:t.result.keyEncryptionAlgorithm}),this.encryptedKey=t.result.encryptedKey}toSchema(){const e=[];return this.rid instanceof Ie?(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 d({value:e})}toJSON(){return{version:this.version,rid:this.rid.toJSON(),keyEncryptionAlgorithm:this.keyEncryptionAlgorithm.toJSON(),encryptedKey:this.encryptedKey.toJSON()}}}at.CLASS_NAME="KeyTransRecipientInfo";const Hr="algorithm",_r="publicKey",jy=[Hr,_r];class ys extends k{constructor(e={}){super(),this.algorithm=r(e,Hr,ys.defaultValues(Hr)),this.publicKey=r(e,_r,ys.defaultValues(_r)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Hr:return new v;case _r:return new G;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Hr:case _r:return t.isEqual(ys.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.algorithm||{}),new G({name:t.publicKey||u})]})}fromSchema(e){C(e,jy);const t=N(e,e,ys.schema({names:{algorithm:{names:{blockName:Hr}},publicKey:_r}}));p.assertSchema(t,this.className),this.algorithm=new v({schema:t.result.algorithm}),this.publicKey=t.result.publicKey}toSchema(){return new d({value:[this.algorithm.toSchema(),this.publicKey]})}toJSON(){return{algorithm:this.algorithm.toJSON(),publicKey:this.publicKey.toJSON()}}}ys.CLASS_NAME="OriginatorPublicKey";const Mc="variant",lo="value",Fy=["blockName"];class bs extends k{constructor(e={}){super(),this.variant=r(e,Mc,bs.defaultValues(Mc)),lo in e&&(this.value=r(e,lo,bs.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=r(e,"names",{});return new he({value:[Ie.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:ys.schema().valueBlock.value})]})}fromSchema(e){C(e,Fy);const t=N(e,e,bs.schema({names:{blockName:"blockName"}}));p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1?(this.variant=1,this.value=new Ie({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 ys({schema:new d({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}}bs.CLASS_NAME="OriginatorIdentifierOrKey";const Mr="keyAttrId",_t="keyAttr",qy=[Mr,_t];class Pt extends k{constructor(e={}){super(),this.keyAttrId=r(e,Mr,Pt.defaultValues(Mr)),_t in e&&(this.keyAttr=r(e,_t,Pt.defaultValues(_t))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Mr:return u;case _t:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Mr:return typeof t=="string"&&t===u;case _t:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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,qy);const t=N(e,e,Pt.schema({names:{keyAttrId:Mr,keyAttr:_t}}));p.assertSchema(t,this.className),this.keyAttrId=t.result.keyAttrId.valueBlock.toString(),_t in t.result&&(this.keyAttr=t.result.keyAttr)}toSchema(){const e=[];return e.push(new T({value:this.keyAttrId})),_t in this&&e.push(this.keyAttr),new d({value:e})}toJSON(){const e={keyAttrId:this.keyAttrId};return _t in this&&(e.keyAttr=this.keyAttr.toJSON()),e}}Pt.CLASS_NAME="OtherKeyAttribute";const pi="subjectKeyIdentifier",tn="date",sn="other",Wy=[pi,tn,sn];class Jt extends k{constructor(e={}){super(),this.subjectKeyIdentifier=r(e,pi,Jt.defaultValues(pi)),tn in e&&(this.date=r(e,tn,Jt.defaultValues(tn))),sn in e&&(this.other=r(e,sn,Jt.defaultValues(sn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case pi:return new B;case tn:return new ue;case sn:return new Pt;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case pi:return t.isEqual(Jt.defaultValues(pi));case tn:return t.year===0&&t.month===0&&t.day===0&&t.hour===0&&t.minute===0&&t.second===0&&t.millisecond===0;case sn:return t.keyAttrId===u&&!("keyAttr"in t);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new B({name:t.subjectKeyIdentifier||u}),new ue({optional:!0,name:t.date||u}),Pt.schema(t.other||{})]})}fromSchema(e){C(e,Wy);const t=N(e,e,Jt.schema({names:{subjectKeyIdentifier:pi,date:tn,other:{names:{blockName:sn}}}}));p.assertSchema(t,this.className),this.subjectKeyIdentifier=t.result.subjectKeyIdentifier,tn in t.result&&(this.date=t.result.date),sn in t.result&&(this.other=new Pt({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 d({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}}Jt.CLASS_NAME="RecipientKeyIdentifier";const $c="variant",Kc="value",Gy=["blockName"];class Gt extends k{constructor(e={}){super(),this.variant=r(e,$c,Gt.defaultValues($c)),this.value=r(e,Kc,Gt.defaultValues(Kc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case $c:return-1;case Kc:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case $c:return t===-1;case Kc:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new he({value:[Ie.schema(t.issuerAndSerialNumber||{names:{blockName:t.blockName||u}}),new w({name:t.blockName||u,idBlock:{tagClass:3,tagNumber:0},value:Jt.schema(t.rKeyId||{names:{blockName:t.blockName||u}}).valueBlock.value})]})}fromSchema(e){C(e,Gy);const t=N(e,e,Gt.schema({names:{blockName:"blockName"}}));p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1?(this.variant=1,this.value=new Ie({schema:t.result.blockName})):(this.variant=2,this.value=new Jt({schema:new d({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}}Gt.CLASS_NAME="KeyAgreeRecipientIdentifier";const $r="rid",bi="encryptedKey",Yy=[$r,bi];class vs extends k{constructor(e={}){super(),this.rid=r(e,$r,vs.defaultValues($r)),this.encryptedKey=r(e,bi,vs.defaultValues(bi)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case $r:return new Gt;case bi:return new B;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case $r:return t.variant===-1&&!("value"in t);case bi:return t.isEqual(vs.defaultValues(bi));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[Gt.schema(t.rid||{}),new B({name:t.encryptedKey||u})]})}fromSchema(e){C(e,Yy);const t=N(e,e,vs.schema({names:{rid:{names:{blockName:$r}},encryptedKey:bi}}));p.assertSchema(t,this.className),this.rid=new Gt({schema:t.result.rid}),this.encryptedKey=t.result.encryptedKey}toSchema(){return new d({value:[this.rid.toSchema(),this.encryptedKey]})}toJSON(){return{rid:this.rid.toJSON(),encryptedKey:this.encryptedKey.toJSON()}}}vs.CLASS_NAME="RecipientEncryptedKey";const Jc="encryptedKeys",Jm="RecipientEncryptedKeys",Qy=[Jm];class Rn extends k{constructor(e={}){super(),this.encryptedKeys=r(e,Jc,Rn.defaultValues(Jc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){return e===Jc?[]:super.defaultValues(e)}static compareWithDefault(e,t){return e===Jc?t.length===0:super.defaultValues(e)}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.RecipientEncryptedKeys||u,value:vs.schema()})]})}fromSchema(e){C(e,Qy);const t=N(e,e,Rn.schema({names:{RecipientEncryptedKeys:Jm}}));p.assertSchema(t,this.className),this.encryptedKeys=Array.from(t.result.RecipientEncryptedKeys,s=>new vs({schema:s}))}toSchema(){return new d({value:Array.from(this.encryptedKeys,e=>e.toSchema())})}toJSON(){return{encryptedKeys:Array.from(this.encryptedKeys,e=>e.toJSON())}}}Rn.CLASS_NAME="RecipientEncryptedKeys";const Kr="version",Jr="originator",os="ukm",jr="keyEncryptionAlgorithm",Fr="recipientEncryptedKeys",jc="recipientCertificate",Fc="recipientPublicKey",Xy=[Kr,Jr,os,jr,Fr];class tt extends k{constructor(e={}){super(),this.version=r(e,Kr,tt.defaultValues(Kr)),this.originator=r(e,Jr,tt.defaultValues(Jr)),os in e&&(this.ukm=r(e,os,tt.defaultValues(os))),this.keyEncryptionAlgorithm=r(e,jr,tt.defaultValues(jr)),this.recipientEncryptedKeys=r(e,Fr,tt.defaultValues(Fr)),this.recipientCertificate=r(e,jc,tt.defaultValues(jc)),this.recipientPublicKey=r(e,Fc,tt.defaultValues(Fc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Kr:return 0;case Jr:return new bs;case os:return new B;case jr:return new v;case Fr:return new Rn;case jc:return new X;case Fc:return null;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Kr:return t===0;case Jr:return t.variant===-1&&!("value"in t);case os:return t.isEqual(tt.defaultValues(os));case jr:return t.algorithmId===u&&!("algorithmParams"in t);case Fr:return t.encryptedKeys.length===0;case jc:return!1;case Fc:return!1;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||u}),new w({idBlock:{tagClass:3,tagNumber:0},value:[bs.schema(t.originator||{})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new B({name:t.ukm||u})]}),v.schema(t.keyEncryptionAlgorithm||{}),Rn.schema(t.recipientEncryptedKeys||{})]})}fromSchema(e){C(e,Xy);const t=N(e,e,tt.schema({names:{version:Kr,originator:{names:{blockName:Jr}},ukm:os,keyEncryptionAlgorithm:{names:{blockName:jr}},recipientEncryptedKeys:{names:{blockName:Fr}}}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.originator=new bs({schema:t.result.originator}),os in t.result&&(this.ukm=t.result.ukm),this.keyEncryptionAlgorithm=new v({schema:t.result.keyEncryptionAlgorithm}),this.recipientEncryptedKeys=new Rn({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 d({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 ki="keyIdentifier",nn="date",rn="other",Zy=[ki,nn,rn];class xt extends k{constructor(e={}){super(),this.keyIdentifier=r(e,ki,xt.defaultValues(ki)),nn in e&&(this.date=r(e,nn,xt.defaultValues(nn))),rn in e&&(this.other=r(e,rn,xt.defaultValues(rn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ki:return new B;case nn:return new ue;case rn:return new Pt;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ki:return t.isEqual(xt.defaultValues(ki));case nn:return t.year===0&&t.month===0&&t.day===0&&t.hour===0&&t.minute===0&&t.second===0&&t.millisecond===0;case rn:return t.compareWithDefault("keyAttrId",t.keyAttrId)&&!("keyAttr"in t);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new B({name:t.keyIdentifier||u}),new ue({optional:!0,name:t.date||u}),Pt.schema(t.other||{})]})}fromSchema(e){C(e,Zy);const t=N(e,e,xt.schema({names:{keyIdentifier:ki,date:nn,other:{names:{blockName:rn}}}}));p.assertSchema(t,this.className),this.keyIdentifier=t.result.keyIdentifier,nn in t.result&&(this.date=t.result.date),rn in t.result&&(this.other=new Pt({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 d({value:e})}toJSON(){const e={keyIdentifier:this.keyIdentifier.toJSON()};return this.date&&(e.date=this.date),this.other&&(e.other=this.other.toJSON()),e}}xt.CLASS_NAME="KEKIdentifier";const qr="version",Wr="kekid",Gr="keyEncryptionAlgorithm",Ei="encryptedKey",qc="preDefinedKEK",zy=[qr,Wr,Gr,Ei];class ot extends k{constructor(e={}){super(),this.version=r(e,qr,ot.defaultValues(qr)),this.kekid=r(e,Wr,ot.defaultValues(Wr)),this.keyEncryptionAlgorithm=r(e,Gr,ot.defaultValues(Gr)),this.encryptedKey=r(e,Ei,ot.defaultValues(Ei)),this.preDefinedKEK=r(e,qc,ot.defaultValues(qc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case qr:return 0;case Wr:return new xt;case Gr:return new v;case Ei:return new B;case qc:return be;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case"KEKRecipientInfo":return t===ot.defaultValues(qr);case Wr:return t.compareWithDefault("keyIdentifier",t.keyIdentifier)&&!("date"in t)&&!("other"in t);case Gr:return t.algorithmId===u&&!("algorithmParams"in t);case Ei:return t.isEqual(ot.defaultValues(Ei));case qc:return t.byteLength===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||u}),xt.schema(t.kekid||{}),v.schema(t.keyEncryptionAlgorithm||{}),new B({name:t.encryptedKey||u})]})}fromSchema(e){C(e,zy);const t=N(e,e,ot.schema({names:{version:qr,kekid:{names:{blockName:Wr}},keyEncryptionAlgorithm:{names:{blockName:Gr}},encryptedKey:Ei}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.kekid=new xt({schema:t.result.kekid}),this.keyEncryptionAlgorithm=new v({schema:t.result.keyEncryptionAlgorithm}),this.encryptedKey=t.result.encryptedKey}toSchema(){return new d({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()}}}ot.CLASS_NAME="KEKRecipientInfo";const Yr="version",an="keyDerivationAlgorithm",Qr="keyEncryptionAlgorithm",Ni="encryptedKey",Wc="password",ev=[Yr,an,Qr,Ni];class vt extends k{constructor(e={}){super(),this.version=r(e,Yr,vt.defaultValues(Yr)),an in e&&(this.keyDerivationAlgorithm=r(e,an,vt.defaultValues(an))),this.keyEncryptionAlgorithm=r(e,Qr,vt.defaultValues(Qr)),this.encryptedKey=r(e,Ni,vt.defaultValues(Ni)),this.password=r(e,Wc,vt.defaultValues(Wc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Yr:return-1;case an:return new v;case Qr:return new v;case Ni:return new B;case Wc:return be;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Yr:return t===-1;case an:case Qr:return t.algorithmId===u&&!("algorithmParams"in t);case Ni:return t.isEqual(vt.defaultValues(Ni));case Wc:return t.byteLength===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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 B({name:t.encryptedKey||u})]})}fromSchema(e){C(e,ev);const t=N(e,e,vt.schema({names:{version:Yr,keyDerivationAlgorithm:an,keyEncryptionAlgorithm:{names:{blockName:Qr}},encryptedKey:Ni}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,an in t.result&&(this.keyDerivationAlgorithm=new v({schema:new d({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 d({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 Xr="oriType",Ci="oriValue",tv=[Xr,Ci];class Bn extends k{constructor(e={}){super(),this.oriType=r(e,Xr,Bn.defaultValues(Xr)),this.oriValue=r(e,Ci,Bn.defaultValues(Ci)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Xr:return u;case Ci:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Xr:return t===u;case Ci:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.oriType||u}),new K({name:t.oriValue||u})]})}fromSchema(e){C(e,tv);const t=N(e,e,Bn.schema({names:{oriType:Xr,oriValue:Ci}}));p.assertSchema(t,this.className),this.oriType=t.result.oriType.valueBlock.toString(),this.oriValue=t.result.oriValue}toSchema(){return new d({value:[new T({value:this.oriType}),this.oriValue]})}toJSON(){const e={oriType:this.oriType};return Bn.compareWithDefault(Ci,this.oriValue)||(e.oriValue=this.oriValue.toJSON()),e}}Bn.CLASS_NAME="OtherRecipientInfo";const Gc="variant",co="value",sv=["blockName"];class St extends k{constructor(e={}){super(),this.variant=r(e,Gc,St.defaultValues(Gc)),co in e&&(this.value=r(e,co,St.defaultValues(co))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Gc:return-1;case co:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Gc:return t===St.defaultValues(e);case co:return Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new he({value:[at.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:ot.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:Bn.schema().valueBlock.value})]})}fromSchema(e){C(e,sv);const t=N(e,e,St.schema({names:{blockName:"blockName"}}));if(p.assertSchema(t,this.className),t.result.blockName.idBlock.tagClass===1)this.variant=1,this.value=new at({schema:t.result.blockName});else{const s=new d({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 ot({schema:s});break;case 3:this.variant=4,this.value=new vt({schema:s});break;case 4:this.variant=5,this.value=new Bn({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}}St.CLASS_NAME="RecipientInfo";const on="hashAlgorithm",ln="maskGenAlgorithm",cn="pSourceAlgorithm",nv=[on,ln,cn];class We extends k{constructor(e={}){super(),this.hashAlgorithm=r(e,on,We.defaultValues(on)),this.maskGenAlgorithm=r(e,ln,We.defaultValues(ln)),this.pSourceAlgorithm=r(e,cn,We.defaultValues(cn)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case on:return new v({algorithmId:"1.3.14.3.2.26",algorithmParams:new Ae});case ln: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 cn:return new v({algorithmId:"1.2.840.113549.1.1.9",algorithmParams:new B({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=r(e,"names",{});return new d({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,nv);const t=N(e,e,We.schema({names:{hashAlgorithm:{names:{blockName:on}},maskGenAlgorithm:{names:{blockName:ln}},pSourceAlgorithm:{names:{blockName:cn}}}}));p.assertSchema(t,this.className),on in t.result&&(this.hashAlgorithm=new v({schema:t.result.hashAlgorithm})),ln in t.result&&(this.maskGenAlgorithm=new v({schema:t.result.maskGenAlgorithm})),cn in t.result&&(this.pSourceAlgorithm=new v({schema:t.result.pSourceAlgorithm}))}toSchema(){const e=[];return this.hashAlgorithm.isEqual(We.defaultValues(on))||e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:[this.hashAlgorithm.toSchema()]})),this.maskGenAlgorithm.isEqual(We.defaultValues(ln))||e.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[this.maskGenAlgorithm.toSchema()]})),this.pSourceAlgorithm.isEqual(We.defaultValues(cn))||e.push(new w({idBlock:{tagClass:3,tagNumber:2},value:[this.pSourceAlgorithm.toSchema()]})),new d({value:e})}toJSON(){const e={};return this.hashAlgorithm.isEqual(We.defaultValues(on))||(e.hashAlgorithm=this.hashAlgorithm.toJSON()),this.maskGenAlgorithm.isEqual(We.defaultValues(ln))||(e.maskGenAlgorithm=this.maskGenAlgorithm.toJSON()),this.pSourceAlgorithm.isEqual(We.defaultValues(cn))||(e.pSourceAlgorithm=this.pSourceAlgorithm.toJSON()),e}}We.CLASS_NAME="RSAESOAEPParams";const Zr="keyInfo",un="entityUInfo",zr="suppPubInfo",iv=[Zr,un,zr];class fs extends k{constructor(e={}){super(),this.keyInfo=r(e,Zr,fs.defaultValues(Zr)),un in e&&(this.entityUInfo=r(e,un,fs.defaultValues(un))),this.suppPubInfo=r(e,zr,fs.defaultValues(zr)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Zr:return new v;case un:return new B;case zr:return new B;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Zr:case un:case zr:return t.isEqual(fs.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.keyInfo||{}),new w({name:t.entityUInfo||u,idBlock:{tagClass:3,tagNumber:0},optional:!0,value:[new B]}),new w({name:t.suppPubInfo||u,idBlock:{tagClass:3,tagNumber:2},value:[new B]})]})}fromSchema(e){C(e,iv);const t=N(e,e,fs.schema({names:{keyInfo:{names:{blockName:Zr}},entityUInfo:un,suppPubInfo:zr}}));p.assertSchema(t,this.className),this.keyInfo=new v({schema:t.result.keyInfo}),un 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 d({value:e})}toJSON(){const e={keyInfo:this.keyInfo.toJSON(),suppPubInfo:this.suppPubInfo.toJSON()};return this.entityUInfo&&(e.entityUInfo=this.entityUInfo.toJSON()),e}}fs.CLASS_NAME="ECCCMSSharedInfo";const ea="version",hn="originatorInfo",ta="recipientInfos",sa="encryptedContentInfo",fn="unprotectedAttrs",rv=[ea,hn,ta,sa,fn],od={kdfAlgorithm:"SHA-512",kekEncryptionLength:256},av={"P-256":256,"P-384":384,"P-521":528};class It extends k{constructor(e={}){super(),this.version=r(e,ea,It.defaultValues(ea)),hn in e&&(this.originatorInfo=r(e,hn,It.defaultValues(hn))),this.recipientInfos=r(e,ta,It.defaultValues(ta)),this.encryptedContentInfo=r(e,sa,It.defaultValues(sa)),fn in e&&(this.unprotectedAttrs=r(e,fn,It.defaultValues(fn))),this.policy={disableSplit:!!e.disableSplit},e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ea:return 0;case hn:return new zi;case ta:return[];case sa:return new Ee;case fn:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ea:return t===It.defaultValues(e);case hn:return t.certs.certificates.length===0&&t.crls.crls.length===0;case ta:case fn:return t.length===0;case sa: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=r(e,"names",{});return new d({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:St.schema()})]}),Ee.schema(t.encryptedContentInfo||{}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.unprotectedAttrs||u,value:oe.schema()})]})]})}fromSchema(e){C(e,rv);const t=N(e,e,It.schema({names:{version:ea,originatorInfo:hn,recipientInfos:ta,encryptedContentInfo:{names:{blockName:sa}},unprotectedAttrs:fn}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,hn in t.result&&(this.originatorInfo=new zi({schema:new d({value:t.result.originatorInfo.valueBlock.value})})),this.recipientInfos=Array.from(t.result.recipientInfos,s=>new St({schema:s})),this.encryptedContentInfo=new Ee({schema:t.result.encryptedContentInfo}),fn in t.result&&(this.unprotectedAttrs=Array.from(t.result.unprotectedAttrs,s=>new oe({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 d({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"},od,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"),f=new v({algorithmId:h,algorithmParams:new Ae});l=new We({hashAlgorithm:f,maskGenAlgorithm:new v({algorithmId:"1.2.840.113549.1.1.8",algorithmParams:f.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 at({version:0,rid:new Ie({issuer:e.issuer,serialNumber:e.serialNumber}),keyEncryptionAlgorithm:new v({algorithmId:o,algorithmParams:l}),recipientCertificate:e});this.recipientInfos.push(new St({variant:1,value:c}))}break;case 2:{const o=new Gt({variant:1,value:new Ie({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 ot({version:4,kekid:new xt({keyIdentifier:new B({valueHex:t.keyIdentifier})}),keyEncryptionAlgorithm:new v({algorithmId:i,algorithmParams:t.keyEncryptionAlgorithmParams}),preDefinedKEK:e});this.recipientInfos.push(new St({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 B({valueHex:o}),iterationCount:t.iterationCount,prf:new v({algorithmId:c,algorithmParams:new Ae})}),f=n.getOIDByAlgorithm(t.keyEncryptionAlgorithm,!0,"keyEncryptionAlgorithm"),g=new vt({version:0,keyDerivationAlgorithm:new v({algorithmId:i,algorithmParams:h.toSchema()}),keyEncryptionAlgorithm:new v({algorithmId:f,algorithmParams:t.keyEncryptionAlgorithmParams}),password:e});this.recipientInfos.push(new St({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({},od,s||{}),o=new Gt({variant:2,value:new Jt({subjectKeyIdentifier:new B({valueHex:t})})});this._addKeyAgreeRecipientInfo(o,i,{recipientPublicKey:e},n)}_addKeyAgreeRecipientInfo(e,t,s,n=q(!0)){const i=new vs({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),f=new Uint8Array(h);n.getRandomValues(f);const g={version:3,ukm:new B({valueHex:h}),keyEncryptionAlgorithm:new v({algorithmId:c,algorithmParams:l.toSchema()}),recipientEncryptedKeys:new Rn({encryptedKeys:[i]})},m=new tt(Object.assign(g,s));this.recipientInfos.push(new St({variant:2,value:m}))}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),f=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 B({valueHex:n})}),encryptedContent:new B({valueHex:h})});const g=async y=>{const O=this.recipientInfos[y].value;let x,I;if(O.recipientPublicKey)x=O.recipientPublicKey.algorithm.namedCurve,I=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}`)}I=await O.recipientCertificate.getPublicKey({algorithm:{algorithm:{name:"ECDH",namedCurve:x},usages:[]}},s)}else throw new Error("Unsupported RecipientInfo");const V=av[x],R=await s.generateKey({name:"ECDH",namedCurve:x},!0,["deriveBits"]),M=await s.exportKey("spki",R.publicKey),te=await s.deriveBits({name:"ECDH",public:I},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 fs({keyInfo:new v({algorithmId:j.algorithmId}),entityUInfo:O.ukm,suppPubInfo:new B({valueHex:se})}).toSchema().toBER(!1),fe=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"ecdhAlgorithm"),ze=await Gf(fe.kdf,te,z.length,_e,s),et=await s.importKey("raw",ze,{name:"AES-KW"},!0,["wrapKey"]),gt=await s.wrapKey("raw",c,et,{name:"AES-KW"}),we=new bs;return we.variant=3,we.value=ys.fromBER(M),O.originator=we,O.recipientEncryptedKeys.encryptedKeys[0].encryptedKey=new B({valueHex:gt}),{ecdhPrivateKey:R.privateKey}},m=async y=>{const O=this.recipientInfos[y].value,x=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"keyEncryptionAlgorithm");if(x.name==="RSA-OAEP"){const I=O.keyEncryptionAlgorithm.algorithmParams,V=new We({schema:I});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 I=await O.recipientCertificate.getPublicKey({algorithm:{algorithm:x,usages:["encrypt","wrapKey"]}},s),V=await s.encrypt(I.algorithm,I,f);O.encryptedKey=new B({valueHex:V})}catch{}},b=async y=>{const O=this.recipientInfos[y].value,x=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"kekAlgorithm"),I=await s.importKey("raw",new Uint8Array(O.preDefinedKEK),x,!0,["wrapKey"]),V=await s.wrapKey("raw",c,I,x);O.encryptedKey=new B({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 I=new Uint8Array(O.password),V=await s.importKey("raw",I,"PBKDF2",!1,["deriveKey"]),R=s.getAlgorithmByOID(O.keyEncryptionAlgorithm.algorithmId,!0,"kekAlgorithm");let M="SHA-1";x.prf&&(M=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:M},salt:te,iterations:j},V,R,!0,["wrapKey"]),ye=await s.wrapKey("raw",c,z,R);O.encryptedKey=new B({valueHex:ye})},E=[];for(let y=0;y<this.recipientInfos.length;y++)switch(this.recipientInfos[y].variant){case 1:E.push(await m(y));break;case 2:E.push(await g(y));break;case 3:E.push(await b(y));break;case 4:E.push(await A(y));break;default:throw new Error(`Unknown recipient type in array with index ${y}`)}return E}async decrypt(e,t,s=q(!0)){const n=t||{};if(e+1>this.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,I;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",I=256;break;case"1.3.132.0.34":x="P-384",I=384;break;case"1.3.132.0.35":x="P-521",I=528;break;default:throw new Error(`Incorrect curve OID for index ${E}`)}let R,M=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&&(M=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 M.deriveBits({name:"ECDH",public:j},R,I);async function ye(fe){fe=fe||!1;const ze=new v({schema:y.keyEncryptionAlgorithm.algorithmParams}),et=s.getAlgorithmByOID(ze.algorithmId,!0,"kwAlgorithm");let gt=et.length;const we=new ArrayBuffer(4),P=new Uint8Array(we);for(let Te=3;Te>=0;Te--)P[Te]=gt,gt>>=8;const F={algorithmId:ze.algorithmId};fe&&(F.algorithmParams=new Ae);const Y=new fs({keyInfo:new v(F),entityUInfo:y.ukm,suppPubInfo:new B({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 Gf(ne.kdf,z,et.length,Y,s)}const se=await ye(),ae=async fe=>s.importKey("raw",fe,{name:"AES-KW"},!0,["unwrapKey"]),Xt=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(Xt)}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 We({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,I=s;L.isBufferSource(n.recipientPrivateKey)?x=await s.importKey("pkcs8",n.recipientPrivateKey,O,!0,["decrypt"]):(x=n.recipientPrivateKey,"crypto"in n&&n.crypto&&(I=n.crypto.subtle));const V=await I.decrypt(x.algorithm,x,y.encryptedKey.valueBlock.valueHexView),R=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,M=s.getAlgorithmByOID(R,!0,"contentEncryptionAlgorithm");if(!("name"in M))throw new Error(`Incorrect "contentEncryptionAlgorithm": ${R}`);return s.importKey("raw",V,M,!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"]),I=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,V=s.getAlgorithmByOID(I,!0,"contentEncryptionAlgorithm");if(!V.name)throw new Error(`Incorrect "contentEncryptionAlgorithm": ${I}`);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"]),I=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),M=O.iterationCount,te=await s.deriveKey({name:"PBKDF2",hash:{name:V},salt:R,iterations:M},x,I,!0,["unwrapKey"]),j=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,z=s.getAlgorithmByOID(j,!0,"contentEncryptionAlgorithm");return s.unwrapKey("raw",y.encryptedKey.valueBlock.valueHexView,te,I,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 f=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId,g=s.getAlgorithmByOID(f,!0,"contentEncryptionAlgorithm"),m=this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmParams.valueBlock.valueHex,b=new Uint8Array(m);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)}}It.CLASS_NAME="EnvelopedData";const cr="safeContents",uo="parsedValue",ld="contentInfos";class Tn extends k{constructor(e={}){super(),this.safeContents=r(e,cr,Tn.defaultValues(cr)),uo in e&&(this.parsedValue=r(e,uo,Tn.defaultValues(uo))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case cr:return[];case uo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case cr:return t.length===0;case uo:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new J({name:t.contentInfos||u,value:le.schema()})]})}fromSchema(e){C(e,[ld]);const t=N(e,e,Tn.schema({names:{contentInfos:ld}}));p.assertSchema(t,this.className),this.safeContents=Array.from(t.result.contentInfos,s=>new le({schema:s}))}toSchema(){return new d({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,cr),ie.assert(e.safeContents,cr,"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 kf:{ie.assert(n.content,"this.safeContents[j].content",B);const l=n.content.getValue();this.parsedValue.safeContents.push({privacyMode:0,value:Tt.fromBER(l)})}break;case Pm:{const l=new It({schema:n.content});Q.assert(o,i,"recipientCertificate","recipientKey");const c=i,h=c.recipientCertificate,f=c.recipientKey,g=await l.decrypt(0,{recipientCertificate:h,recipientPrivateKey:f},t);this.parsedValue.safeContents.push({privacyMode:2,value:Tt.fromBER(g)})}break;case Lm:{const l=new Ft({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:Tt.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",Tt),n.privacyMode){case 0:{const i=n.value.toSchema().toBER(!1);this.safeContents.push(new le({contentType:"1.2.840.113549.1.7.1",content:new B({valueHex:i})}))}break;case 1:{const i=new Ft,o=e.safeContents[s];o.contentToEncrypt=n.value.toSchema().toBER(!1),await i.encrypt(o,t),this.safeContents.push(new le({contentType:"1.2.840.113549.1.7.6",content:i.toSchema()}))}break;case 2:{const i=new It,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 le({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}}Tn.CLASS_NAME="AuthenticatedSafe";const Bi="hashAlgorithm",na="issuerNameHash",ia="issuerKeyHash",Ii="serialNumber",ov=[Bi,na,ia,Ii];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=r(e,Bi,Ne.defaultValues(Bi)),this.issuerNameHash=r(e,na,Ne.defaultValues(na)),this.issuerKeyHash=r(e,ia,Ne.defaultValues(ia)),this.serialNumber=r(e,Ii,Ne.defaultValues(Ii)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Bi:return new v;case na:case ia:return new B;case Ii:return new S;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Bi:return t.algorithmId===u&&!("algorithmParams"in t);case na:case ia:case Ii:return t.isEqual(Ne.defaultValues(Ii));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.hashAlgorithmObject||{names:{blockName:t.hashAlgorithm||u}}),new B({name:t.issuerNameHash||u}),new B({name:t.issuerKeyHash||u}),new S({name:t.serialNumber||u})]})}fromSchema(e){C(e,ov);const t=N(e,e,Ne.schema({names:{hashAlgorithm:Bi,issuerNameHash:na,issuerKeyHash:ia,serialNumber:Ii}}));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 d({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,Bi,"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 B({valueHex:o});const l=i.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView,c=await s.digest({name:t.hashAlgorithm},l);this.issuerKeyHash=new B({valueHex:c})}}Ne.CLASS_NAME="CertID";const ra="certID",aa="certStatus",oa="thisUpdate",dn="nextUpdate",Vi="singleExtensions",lv=[ra,aa,oa,dn,Vi];class Vt extends k{constructor(e={}){super(),this.certID=r(e,ra,Vt.defaultValues(ra)),this.certStatus=r(e,aa,Vt.defaultValues(aa)),this.thisUpdate=r(e,oa,Vt.defaultValues(oa)),dn in e&&(this.nextUpdate=r(e,dn,Vt.defaultValues(dn))),Vi in e&&(this.singleExtensions=r(e,Vi,Vt.defaultValues(Vi))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ra:return new Ne;case aa:return{};case oa:case dn:return new Date(0,0,0);case Vi:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ra:return Ne.compareWithDefault("hashAlgorithm",t.hashAlgorithm)&&Ne.compareWithDefault("issuerNameHash",t.issuerNameHash)&&Ne.compareWithDefault("issuerKeyHash",t.issuerKeyHash)&&Ne.compareWithDefault("serialNumber",t.serialNumber);case aa:return Object.keys(t).length===0;case oa:case dn:return t===Vt.defaultValues(e);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({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 tr]})]}),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,lv);const t=N(e,e,Vt.schema({names:{certID:{names:{blockName:ra}},certStatus:aa,thisUpdate:oa,nextUpdate:dn,singleExtensions:{names:{blockName:Vi}}}}));p.assertSchema(t,this.className),this.certID=new Ne({schema:t.result.certID}),this.certStatus=t.result.certStatus,this.thisUpdate=t.result.thisUpdate.toDate(),dn in t.result&&(this.nextUpdate=t.result.nextUpdate.toDate()),Vi in t.result&&(this.singleExtensions=Array.from(t.result.singleExtensions.valueBlock.value,s=>new xe({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 d({value:Array.from(this.singleExtensions,t=>t.toSchema())})]})),new d({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}}Vt.CLASS_NAME="SingleResponse";const Yc="tbs",xi="version",jl="responderID",Fl="producedAt",ql="responses",la="responseExtensions",ir="ResponseData",ou=`${ir}.${xi}`,ca=`${ir}.${jl}`,$h=`${ir}.${Fl}`,Kh=`${ir}.${ql}`,lu=`${ir}.${la}`,cv=[ir,ou,ca,$h,Kh,lu];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(r(e,Yc,Re.defaultValues(Yc))),xi in e&&(this.version=r(e,xi,Re.defaultValues(xi))),this.responderID=r(e,jl,Re.defaultValues(jl)),this.producedAt=r(e,Fl,Re.defaultValues(Fl)),this.responses=r(e,ql,Re.defaultValues(ql)),la in e&&(this.responseExtensions=r(e,la,Re.defaultValues(la))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case xi:return 0;case Yc:return be;case jl:return{};case Fl:return new Date(0,0,0);case ql:case la:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Yc:return t.byteLength===0;case jl:return Object.keys(t).length===0;case Fl:return t===Re.defaultValues(e);case ql:case la:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||ir,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({name:t.version||ou})]}),new he({value:[new w({name:t.responderID||ca,idBlock:{tagClass:3,tagNumber:1},value:[re.schema(t.ResponseDataByName||{names:{blockName:"ResponseData.byName"}})]}),new w({name:t.responderID||ca,idBlock:{tagClass:3,tagNumber:2},value:[new B({name:t.ResponseDataByKey||"ResponseData.byKey"})]})]}),new ue({name:t.producedAt||$h}),new d({value:[new J({name:Kh,value:Vt.schema(t.response||{})})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[ke.schema(t.extensions||{names:{blockName:lu}})]})]})}fromSchema(e){C(e,cv);const t=N(e,e,Re.schema());p.assertSchema(t,this.className),this.tbsView=t.result.ResponseData.valueBeforeDecodeView,ou in t.result&&(this.version=t.result[ou].valueBlock.valueDec),t.result[ca].idBlock.tagNumber===1?this.responderID=new re({schema:t.result[ca].valueBlock.value[0]}):this.responderID=t.result[ca].valueBlock.value[0],this.producedAt=t.result[$h].toDate(),this.responses=Array.from(t.result[Kh],s=>new Vt({schema:s})),lu in t.result&&(this.responseExtensions=Array.from(t.result[lu].valueBlock.value,s=>new xe({schema:s})))}toSchema(e=!1){let t;if(e===!1){if(!this.tbsView.byteLength)return Re.schema();const s=Be(this.tbsView);p.assert(s,"TBS Response Data"),t=s.result}else{const s=[];xi 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 d({value:Array.from(this.responses,n=>n.toSchema())})),this.responseExtensions&&s.push(new w({idBlock:{tagClass:3,tagNumber:1},value:[new d({value:Array.from(this.responseExtensions,n=>n.toSchema())})]})),t=new d({value:s})}return t}toJSON(){const e={};return xi 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 Sh="trustedCerts",Ah="certs",ph="crls",bh="ocsps",kh="checkDate",Eh="findOrigin",Nh="findIssuer";var Mi;(function(a){a[a.unknown=-1]="unknown",a[a.success=0]="success",a[a.noRevocation=11]="noRevocation",a[a.noPath=60]="noPath",a[a.noValidPath=97]="noValidPath"})(Mi||(Mi={}));class bn extends Error{constructor(e,t){super(t),this.name=bn.NAME,this.code=e,this.message=t}}bn.NAME="ChainValidationError";function uv(a,e){for(let t=0;t<e.length;t++)if(L.isEqual(a.tbsView,e[t].tbsView))return!0;return!1}class Yu{constructor(e={}){this.trustedCerts=r(e,Sh,this.defaultValues(Sh)),this.certs=r(e,Ah,this.defaultValues(Ah)),this.crls=r(e,ph,this.defaultValues(ph)),this.ocsps=r(e,bh,this.defaultValues(bh)),this.checkDate=r(e,kh,this.defaultValues(kh)),this.findOrigin=r(e,Eh,this.defaultValues(Eh)),this.findIssuer=r(e,Nh,this.defaultValues(Nh))}static defaultFindOrigin(e,t){e.tbsView.byteLength===0&&(e.tbsView=new Uint8Array(e.encodeTBS().toBER()));for(const s of t.certs)if(s.tbsView.byteLength===0&&(s.tbsView=new Uint8Array(s.encodeTBS().toBER())),L.isEqual(e.tbsView,s.tbsView))return"Intermediate Certificates";for(const s of t.trustedCerts)if(s.tbsView.byteLength===0&&(s.tbsView=new Uint8Array(s.encodeTBS().toBER())),L.isEqual(e.tbsView,s.tbsView))return"Trusted Certificates";return"Unknown"}async defaultFindIssuer(e,t,s=q(!0)){const n=[];let i=null,o=null,l=null;if(e.subject.isEqual(e.issuer))try{if(await e.verify(void 0,s))return[e]}catch{}if(e.extensions){for(const h of e.extensions)if(h.extnID===pf&&h.parsedValue instanceof En){h.parsedValue.keyIdentifier?i=h.parsedValue.keyIdentifier:(h.parsedValue.authorityCertIssuer&&(o=h.parsedValue.authorityCertIssuer),h.parsedValue.authorityCertSerialNumber&&(l=h.parsedValue.authorityCertSerialNumber));break}}function c(h){if(i!==null&&h.extensions){let g=!1;for(const m of h.extensions)if(m.extnID===mw&&m.parsedValue){g=!0,L.isEqual(m.parsedValue.valueBlock.valueHex,i.valueBlock.valueHexView)&&n.push(h);break}if(g)return}let f=!1;l!==null&&(f=h.serialNumber.isEqual(l)),o!==null?h.subject.isEqual(o)&&f&&n.push(h):e.issuer.isEqual(h.subject)&&n.push(h)}for(const h of t.trustedCerts)c(h);for(const h of t.certs)c(h);for(let h=n.length-1;h>=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 Sh:return[];case Ah:return[];case ph:return[];case bh:return[];case kh:return new Date;case Eh:return Yu.defaultFindOrigin;case Nh: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(I){let V=!0;for(let R=0;R<I.length;R++){for(let M=0;M<I.length;M++)if(M!==R&&I[R]===I[M]){V=!1;break}if(!V)break}return V}if(uv(A,this.trustedCerts))return[[A]];const x=await this.findIssuer(A,this,E);if(x.length===0)throw new Error("No valid certificate paths found");for(let I=0;I<x.length;I++){if(L.isEqual(x[I].tbsView,A.tbsView)){y.push([x[I]]);continue}const V=await n(x[I],E);for(let R=0;R<V.length;R++){const M=V[R].slice();M.splice(0,0,x[I]),O(M)?y.push(M):y.push(V[R])}}return y},i=async A=>{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<y.length;x++){const I=y[x];if(!(I.nextUpdate&&I.nextUpdate.value<this.checkDate))for(let V=0;V<E.length;V++)try{if(await y[x].verify({issuerCertificate:E[V]},t)){O.push({crl:y[x],certificate:E[V]});break}}catch{}}return O.length?{status:0,statusMessage:u,result:O}:{status:3,statusMessage:"No valid CRLs found"}},o=async(A,E)=>{const y=t.getAlgorithmByOID(A.signatureAlgorithm.algorithmId);if(!y.name||!y.hash)return 1;for(let O=0;O<this.ocsps.length;O++){const I=await this.ocsps[O].getCertificateStatus(A,E,t);if(I.isForCertificate)return I.status===0?0:1}return 2};async function l(A,E=!1){let y=!1,O=!1,x=!1,I=!1;if(A.extensions){for(let V=0;V<A.extensions.length;V++){const R=A.extensions[V];if(R.critical&&!R.parsedValue)return{result:!1,resultCode:6,resultMessage:`Unable to parse critical certificate extension: ${R.extnID}`};if(R.extnID===gw){x=!0;const M=new Uint8Array(R.parsedValue.valueBlock.valueHex);(M[0]&4)===4&&(O=!0),(M[0]&2)===2&&(I=!0)}R.extnID===Sf&&"cA"in R.parsedValue&&R.parsedValue.cA===!0&&(y=!0)}if(O===!0&&y===!1)return{result:!1,resultCode:3,resultMessage:'Unable to build certificate chain - using "keyCertSign" flag set without BasicConstraints'};if(x===!0&&y===!0&&O===!1)return{result:!1,resultCode:4,resultMessage:'Unable to build certificate chain - "keyCertSign" flag was not set'};if(y===!0&&x===!0&&E&&I===!1)return{result:!1,resultCode:5,resultMessage:'Unable to build certificate chain - intermediate certificate must have "cRLSign" key usage flag'}}return y===!1?{result:!1,resultCode:7,resultMessage:"Unable to build certificate chain - more than one possible end-user certificate"}:{result:!0,resultCode:0,resultMessage:u}}const c=async(A,E)=>{for(let y=0;y<A.length;y++)if(A[y].notBefore.value>E||A[y].notAfter.value<E)return{result:!1,resultCode:8,resultMessage:"The certificate is either not yet valid or expired"};if(A.length<2)return{result:!1,resultCode:9,resultMessage:"Too short certificate path"};for(let y=A.length-2;y>=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<A.length-1;y++){let O=2,x={status:0,statusMessage:u};if(this.ocsps.length!==0)switch(O=await o(A[y],A[y+1]),O){case 0:continue;case 1:return{result:!1,resultCode:12,resultMessage:"One of certificates was revoked via OCSP response"}}if(this.crls.length!==0){if(x=await i(A[y]),x.status===0&&x.result)for(let I=0;I<x.result.length;I++){if(x.result[I].crl.isCertificateRevoked(A[y]))return{result:!1,resultCode:12,resultMessage:"One of certificates had been revoked"};if((await l(x.result[I].certificate,!0)).result===!1)return{result:!1,resultCode:13,resultMessage:"CRL issuer certificate is not a CA certificate or does not have crlSign flag"}}else if(e===!1)throw new bn(Mi.noRevocation,`No revocation values found for one of certificates: ${x.statusMessage}`)}else if(O===2)return{result:!1,resultCode:11,resultMessage:"No revocation values found for one of certificates"};if(O===2&&x.status===2&&e){const I=A[y+1];let V=!1;if(I.extensions)for(const R of I.extensions)switch(R.extnID){case xm:case Af:case bf:V=!0;break}if(V)throw new bn(Mi.noRevocation,`No revocation values found for one of certificates: ${x.statusMessage}`)}}for(const[y,O]of A.entries()){if(!y)continue;if(!(await l(O)).result)return{result:!1,resultCode:14,resultMessage:"One of intermediate certificates is not a CA certificate"}}return{result:!0}};s.push(...this.trustedCerts),s.push(...this.certs);for(let A=0;A<s.length;A++)for(let E=0;E<s.length;E++)if(A!==E&&L.isEqual(s[A].tbsView,s[E].tbsView)){s.splice(E,1),A=0;break}const h=s[s.length-1];let f;const g=[h];if(f=await n(h,t),f.length===0)throw new bn(Mi.noPath,"Unable to find certificate path");for(let A=f.length-1;A>=0;A--){let E=!1;for(let y=0;y<f[A].length;y++){const O=f[A][y];for(let x=0;x<this.trustedCerts.length;x++)if(L.isEqual(O.tbsView,this.trustedCerts[x].tbsView)){E=!0;break}if(E)break}E||f.splice(A,1)}if(f.length===0)throw new bn(Mi.noValidPath,"No valid certificate paths found");let m=f[0].length,b=0;for(let A=0;A<f.length;A++)f[A].length<m&&(m=f[A].length,b=A);for(let A=0;A<f[b].length;A++)g.push(f[b][A]);if(f=await c(g,this.checkDate),f.result===!1)throw f;return g}async verify(e={},t=q(!0)){function s(c,h){const f=An(c),g=An(h),m=f.split("."),b=g.split("."),A=m.length,E=b.length;if(A===0||E===0||A<E)return!1;for(let y=0;y<A;y++)if(m[y].length===0)return!1;for(let y=0;y<E;y++)if(b[y].length===0){if(y===0){if(E===1)return!1;continue}return!1}for(let y=0;y<E;y++)if(b[E-1-y].length!==0&&m[A-1-y].localeCompare(b[E-1-y])!==0)return!1;return!0}function n(c,h){const f=An(c),g=An(h),m=f.split("@"),b=g.split("@");if(m.length===0||b.length===0||m.length<b.length)return!1;if(b.length===1){if(s(m[1],b[0])){const E=m[1].split("."),y=b[0].split(".");return y[0].length===0?!0:E.length===y.length}return!1}return f.localeCompare(g)===0}function i(c,h){let f=An(c);const g=An(h),m=f.split("/");if(g.split("/").length>1)return!1;if(m.length>1){for(let E=0;E<m.length;E++)if(m[E].length>0&&m[E].charAt(m[E].length-1)!==":"){f=m[E].split(":")[0];break}}if(s(f,g)){const E=f.split("."),y=g.split(".");return y[0].length===0?!0:E.length===y.length}return!1}function o(c,h){const f=c.valueBlock.valueHexView,g=h.valueBlock.valueHexView;if(f.length===4&&g.length===8){for(let m=0;m<4;m++)if((f[m]^g[m])&g[m+4])return!1;return!0}if(f.length===16&&g.length===32){for(let m=0;m<16;m++)if((f[m]^g[m])&g[m+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<h.typesAndValues.length)return!1;let f=!0,g=0;for(let m=0;m<h.typesAndValues.length;m++){let b=!1;for(let A=g;A<c.typesAndValues.length;A++)if(b=c.typesAndValues[A].isEqual(h.typesAndValues[m]),c.typesAndValues[A].type===h.typesAndValues[m].type&&(f=f&&b),b===!0)if(g===0||g===A){g=A+1;break}else return!1;if(b===!1)return!1}return g===0?!1:f}try{if(this.certs.length===0)throw new Error("Empty certificate array");const c=e.passedWhenNotRevValues||!1,h=e.initialPolicySet||[wt],f=e.initialExplicitPolicy||!1,g=e.initialPolicyMappingInhibit||!1,m=e.initialInhibitPolicy||!1,b=e.initialPermittedSubtreesSet||[],A=e.initialExcludedSubtreesSet||[],E=e.initialRequiredNameForms||[];let y=f,O=g,x=m;const I=[!1,!1,!1];let V=0,R=0,M=0,te=b,j=A;const z=E;let ye=1;this.certs=await this.sort(c,t);const se=[];se.push(wt);const ae=[],Xt=new Array(this.certs.length-1);for(let P=0;P<this.certs.length-1;P++)Xt[P]=!0;ae.push(Xt);const _e=new Array(this.certs.length-1),fe=new Array(this.certs.length-1);let ze=y?this.certs.length-1:-1;for(let P=this.certs.length-2;P>=0;P--,ye++){const F=this.certs[P];if(F.extensions){for(let U=0;U<F.extensions.length;U++){const Y=F.extensions[U];if(Y.extnID===Om){fe[P]=Y.parsedValue;for(let ne=0;ne<se.length;ne++)if(se[ne]===wt){delete ae[ne][P];break}for(let ne=0;ne<Y.parsedValue.certificatePolicies.length;ne++){let Te=-1;const Zt=Y.parsedValue.certificatePolicies[ne].policyIdentifier;for(let ve=0;ve<se.length;ve++)if(Zt===se[ve]){Te=ve;break}if(Te===-1){se.push(Zt);const ve=new Array(this.certs.length-1);ve[P]=!0,ae.push(ve)}else ae[Te][P]=!0}}if(Y.extnID===Rm){if(O)return{result:!1,resultCode:98,resultMessage:"Policy mapping prohibited"};_e[P]=Y.parsedValue}Y.extnID===Tm&&y===!1&&(Y.parsedValue.requireExplicitPolicy===0?(y=!0,ze=P):I[0]===!1?(I[0]=!0,V=Y.parsedValue.requireExplicitPolicy):V=V>Y.parsedValue.requireExplicitPolicy?Y.parsedValue.requireExplicitPolicy:V,Y.parsedValue.inhibitPolicyMapping===0?O=!0:I[1]===!1?(I[1]=!0,R=Y.parsedValue.inhibitPolicyMapping+1):R=R>Y.parsedValue.inhibitPolicyMapping+1?Y.parsedValue.inhibitPolicyMapping+1:R),Y.extnID===kw&&x===!1&&(Y.parsedValue.valueBlock.valueDec===0?x=!0:I[2]===!1?(I[2]=!0,M=Y.parsedValue.valueBlock.valueDec):M=M>Y.parsedValue.valueBlock.valueDec?Y.parsedValue.valueBlock.valueDec:M)}if(x===!0){let U=-1;for(let Y=0;Y<se.length;Y++)if(se[Y]===wt){U=Y;break}U!==-1&&delete ae[0][P]}y===!1&&I[0]===!0&&(V--,V===0&&(y=!0,ze=P,I[0]=!1)),O===!1&&I[1]===!0&&(R--,R===0&&(O=!0,I[1]=!1)),x===!1&&I[2]===!0&&(M--,M===0&&(x=!0,I[2]=!1))}}for(let P=0;P<this.certs.length-1;P++)if(P<this.certs.length-2&&typeof _e[P+1]<"u")for(let F=0;F<_e[P+1].mappings.length;F++){if(_e[P+1].mappings[F].issuerDomainPolicy===wt||_e[P+1].mappings[F].subjectDomainPolicy===wt)return{result:!1,resultCode:99,resultMessage:'The "anyPolicy" should not be a part of policy mapping scheme'};let U=-1,Y=-1;for(let ne=0;ne<se.length;ne++)se[ne]===_e[P+1].mappings[F].issuerDomainPolicy&&(U=ne),se[ne]===_e[P+1].mappings[F].subjectDomainPolicy&&(Y=ne);typeof ae[U][P]<"u"&&delete ae[U][P];for(let ne=0;ne<fe[P].certificatePolicies.length;ne++)if(_e[P+1].mappings[F].subjectDomainPolicy===fe[P].certificatePolicies[ne].policyIdentifier&&U!==-1&&Y!==-1)for(let Te=0;Te<=P;Te++)typeof ae[Y][Te]<"u"&&(ae[U][Te]=!0,delete ae[Y][Te])}for(let P=0;P<se.length;P++)if(se[P]===wt)for(let F=0;F<ze;F++)delete ae[P][F];const et=[];for(let P=0;P<ae.length;P++){let F=!0;for(let U=0;U<this.certs.length-1;U++){let Y=!1;if(U<ze&&se[P]===wt&&se.length>1){F=!1;break}if(typeof ae[P][U]>"u"){if(U>=ze){for(let ne=0;ne<se.length;ne++)if(se[ne]===wt){ae[ne][U]===!0&&(Y=!0);break}}if(!Y){F=!1;break}}}F===!0&&et.push(se[P])}let gt=[];if(h.length===1&&h[0]===wt&&y===!1)gt=h;else if(et.length===1&&et[0]===wt)gt=h;else for(let P=0;P<et.length;P++)for(let F=0;F<h.length;F++)if(h[F]===et[P]||h[F]===wt){gt.push(et[P]);break}const we={result:gt.length>0,resultCode:0,resultMessage:gt.length>0?u:'Zero "userConstrPolicies" array, no intersections with "authConstrPolicies"',authConstrPolicies:et,userConstrPolicies:gt,explicitPolicyIndicator:y,policyMappings:_e,certificatePath:this.certs};if(gt.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 ee=0;ee<F.extensions.length;ee++){const $=F.extensions[ee];$.extnID===Vm&&("permittedSubtrees"in $.parsedValue&&(Y=Y.concat($.parsedValue.permittedSubtrees)),"excludedSubtrees"in $.parsedValue&&(ne=ne.concat($.parsedValue.excludedSubtrees))),$.extnID===Nm&&(U=U.concat($.parsedValue.altNames))}let Te=z.length<=0;for(let ee=0;ee<z.length;ee++)switch(z[ee].base.type){case 4:{if(z[ee].base.value.typesAndValues.length!==F.subject.typesAndValues.length)continue;Te=!0;for(let $=0;$<F.subject.typesAndValues.length;$++)if(F.subject.typesAndValues[$].type!==z[ee].base.value.typesAndValues[$].type){Te=!1;break}if(Te===!0)break}break;default:}if(Te===!1)throw we.result=!1,we.resultCode=21,we.resultMessage="No necessary name form found",we;const Zt=[[],[],[],[],[]];for(let ee=0;ee<te.length;ee++)switch(te[ee].base.type){case 1:Zt[0].push(te[ee]);break;case 2:Zt[1].push(te[ee]);break;case 4:Zt[2].push(te[ee]);break;case 6:Zt[3].push(te[ee]);break;case 7:Zt[4].push(te[ee]);break;default:}for(let ee=0;ee<5;ee++){let $=!1,Pn=!1;const Bs=Zt[ee];for(let Is=0;Is<Bs.length;Is++){switch(ee){case 0:if(U.length>0)for(let ce=0;ce<U.length;ce++)U[ce].type===1&&(Pn=!0,$=$||n(U[ce].value,Bs[Is].base.value));else for(let ce=0;ce<F.subject.typesAndValues.length;ce++)(F.subject.typesAndValues[ce].type==="1.2.840.113549.1.9.1"||F.subject.typesAndValues[ce].type==="0.9.2342.19200300.100.1.3")&&(Pn=!0,$=$||n(F.subject.typesAndValues[ce].value.valueBlock.value,Bs[Is].base.value));break;case 1:if(U.length>0)for(let ce=0;ce<U.length;ce++)U[ce].type===2&&(Pn=!0,$=$||s(U[ce].value,Bs[Is].base.value));break;case 2:Pn=!0,$=l(F.subject,Bs[Is].base.value);break;case 3:if(U.length>0)for(let ce=0;ce<U.length;ce++)U[ce].type===6&&(Pn=!0,$=$||i(U[ce].value,Bs[Is].base.value));break;case 4:if(U.length>0)for(let ce=0;ce<U.length;ce++)U[ce].type===7&&(Pn=!0,$=$||o(U[ce].value,Bs[Is].base.value));break;default:}if($)break}if($===!1&&Bs.length>0&&Pn)throw we.result=!1,we.resultCode=41,we.resultMessage='Failed to meet "permitted sub-trees" name constraint',we}let ve=!1;for(let ee=0;ee<j.length;ee++){switch(j[ee].base.type){case 1:if(U.length>=0)for(let $=0;$<U.length;$++)U[$].type===1&&(ve=ve||n(U[$].value,j[ee].base.value));else for(let $=0;$<F.subject.typesAndValues.length;$++)(F.subject.typesAndValues[$].type==="1.2.840.113549.1.9.1"||F.subject.typesAndValues[$].type==="0.9.2342.19200300.100.1.3")&&(ve=ve||n(F.subject.typesAndValues[$].value.valueBlock.value,j[ee].base.value));break;case 2:if(U.length>0)for(let $=0;$<U.length;$++)U[$].type===2&&(ve=ve||s(U[$].value,j[ee].base.value));break;case 4:ve=ve||l(F.subject,j[ee].base.value);break;case 6:if(U.length>0)for(let $=0;$<U.length;$++)U[$].type===6&&(ve=ve||i(U[$].value,j[ee].base.value));break;case 7:if(U.length>0)for(let $=0;$<U.length;$++)U[$].type===7&&(ve=ve||o(U[$].value,j[ee].base.value));break;default:}if(ve)break}if(ve===!0)throw we.result=!1,we.resultCode=42,we.resultMessage='Failed to meet "excluded sub-trees" name constraint',we;te=te.concat(Y),j=j.concat(ne)}return we}catch(c){return c instanceof Error?c instanceof bn?{result:!1,resultCode:c.code,resultMessage:c.message,error:c}:{result:!1,resultCode:Mi.unknown,resultMessage:c.message,error:c}:c&&typeof c=="object"&&"resultMessage"in c?c:{result:!1,resultCode:-1,resultMessage:`${c}`}}}}const cu="tbsResponseData",Wl="signatureAlgorithm",Gl="signature",ua="certs",Nc="BasicOCSPResponse",Jh=`${Nc}.${cu}`,jh=`${Nc}.${Wl}`,Fh=`${Nc}.${Gl}`,uu=`${Nc}.${ua}`,hv=[Jh,jh,Fh,uu];class At extends k{constructor(e={}){super(),this.tbsResponseData=r(e,cu,At.defaultValues(cu)),this.signatureAlgorithm=r(e,Wl,At.defaultValues(Wl)),this.signature=r(e,Gl,At.defaultValues(Gl)),ua in e&&(this.certs=r(e,ua,At.defaultValues(ua))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case cu:return new Re;case Wl:return new v;case Gl:return new G;case ua:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case"type":{let s=Re.compareWithDefault("tbs",t.tbs)&&Re.compareWithDefault("responderID",t.responderID)&&Re.compareWithDefault("producedAt",t.producedAt)&&Re.compareWithDefault("responses",t.responses);return"responseExtensions"in t&&(s=s&&Re.compareWithDefault("responseExtensions",t.responseExtensions)),s}case Wl:return t.algorithmId===u&&!("algorithmParams"in t);case Gl:return t.isEqual(At.defaultValues(e));case ua:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||Nc,value:[Re.schema(t.tbsResponseData||{names:{blockName:Jh}}),v.schema(t.signatureAlgorithm||{names:{blockName:jh}}),new G({name:t.signature||Fh}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new d({value:[new J({name:uu,value:X.schema(t.certs||{})})]})]})]})}fromSchema(e){C(e,hv);const t=N(e,e,At.schema());p.assertSchema(t,this.className),this.tbsResponseData=new Re({schema:t.result[Jh]}),this.signatureAlgorithm=new v({schema:t.result[jh]}),this.signature=t.result[Fh],uu in t.result&&(this.certs=Array.from(t.result[uu],s=>new X({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 d({value:Array.from(this.certs,t=>t.toSchema())})]})),new d({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 G({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,f]of this.certs.entries())if(f.subject.isEqual(this.tbsResponseData.responderID)){n=h;break}break;case this.tbsResponseData.responderID instanceof B:for(const[h,f]of this.certs.entries()){const g=await t.digest({name:"sha-1"},f.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 f=await Km(h,s);f&&o.push(f)}if(!(await new Yu({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)}}At.CLASS_NAME="BasicOCSPResponse";const Ch="tbs",Bh="version",Ih="subject",Vh="subjectPublicKeyInfo",ur="attributes",Yl="signatureAlgorithm",Ql="signatureValue",Qa="CertificationRequestInfo",Of=`${Qa}.version`,Rf=`${Qa}.subject`,Tf=`${Qa}.subjectPublicKeyInfo`,Ju=`${Qa}.attributes`,fv=[Qa,Of,Rf,Tf,Ju,Yl,Ql];function dv(a={}){const e=r(a,"names",{});return new d({name:e.CertificationRequestInfo||Qa,value:[new S({name:e.CertificationRequestInfoVersion||Of}),re.schema(e.subject||{names:{blockName:Rf}}),Xe.schema({names:{blockName:Tf}}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({optional:!0,name:e.CertificationRequestInfoAttributes||Ju,value:oe.schema(e.attributes||{})})]})]})}class Bt extends k{get tbs(){return L.toArrayBuffer(this.tbsView)}set tbs(e){this.tbsView=new Uint8Array(e)}constructor(e={}){super(),this.tbsView=new Uint8Array(r(e,Ch,Bt.defaultValues(Ch))),this.version=r(e,Bh,Bt.defaultValues(Bh)),this.subject=r(e,Ih,Bt.defaultValues(Ih)),this.subjectPublicKeyInfo=r(e,Vh,Bt.defaultValues(Vh)),ur in e&&(this.attributes=r(e,ur,Bt.defaultValues(ur))),this.signatureAlgorithm=r(e,Yl,Bt.defaultValues(Yl)),this.signatureValue=r(e,Ql,Bt.defaultValues(Ql)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ch:return be;case Bh:return 0;case Ih:return new re;case Vh:return new Xe;case ur:return[];case Yl:return new v;case Ql:return new G;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({value:[dv(t.certificationRequestInfo||{}),new d({name:t.signatureAlgorithm||Yl,value:[new T,new K({optional:!0})]}),new G({name:t.signatureValue||Ql})]})}fromSchema(e){C(e,fv);const t=N(e,e,Bt.schema());p.assertSchema(t,this.className),this.tbsView=t.result.CertificationRequestInfo.valueBeforeDecodeView,this.version=t.result[Of].valueBlock.valueDec,this.subject=new re({schema:t.result[Rf]}),this.subjectPublicKeyInfo=new Xe({schema:t.result[Tf]}),Ju in t.result&&(this.attributes=Array.from(t.result[Ju],s=>new oe({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 ur in this&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.attributes||[],t=>t.toSchema())})),new d({value:e})}toSchema(e=!1){let t;if(e===!1){if(this.tbsView.byteLength===0)return Bt.schema();const s=Be(this.tbsView);p.assert(s,"PKCS#10 Certificate Request"),t=s.result}else t=this.encodeTBS();return new d({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 ur 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 G({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)}}Bt.CLASS_NAME="CertificationRequest";const Oi="digestAlgorithm",Ri="digest",mv=[Oi,Ri];class bt extends k{constructor(e={}){super(),this.digestAlgorithm=r(e,Oi,bt.defaultValues(Oi)),this.digest=r(e,Ri,bt.defaultValues(Ri)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Oi:return new v;case Ri:return new B;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Oi:return v.compareWithDefault("algorithmId",t.algorithmId)&&!("algorithmParams"in t);case Ri:return t.isEqual(bt.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.digestAlgorithm||{names:{blockName:Oi}}),new B({name:t.digest||Ri})]})}fromSchema(e){C(e,mv);const t=N(e,e,bt.schema({names:{digestAlgorithm:{names:{blockName:Oi}},digest:Ri}}));p.assertSchema(t,this.className),this.digestAlgorithm=new v({schema:t.result.digestAlgorithm}),this.digest=t.result.digest}toSchema(){return new d({value:[this.digestAlgorithm.toSchema(),this.digest]})}toJSON(){return{digestAlgorithm:this.digestAlgorithm.toJSON(),digest:this.digest.toJSON()}}}bt.CLASS_NAME="DigestInfo";const ha="eContentType",Ct="eContent",gv=[ha,Ct];class it extends k{constructor(e={}){if(super(),this.eContentType=r(e,ha,it.defaultValues(ha)),Ct in e&&(this.eContent=r(e,Ct,it.defaultValues(Ct)),this.eContent.idBlock.tagClass===1&&this.eContent.idBlock.tagNumber===4&&this.eContent.idBlock.isConstructed===!1)){const t=new B({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;h<c.length;h++)c[h]=o[h];t.valueBlock.value.push(new B({valueHex:l})),i-=o.length,s+=o.length}this.eContent=t}e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ha:return u;case Ct:return new B;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ha:return t===u;case Ct:return t.idBlock.tagClass===1&&t.idBlock.tagNumber===4?t.isEqual(it.defaultValues(Ct)):!1;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.eContentType||u}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new K({name:t.eContent||u})]})]})}fromSchema(e){C(e,gv);const t=N(e,e,it.schema({names:{eContentType:ha,eContent:Ct}}));p.assertSchema(t,this.className),this.eContentType=t.result.eContentType.valueBlock.toString(),Ct in t.result&&(this.eContent=t.result.eContent)}toSchema(){const e=[];return e.push(new T({value:this.eContentType})),this.eContent&&it.compareWithDefault(Ct,this.eContent)===!1&&e.push(new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[this.eContent]})),new d({value:e})}toJSON(){const e={eContentType:this.eContentType};return this.eContent&&it.compareWithDefault(Ct,this.eContent)===!1&&(e.eContent=this.eContent.toJSON()),e}}it.CLASS_NAME="EncapsulatedContentInfo";const Ti="mac",Di="macSalt",ls="iterations",wv=[Ti,Di,ls];class Ge extends k{constructor(e={}){super(),this.mac=r(e,Ti,Ge.defaultValues(Ti)),this.macSalt=r(e,Di,Ge.defaultValues(Di)),ls in e&&(this.iterations=r(e,ls,Ge.defaultValues(ls))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ti:return new bt;case Di:return new B;case ls:return 1;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ti:return bt.compareWithDefault("digestAlgorithm",t.digestAlgorithm)&&bt.compareWithDefault("digest",t.digest);case Di:return t.isEqual(Ge.defaultValues(e));case ls:return t===Ge.defaultValues(e);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,optional:t.optional||!0,value:[bt.schema(t.mac||{names:{blockName:Ti}}),new B({name:t.macSalt||Di}),new S({optional:!0,name:t.iterations||ls})]})}fromSchema(e){C(e,wv);const t=N(e,e,Ge.schema({names:{mac:{names:{blockName:Ti}},macSalt:Di,iterations:ls}}));p.assertSchema(t,this.className),this.mac=new bt({schema:t.result.mac}),this.macSalt=t.result.macSalt,ls in t.result&&(this.iterations=t.result.iterations.valueBlock.valueDec)}toSchema(){const e=[this.mac.toSchema(),this.macSalt];return this.iterations!==void 0&&e.push(new S({value:this.iterations})),new d({value:e})}toJSON(){const e={mac:this.mac.toJSON(),macSalt:this.macSalt.toJSON()};return this.iterations!==void 0&&(e.iterations=this.iterations),e}}Ge.CLASS_NAME="MacData";const $i="hashAlgorithm",Ki="hashedMessage",yv=[$i,Ki];class He extends k{static async create(e,t,s=q(!0)){const n=s.getOIDByAlgorithm({name:e},!0,"hashAlgorithm"),i=await s.digest(e,t);return new He({hashAlgorithm:new v({algorithmId:n,algorithmParams:new Ae}),hashedMessage:new B({valueHex:i})})}constructor(e={}){super(),this.hashAlgorithm=r(e,$i,He.defaultValues($i)),this.hashedMessage=r(e,Ki,He.defaultValues(Ki)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case $i:return new v;case Ki:return new B;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case $i:return t.algorithmId===u&&!("algorithmParams"in t);case Ki:return t.isEqual(He.defaultValues(e))===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.hashAlgorithm||{}),new B({name:t.hashedMessage||u})]})}fromSchema(e){C(e,yv);const t=N(e,e,He.schema({names:{hashAlgorithm:{names:{blockName:$i}},hashedMessage:Ki}}));p.assertSchema(t,this.className),this.hashAlgorithm=new v({schema:t.result.hashAlgorithm}),this.hashedMessage=t.result.hashedMessage}toSchema(){return new d({value:[this.hashAlgorithm.toSchema(),this.hashedMessage]})}toJSON(){return{hashAlgorithm:this.hashAlgorithm.toJSON(),hashedMessage:this.hashedMessage.toJSON()}}}He.CLASS_NAME="MessageImprint";const fa="reqCert",mn="singleRequestExtensions",vv=[fa,mn];class Ss extends k{constructor(e={}){super(),this.reqCert=r(e,fa,Ss.defaultValues(fa)),mn in e&&(this.singleRequestExtensions=r(e,mn,Ss.defaultValues(mn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case fa:return new Ne;case mn:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case fa:return t.isEqual(Ss.defaultValues(e));case mn:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[Ne.schema(t.reqCert||{}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[ke.schema(t.extensions||{names:{blockName:t.singleRequestExtensions||u}})]})]})}fromSchema(e){C(e,vv);const t=N(e,e,Ss.schema({names:{reqCert:{names:{blockName:fa}},extensions:{names:{blockName:mn}}}}));p.assertSchema(t,this.className),this.reqCert=new Ne({schema:t.result.reqCert}),mn in t.result&&(this.singleRequestExtensions=Array.from(t.result.singleRequestExtensions.valueBlock.value,s=>new xe({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 d({value:Array.from(this.singleRequestExtensions,t=>t.toSchema())})]})),new d({value:e})}toJSON(){const e={reqCert:this.reqCert.toJSON()};return this.singleRequestExtensions&&(e.singleRequestExtensions=Array.from(this.singleRequestExtensions,t=>t.toJSON())),e}}Ss.CLASS_NAME="Request";const Qc="tbs",da="version",ma="requestorName",Xc="requestList",ga="requestExtensions",Xa="TBSRequest",hu=`${Xa}.${da}`,fu=`${Xa}.${ma}`,qh=`${Xa}.requests`,du=`${Xa}.${ga}`,Sv=[Xa,hu,fu,qh,du];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(r(e,Qc,Le.defaultValues(Qc))),da in e&&(this.version=r(e,da,Le.defaultValues(da))),ma in e&&(this.requestorName=r(e,ma,Le.defaultValues(ma))),this.requestList=r(e,Xc,Le.defaultValues(Xc)),ga in e&&(this.requestExtensions=r(e,ga,Le.defaultValues(ga))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Qc:return be;case da:return 0;case ma:return new Z;case Xc:case ga:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Qc:return t.byteLength===0;case da:return t===Le.defaultValues(e);case ma:return t.type===Z.defaultValues("type")&&Object.keys(t.value).length===0;case Xc:case ga:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||Xa,value:[new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new S({name:t.TBSRequestVersion||hu})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[Z.schema(t.requestorName||{names:{blockName:fu}})]}),new d({name:t.requestList||"TBSRequest.requestList",value:[new J({name:t.requests||qh,value:Ss.schema(t.requestNames||{})})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:2},value:[ke.schema(t.extensions||{names:{blockName:t.requestExtensions||du}})]})]})}fromSchema(e){C(e,Sv);const t=N(e,e,Le.schema());p.assertSchema(t,this.className),this.tbsView=t.result.TBSRequest.valueBeforeDecodeView,hu in t.result&&(this.version=t.result[hu].valueBlock.valueDec),fu in t.result&&(this.requestorName=new Z({schema:t.result[fu]})),this.requestList=Array.from(t.result[qh],s=>new Ss({schema:s})),du in t.result&&(this.requestExtensions=Array.from(t.result[du].valueBlock.value,s=>new xe({schema:s})))}toSchema(e=!1){let t;if(e===!1){if(this.tbsView.byteLength===0)return Le.schema();const s=Be(this.tbsView);if(p.assert(s,"TBS Request"),!(s.result instanceof d))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 d({value:Array.from(this.requestList,n=>n.toSchema())})),this.requestExtensions&&s.push(new w({idBlock:{tagClass:3,tagNumber:2},value:[new d({value:Array.from(this.requestExtensions,n=>n.toSchema())})]})),t=new d({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 hr="signatureAlgorithm",fr="signature",Ds="certs";class ut extends k{constructor(e={}){super(),this.signatureAlgorithm=r(e,hr,ut.defaultValues(hr)),this.signature=r(e,fr,ut.defaultValues(fr)),Ds in e&&(this.certs=r(e,Ds,ut.defaultValues(Ds))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case hr:return new v;case fr:return new G;case Ds:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case hr:return t.algorithmId===u&&!("algorithmParams"in t);case fr:return t.isEqual(ut.defaultValues(e));case Ds:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[v.schema(t.signatureAlgorithm||{}),new G({name:t.signature||u}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new d({value:[new J({name:t.certs||u,value:X.schema({})})]})]})]})}fromSchema(e){C(e,[hr,fr,Ds]);const t=N(e,e,ut.schema({names:{signatureAlgorithm:{names:{blockName:hr}},signature:fr,certs:Ds}}));p.assertSchema(t,this.className),this.signatureAlgorithm=new v({schema:t.result.signatureAlgorithm}),this.signature=t.result.signature,Ds in t.result&&(this.certs=Array.from(t.result.certs,s=>new X({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 d({value:Array.from(this.certs,t=>t.toSchema())})]})),new d({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}}ut.CLASS_NAME="Signature";const wa="tbsRequest",gn="optionalSignature",Av=[wa,gn];class hc extends k{constructor(e={}){super(),this.tbsRequest=r(e,wa,hc.defaultValues(wa)),gn in e&&(this.optionalSignature=r(e,gn,hc.defaultValues(gn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case wa:return new Le;case gn:return new ut;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case wa: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 gn:return ut.compareWithDefault("signatureAlgorithm",t.signatureAlgorithm)&&ut.compareWithDefault("signature",t.signature)&&ut.compareWithDefault("certs",t.certs);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||"OCSPRequest",value:[Le.schema(t.tbsRequest||{names:{blockName:wa}}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[ut.schema(t.optionalSignature||{names:{blockName:gn}})]})]})}fromSchema(e){C(e,Av);const t=N(e,e,hc.schema());p.assertSchema(t,this.className),this.tbsRequest=new Le({schema:t.result.tbsRequest}),gn in t.result&&(this.optionalSignature=new ut({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 d({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 Ss({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 G({valueHex:l})}verify(){}}hc.CLASS_NAME="OCSPRequest";const ya="responseType",va="response",pv=[ya,va];class Ot extends k{constructor(e={}){super(),this.responseType=r(e,ya,Ot.defaultValues(ya)),this.response=r(e,va,Ot.defaultValues(va)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case ya:return u;case va:return new B;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case ya:return t===u;case va:return t.isEqual(Ot.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new T({name:t.responseType||u}),new B({name:t.response||u})]})}fromSchema(e){C(e,pv);const t=N(e,e,Ot.schema({names:{responseType:ya,response:va}}));p.assertSchema(t,this.className),this.responseType=t.result.responseType.valueBlock.toString(),this.response=t.result.response}toSchema(){return new d({value:[new T({value:this.responseType}),this.response]})}toJSON(){return{responseType:this.responseType,response:this.response.toJSON()}}}Ot.CLASS_NAME="ResponseBytes";const dr="responseStatus",zt="responseBytes";class Pa extends k{constructor(e={}){super(),this.responseStatus=r(e,dr,Pa.defaultValues(dr)),zt in e&&(this.responseBytes=r(e,zt,Pa.defaultValues(zt))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case dr:return new tr;case zt:return new Ot;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case dr:return t.isEqual(Pa.defaultValues(e));case zt:return Ot.compareWithDefault("responseType",t.responseType)&&Ot.compareWithDefault("response",t.response);default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||"OCSPResponse",value:[new tr({name:t.responseStatus||dr}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[Ot.schema(t.responseBytes||{names:{blockName:zt}})]})]})}fromSchema(e){C(e,[dr,zt]);const t=N(e,e,Pa.schema());p.assertSchema(t,this.className),this.responseStatus=t.result.responseStatus,zt in t.result&&(this.responseBytes=new Ot({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 d({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!==zc)return i;try{const o=Be(this.responseBytes.response.valueBlock.valueHexView);p.assert(o,"Basic OCSP response"),n=new At({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===zc)return At.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(!(zt in this))throw new Error("Empty ResponseBytes field");if(this.responseBytes&&this.responseBytes.responseType===zc){const n=At.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"}`)}}Pa.CLASS_NAME="OCSPResponse";const _n="type",cs="attributes",Zc="encodedValue",bv=[cs];class me extends k{constructor(e={}){super(),this.type=r(e,_n,me.defaultValues(_n)),this.attributes=r(e,cs,me.defaultValues(cs)),this.encodedValue=r(e,Zc,me.defaultValues(Zc)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case _n:return-1;case cs:return[];case Zc:return be;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case _n:return t===me.defaultValues(_n);case cs:return t.length===0;case Zc:return t.byteLength===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(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:oe.schema()})]})}fromSchema(e){C(e,bv);const t=N(e,e,me.schema({names:{tagNumber:this.type,attributes:cs}}));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,!(cs in t.result)){if(this.type===0)throw new Error("Wrong structure of SignedUnsignedAttributes");return}this.attributes=Array.from(t.result.attributes,n=>new oe({schema:n}))}toSchema(){if(me.compareWithDefault(_n,this.type)||me.compareWithDefault(cs,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(_n,this.type)||me.compareWithDefault(cs,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 Sa="version",Pi="sid",Aa="digestAlgorithm",wn="signedAttrs",pa="signatureAlgorithm",Xl="signature",yn="unsignedAttrs",Dn="SignerInfo",Wh=`${Dn}.${Sa}`,Zl=`${Dn}.${Pi}`,Gh=`${Dn}.${Aa}`,mu=`${Dn}.${wn}`,Yh=`${Dn}.${pa}`,Qh=`${Dn}.${Xl}`,gu=`${Dn}.${yn}`,kv=[Wh,Zl,Gh,mu,Yh,Qh,gu];class Se extends k{constructor(e={}){super(),this.version=r(e,Sa,Se.defaultValues(Sa)),this.sid=r(e,Pi,Se.defaultValues(Pi)),this.digestAlgorithm=r(e,Aa,Se.defaultValues(Aa)),wn in e&&(this.signedAttrs=r(e,wn,Se.defaultValues(wn))),this.signatureAlgorithm=r(e,pa,Se.defaultValues(pa)),this.signature=r(e,Xl,Se.defaultValues(Xl)),yn in e&&(this.unsignedAttrs=r(e,yn,Se.defaultValues(yn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Sa:return 0;case Pi:return new K;case Aa:return new v;case wn:return new me({type:0});case pa:return new v;case Xl:return new B;case yn:return new me({type:1});default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Sa:return Se.defaultValues(Sa)===t;case Pi:return t instanceof K;case Aa:return t instanceof v?t.isEqual(Se.defaultValues(Aa)):!1;case wn:return me.compareWithDefault("type",t.type)&&me.compareWithDefault("attributes",t.attributes)&&me.compareWithDefault("encodedValue",t.encodedValue);case pa:return t instanceof v?t.isEqual(Se.defaultValues(pa)):!1;case Xl:case yn: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=r(e,"names",{});return new d({name:Dn,value:[new S({name:t.version||Wh}),new he({value:[Ie.schema(t.sidSchema||{names:{blockName:Zl}}),new he({value:[new w({optional:!0,name:t.sid||Zl,idBlock:{tagClass:3,tagNumber:0},value:[new B]}),new _({optional:!0,name:t.sid||Zl,idBlock:{tagClass:3,tagNumber:0}})]})]}),v.schema(t.digestAlgorithm||{names:{blockName:Gh}}),me.schema(t.signedAttrs||{names:{blockName:mu,tagNumber:0}}),v.schema(t.signatureAlgorithm||{names:{blockName:Yh}}),new B({name:t.signature||Qh}),me.schema(t.unsignedAttrs||{names:{blockName:gu,tagNumber:1}})]})}fromSchema(e){C(e,kv);const t=N(e,e,Se.schema());p.assertSchema(t,this.className),this.version=t.result[Wh].valueBlock.valueDec;const s=t.result[Zl];s.idBlock.tagClass===1?this.sid=new Ie({schema:s}):this.sid=s,this.digestAlgorithm=new v({schema:t.result[Gh]}),mu in t.result&&(this.signedAttrs=new me({type:0,schema:t.result[mu]})),this.signatureAlgorithm=new v({schema:t.result[Yh]}),this.signature=t.result[Qh],gu in t.result&&(this.unsignedAttrs=new me({type:1,schema:t.result[gu]}))}toSchema(){if(Se.compareWithDefault(Pi,this.sid))throw new Error('Incorrectly initialized "SignerInfo" class');const e=[];return e.push(new S({value:this.version})),this.sid instanceof Ie?e.push(this.sid.toSchema()):e.push(this.sid),e.push(this.digestAlgorithm.toSchema()),this.signedAttrs&&Se.compareWithDefault(wn,this.signedAttrs)===!1&&e.push(this.signedAttrs.toSchema()),e.push(this.signatureAlgorithm.toSchema()),e.push(this.signature),this.unsignedAttrs&&Se.compareWithDefault(yn,this.unsignedAttrs)===!1&&e.push(this.unsignedAttrs.toSchema()),new d({value:e})}toJSON(){if(Se.compareWithDefault(Pi,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(wn,this.signedAttrs)===!1&&(e.signedAttrs=this.signedAttrs.toJSON()),this.unsignedAttrs&&Se.compareWithDefault(yn,this.unsignedAttrs)===!1&&(e.unsignedAttrs=this.unsignedAttrs.toJSON()),e}}Se.CLASS_NAME="SignerInfo";const zl="version",ec="policy",tc="messageImprint",sc="serialNumber",nc="genTime",Li="ordering",Ui="nonce",ba="accuracy",ka="tsa",Ea="extensions",Lt="TSTInfo",Xh=`${Lt}.${zl}`,Zh=`${Lt}.${ec}`,zh=`${Lt}.${tc}`,ef=`${Lt}.${sc}`,tf=`${Lt}.${nc}`,wu=`${Lt}.${ba}`,yu=`${Lt}.${Li}`,vu=`${Lt}.${Ui}`,Su=`${Lt}.${ka}`,Au=`${Lt}.${Ea}`,Ev=[Xh,Zh,zh,ef,tf,wu,yu,vu,Su,Au];class $e extends k{constructor(e={}){super(),this.version=r(e,zl,$e.defaultValues(zl)),this.policy=r(e,ec,$e.defaultValues(ec)),this.messageImprint=r(e,tc,$e.defaultValues(tc)),this.serialNumber=r(e,sc,$e.defaultValues(sc)),this.genTime=r(e,nc,$e.defaultValues(nc)),ba in e&&(this.accuracy=r(e,ba,$e.defaultValues(ba))),Li in e&&(this.ordering=r(e,Li,$e.defaultValues(Li))),Ui in e&&(this.nonce=r(e,Ui,$e.defaultValues(Ui))),ka in e&&(this.tsa=r(e,ka,$e.defaultValues(ka))),Ea in e&&(this.extensions=r(e,Ea,$e.defaultValues(Ea))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case zl:return 0;case ec:return u;case tc:return new He;case sc:return new S;case nc:return new Date(0,0,0);case ba:return new ct;case Li:return!1;case Ui:return new S;case ka:return new Z;case Ea:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case zl:case ec:case nc:case Li:return t===$e.defaultValues(Li);case tc:return He.compareWithDefault($i,t.hashAlgorithm)&&He.compareWithDefault(Ki,t.hashedMessage);case sc:case Ui:return t.isEqual($e.defaultValues(Ui));case ba:return ct.compareWithDefault(Ps,t.seconds)&&ct.compareWithDefault(Ls,t.millis)&&ct.compareWithDefault(Us,t.micros);case ka:return Z.compareWithDefault(mo,t.type)&&Z.compareWithDefault(go,t.value);case Ea:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||Lt,value:[new S({name:t.version||Xh}),new T({name:t.policy||Zh}),He.schema(t.messageImprint||{names:{blockName:zh}}),new S({name:t.serialNumber||ef}),new ue({name:t.genTime||tf}),ct.schema(t.accuracy||{names:{blockName:wu}}),new Yt({name:t.ordering||yu,optional:!0}),new S({name:t.nonce||vu,optional:!0}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[Z.schema(t.tsa||{names:{blockName:Su}})]}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:[new J({name:t.extensions||Au,value:xe.schema(t.extension||{})})]})]})}fromSchema(e){C(e,Ev);const t=N(e,e,$e.schema());p.assertSchema(t,this.className),this.version=t.result[Xh].valueBlock.valueDec,this.policy=t.result[Zh].valueBlock.toString(),this.messageImprint=new He({schema:t.result[zh]}),this.serialNumber=t.result[ef],this.genTime=t.result[tf].toDate(),wu in t.result&&(this.accuracy=new ct({schema:t.result[wu]})),yu in t.result&&(this.ordering=t.result[yu].valueBlock.value),vu in t.result&&(this.nonce=t.result[vu]),Su in t.result&&(this.tsa=new Z({schema:t.result[Su]})),Au in t.result&&(this.extensions=Array.from(t.result[Au],s=>new xe({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 Yt({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 d({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.genTime<e.notBefore)throw new Error("Generation time for TSTInfo object is less than notBefore value");if(e.notAfter&&this.genTime>e.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)}}$e.CLASS_NAME="TSTInfo";const Na="version",ic="digestAlgorithms",rc="encapContentInfo",Ca="certificates",Ba="crls",ac="signerInfos",ho="ocsps",rr="SignedData",sf=`${rr}.${Na}`,pu=`${rr}.${ic}`,nf=`${rr}.${rc}`,bu=`${rr}.${Ca}`,ku=`${rr}.${Ba}`,Eu=`${rr}.${ac}`,Nv=[sf,pu,nf,bu,ku,Eu];class Me 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=r(e,Na,Ue.defaultValues(Na)),this.digestAlgorithms=r(e,ic,Ue.defaultValues(ic)),this.encapContentInfo=r(e,rc,Ue.defaultValues(rc)),Ca in e&&(this.certificates=r(e,Ca,Ue.defaultValues(Ca))),Ba in e&&(this.crls=r(e,Ba,Ue.defaultValues(Ba))),ho in e&&(this.ocsps=r(e,ho,Ue.defaultValues(ho))),this.signerInfos=r(e,ac,Ue.defaultValues(ac)),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Na:return 0;case ic:return[];case rc:return new it;case Ca:return[];case Ba:return[];case ho:return[];case ac:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Na:return t===Ue.defaultValues(Na);case rc:return it.compareWithDefault("eContentType",t.eContentType)&&it.compareWithDefault("eContent",t.eContent);case ic:case Ca:case Ba:case ho:case ac:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return t.optional===void 0&&(t.optional=!1),new d({name:t.blockName||rr,optional:t.optional,value:[new S({name:t.version||sf}),new pe({value:[new J({name:t.digestAlgorithms||pu,value:v.schema()})]}),it.schema(t.encapContentInfo||{names:{blockName:nf}}),new w({name:t.certificates||bu,optional:!0,idBlock:{tagClass:3,tagNumber:0},value:Wt.schema().valueBlock.value}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:1},value:ps.schema(t.crls||{names:{crls:ku}}).valueBlock.value}),new pe({value:[new J({name:t.signerInfos||Eu,value:Se.schema()})]})]})}fromSchema(e){C(e,Nv);const t=N(e,e,Ue.schema());if(p.assertSchema(t,this.className),this.version=t.result[sf].valueBlock.valueDec,pu in t.result&&(this.digestAlgorithms=Array.from(t.result[pu],s=>new v({schema:s}))),this.encapContentInfo=new it({schema:t.result[nf]}),bu in t.result){const s=new Wt({schema:new pe({value:t.result[bu].valueBlock.value})});this.certificates=s.certificates.slice(0)}ku in t.result&&(this.crls=Array.from(t.result[ku],s=>s.idBlock.tagClass===1?new Ve({schema:s}):(s.idBlock.tagClass=1,s.idBlock.tagNumber=16,new As({schema:s})))),Eu in t.result&&(this.signerInfos=Array.from(t.result[Eu],s=>new Se({schema:s})))}toSchema(e=!1){const t=[];if(this.certificates&&this.certificates.length&&this.certificates.some(s=>s instanceof On)||this.crls&&this.crls.length&&this.crls.some(s=>s instanceof As)?this.version=5:this.certificates&&this.certificates.length&&this.certificates.some(s=>s instanceof ft)?this.version=4:this.certificates&&this.certificates.length&&this.certificates.some(s=>s instanceof ms)||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 Wt({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 As){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 d({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}={},f=q(!0)){let g=null,m=null;try{let b=be,A=u,E=[];const y=this.signerInfos[e];if(!y)throw new Me({date:n,code:1,message:"Unable to get signer by supplied index"});if(!this.certificates)throw new Me({date:n,code:2,message:"No certificates attached to this signed data"});if(y.sid instanceof Ie){for(const V of this.certificates)if(V instanceof X&&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 M of this.certificates){if(!(M instanceof X))continue;const te=await f.digest({name:"sha-1"},M.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView);if(Ja(te,R)){g=M;break}}}if(!g)throw new Me({date:n,code:3,message:"Unable to find signer certificate"});if(this.encapContentInfo.eContentType===Vw){if(!this.encapContentInfo.eContent)throw new Me({date:n,code:15,message:"Error during verification: TSTInfo eContent is empty",signatureVerified:null,signerCertificate:g,timestampSerial:m,signerCertificateVerified:!0});let V;try{V=$e.fromBER(this.encapContentInfo.eContent.valueBlock.valueHexView)}catch{throw new Me({date:n,code:15,message:"Error during verification: TSTInfo wrong ASN.1 schema ",signatureVerified:null,signerCertificate:g,timestampSerial:m,signerCertificateVerified:!0})}if(n=V.genTime,m=V.serialNumber.valueBlock.valueHexView.slice().buffer,t.byteLength===0)throw new Me({date:n,code:4,message:"Missed detached data input array"});if(!await V.verify({data:t},f))throw new Me({date:n,code:15,message:"Error during verification: TSTInfo verification is failed",signatureVerified:!1,signerCertificate:g,timestampSerial:m,signerCertificateVerified:!0})}if(i){const V=this.certificates.filter(j=>j instanceof X&&!!Km(j,g)),R={checkDate:n,certs:V,trustedCerts:s};h&&(R.findIssuer=h),c&&(R.findOrigin=c);const M=new Yu(R);if(M.certs.push(g),this.crls)for(const j of this.crls)"thisUpdate"in j?M.crls.push(j):j.otherRevInfoFormat===zc&&M.ocsps.push(new At({schema:j.otherRevInfo}));this.ocsps&&M.ocsps.push(...this.ocsps);const te=await M.verify({passedWhenNotRevValues:o},f).catch(j=>{throw new Me({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 Me({date:n,code:5,message:`Validation of signer's certificate failed: ${te.resultMessage}`,signerCertificate:g,signerCertificateVerified:!1})}const O=f.getAlgorithmByOID(y.digestAlgorithm.algorithmId);if(!("name"in O))throw new Me({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 Me({date:n,code:8,message:"Missed detached data input array",signerCertificate:g,signerCertificateVerified:!0});if(y.signedAttrs){let V=!1,R=!1;for(const M of y.signedAttrs.attributes)if(M.type==="1.2.840.113549.1.9.3"&&(V=!0),M.type==="1.2.840.113549.1.9.4"&&(R=!0,b=M.values[0].valueBlock.valueHex),V&&R)break;if(V===!1)throw new Me({date:n,code:9,message:'Attribute "content-type" is a mandatory attribute for "signed attributes"',signerCertificate:g,signerCertificateVerified:!0});if(R===!1)throw new Me({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 f.digest(A,new Uint8Array(t));if(!Ja(V,b))throw new Me({date:n,code:15,message:"Error during verification: Message digest doesn't match",signatureVerified:null,signerCertificate:g,timestampSerial:m,signerCertificateVerified:!0});t=y.signedAttrs.encodedValue}const I=y.signatureAlgorithm.algorithmId==="1.2.840.113549.1.1.1"?await f.verifyWithPublicKey(t,y.signature,g.subjectPublicKeyInfo,y.signatureAlgorithm,A):await f.verifyWithPublicKey(t,y.signature,g.subjectPublicKeyInfo,y.signatureAlgorithm);return l?{date:n,code:14,message:u,signatureVerified:I,signerCertificate:g,timestampSerial:m,signerCertificateVerified:!0,certificatePath:E}:I}catch(b){throw b instanceof Me?b:new Me({date:n,code:15,message:`Error during verification: ${b instanceof Error?b.message:b}`,signatureVerified:null,signerCertificate:g,timestampSerial:m,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(m=>m.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),f=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 m=L.toUint8Array(n);m[0]=49}else{const m=this.encapContentInfo.eContent;if(m)m.idBlock.tagClass===1&&m.idBlock.tagNumber===4?n=m.getValue():n=m.valueBlock.valueBeforeDecodeView.slice().buffer;else if(n.byteLength===0)throw new Error("Missed detached data input array")}const g=await i.signWithPrivateKey(n,e,f);l.signature=new B({valueHex:g})}}Ue.CLASS_NAME="SignedData";Ue.ID_DATA=kf;const Hi="version",_i="authSafe",us="macData",fo="parsedValue",Cv=[Hi,_i,us];class $t extends k{constructor(e={}){super(),this.version=r(e,Hi,$t.defaultValues(Hi)),this.authSafe=r(e,_i,$t.defaultValues(_i)),us in e&&(this.macData=r(e,us,$t.defaultValues(us))),fo in e&&(this.parsedValue=r(e,fo,$t.defaultValues(fo))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Hi:return 3;case _i:return new le;case us:return new Ge;case fo:return{};default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Hi:return t===$t.defaultValues(e);case _i:return le.compareWithDefault("contentType",t.contentType)&&le.compareWithDefault("content",t.content);case us:return Ge.compareWithDefault("mac",t.mac)&&Ge.compareWithDefault("macSalt",t.macSalt)&&Ge.compareWithDefault("iterations",t.iterations);case fo:return t instanceof Object&&Object.keys(t).length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.version||Hi}),le.schema(t.authSafe||{names:{blockName:_i}}),Ge.schema(t.macData||{names:{blockName:us,optional:!0}})]})}fromSchema(e){C(e,Cv);const t=N(e,e,$t.schema({names:{version:Hi,authSafe:{names:{blockName:_i}},macData:{names:{blockName:us}}}}));p.assertSchema(t,this.className),this.version=t.result.version.valueBlock.valueDec,this.authSafe=new le({schema:t.result.authSafe}),us in t.result&&(this.macData=new Ge({schema:t.result.macData}))}toSchema(){const e=[new S({value:this.version}),this.authSafe.toSchema()];return this.macData&&e.push(this.macData.toSchema()),new d({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 le({contentType:le.DATA,content:new B({valueHex:i})});const o=await t.stampDataWithPassword({password:e.password,hashAlgorithm:e.hmacHashAlgorithm,salt:s,iterationCount:e.iterations,contentToStamp:i});this.macData=new Ge({mac:new bt({digestAlgorithm:new v({algorithmId:t.getOIDByAlgorithm({name:e.hmacHashAlgorithm},!0,"hmacHashAlgorithm")}),digest:new B({valueHex:o})}),macSalt:new B({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 it({eContentType:"1.2.840.113549.1.7.1",eContent:new B({valueHex:s})}),certificates:[e.signingCertificate]}),i=await t.digest({name:e.hashAlgorithm},new Uint8Array(s)),o=[];o.push(new oe({type:"1.2.840.113549.1.9.3",values:[new T({value:"1.2.840.113549.1.7.1"})]})),o.push(new oe({type:"1.2.840.113549.1.9.5",values:[new Fa({valueDate:new Date})]})),o.push(new oe({type:"1.2.840.113549.1.9.4",values:[new B({valueHex:i})]})),n.signerInfos.push(new Se({version:1,sid:new Ie({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 le({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 le.DATA:{Q.assertEmpty(e.password,"password"),this.parsedValue.integrityMode=0,ie.assert(this.authSafe.content,"authSafe.content",B);const s=this.authSafe.content.getValue();if(this.parsedValue.authenticatedSafe=Tn.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 le.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",B);const i=n.getValue();if(this.parsedValue.authenticatedSafe=Tn.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}`)}}}$t.CLASS_NAME="PFX";const Ia="status",vn="statusStrings",Sn="failInfo",Bv=[Ia,vn,Sn];var cd;(function(a){a[a.granted=0]="granted",a[a.grantedWithMods=1]="grantedWithMods",a[a.rejection=2]="rejection",a[a.waiting=3]="waiting",a[a.revocationWarning=4]="revocationWarning",a[a.revocationNotification=5]="revocationNotification"})(cd||(cd={}));class pt extends k{constructor(e={}){super(),this.status=r(e,Ia,pt.defaultValues(Ia)),vn in e&&(this.statusStrings=r(e,vn,pt.defaultValues(vn))),Sn in e&&(this.failInfo=r(e,Sn,pt.defaultValues(Sn))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ia:return 2;case vn:return[];case Sn:return new G;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ia:return t===pt.defaultValues(e);case vn:return t.length===0;case Sn:return t.isEqual(pt.defaultValues(e));default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||u,value:[new S({name:t.status||u}),new d({optional:!0,value:[new J({name:t.statusStrings||u,value:new kt})]}),new G({name:t.failInfo||u,optional:!0})]})}fromSchema(e){C(e,Bv);const t=N(e,e,pt.schema({names:{status:Ia,statusStrings:vn,failInfo:Sn}}));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,vn in t.result&&(this.statusStrings=t.result.statusStrings),Sn in t.result&&(this.failInfo=t.result.failInfo)}toSchema(){const e=[];return e.push(new S({value:this.status})),this.statusStrings&&e.push(new d({optional:!0,value:this.statusStrings})),this.failInfo&&e.push(this.failInfo),new d({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}}pt.CLASS_NAME="PKIStatusInfo";const oc="version",lc="messageImprint",Va="reqPolicy",xa="nonce",hs="certReq",Oa="extensions",ar="TimeStampReq",rf=`${ar}.${oc}`,af=`${ar}.${lc}`,Nu=`${ar}.${Va}`,Cu=`${ar}.${xa}`,Bu=`${ar}.${hs}`,Iu=`${ar}.${Oa}`,Iv=[rf,af,Nu,Cu,Bu,Iu];class rt extends k{constructor(e={}){super(),this.version=r(e,oc,rt.defaultValues(oc)),this.messageImprint=r(e,lc,rt.defaultValues(lc)),Va in e&&(this.reqPolicy=r(e,Va,rt.defaultValues(Va))),xa in e&&(this.nonce=r(e,xa,rt.defaultValues(xa))),hs in e&&(this.certReq=r(e,hs,rt.defaultValues(hs))),Oa in e&&(this.extensions=r(e,Oa,rt.defaultValues(Oa))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case oc:return 0;case lc:return new He;case Va:return u;case xa:return new S;case hs:return!1;case Oa:return[];default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case oc:case Va:case hs:return t===rt.defaultValues(e);case lc:return He.compareWithDefault("hashAlgorithm",t.hashAlgorithm)&&He.compareWithDefault("hashedMessage",t.hashedMessage);case xa:return t.isEqual(rt.defaultValues(e));case Oa:return t.length===0;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||ar,value:[new S({name:t.version||rf}),He.schema(t.messageImprint||{names:{blockName:af}}),new T({name:t.reqPolicy||Nu,optional:!0}),new S({name:t.nonce||Cu,optional:!0}),new Yt({name:t.certReq||Bu,optional:!0}),new w({optional:!0,idBlock:{tagClass:3,tagNumber:0},value:[new J({name:t.extensions||Iu,value:xe.schema()})]})]})}fromSchema(e){C(e,Iv);const t=N(e,e,rt.schema());p.assertSchema(t,this.className),this.version=t.result[rf].valueBlock.valueDec,this.messageImprint=new He({schema:t.result[af]}),Nu in t.result&&(this.reqPolicy=t.result[Nu].valueBlock.toString()),Cu in t.result&&(this.nonce=t.result[Cu]),Bu in t.result&&(this.certReq=t.result[Bu].valueBlock.value),Iu in t.result&&(this.extensions=Array.from(t.result[Iu],s=>new xe({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),hs in this&&rt.compareWithDefault(hs,this.certReq)===!1&&e.push(new Yt({value:this.certReq})),this.extensions&&e.push(new w({idBlock:{tagClass:3,tagNumber:0},value:Array.from(this.extensions,t=>t.toSchema())})),new d({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&&rt.compareWithDefault(hs,this.certReq)===!1&&(e.certReq=this.certReq),this.extensions&&(e.extensions=Array.from(this.extensions,t=>t.toJSON())),e}}rt.CLASS_NAME="TimeStampReq";const Ra="status",Ta="timeStampToken",Df="TimeStampResp",of=`${Df}.${Ra}`,Vu=`${Df}.${Ta}`,Vv=[of,Vu];class fc extends k{constructor(e={}){super(),this.status=r(e,Ra,fc.defaultValues(Ra)),Ta in e&&(this.timeStampToken=r(e,Ta,fc.defaultValues(Ta))),e.schema&&this.fromSchema(e.schema)}static defaultValues(e){switch(e){case Ra:return new pt;case Ta:return new le;default:return super.defaultValues(e)}}static compareWithDefault(e,t){switch(e){case Ra:return pt.compareWithDefault(Ra,t.status)&&!("statusStrings"in t)&&!("failInfo"in t);case Ta:return t.contentType===u&&t.content instanceof K;default:return super.defaultValues(e)}}static schema(e={}){const t=r(e,"names",{});return new d({name:t.blockName||Df,value:[pt.schema(t.status||{names:{blockName:of}}),le.schema(t.timeStampToken||{names:{blockName:Vu,optional:!0}})]})}fromSchema(e){C(e,Vv);const t=N(e,e,fc.schema());p.assertSchema(t,this.className),this.status=new pt({schema:t.result[of]}),Vu in t.result&&(this.timeStampToken=new le({schema:t.result[Vu]}))}toSchema(){const e=[];return e.push(this.status.toSchema()),this.timeStampToken&&e.push(this.timeStampToken.toSchema()),new d({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!==Dm)throw new Error(`Wrong format of timeStampToken: ${this.timeStampToken.contentType}`)}}fc.CLASS_NAME="TimeStampResp";function xv(){if(typeof globalThis<"u"&&"crypto"in globalThis){let a="webcrypto";"webkitSubtle"in globalThis.crypto&&(a="safari"),Wf(a,new Tu({name:a,crypto:globalThis.crypto}))}else if(typeof crypto<"u"&&"webcrypto"in crypto){const a="NodeJS ^15",e=crypto.webcrypto;Wf(a,new Tu({name:a,crypto:e}))}}xv();const Ov="1.2.840.113549.1.12.10.1.1",jm="1.2.840.113549.1.12.10.1.2",Fm="1.2.840.113549.1.12.10.1.3",qm="1.2.840.113549.1.9.20",Wm="1.2.840.113549.1.9.21";async function Fv(a,e,t={}){const s=Be(dc(a));if(s.offset===-1)throw new Error("Invalid PKCS#12 ASN.1.");const n=new TextEncoder().encode(e).buffer,i=new $t({schema:s.result});await i.parseInternalValues({password:n,checkIntegrity:!!i.macData});const o=i.parsedValue?.authenticatedSafe;if(!o)throw new Error("PKCS#12 authenticatedSafe was not found.");await o.parseInternalValues({safeContents:o.safeContents.map(()=>({password:n}))});const l=[],c=[];for(const h of Rv(o.parsedValue))for(const f of h.value.safeBags){if(f.bagId===Ov&&f.bagValue instanceof nt){l.push({friendlyName:ud(f),localKeyId:xh(f),privateKeyInfo:f.bagValue});continue}if(f.bagId===jm&&f.bagValue instanceof Kt){if(await Tv(f.bagValue,n),!f.bagValue.parsedValue)throw new Error("Could not decrypt a PKCS#12 private key bag.");l.push({friendlyName:ud(f),localKeyId:xh(f),privateKeyInfo:f.bagValue.parsedValue});continue}if(f.bagId===Fm&&f.bagValue instanceof ws){const g=Dv(f.bagValue);g&&c.push({localKeyId:xh(f),certificate:g})}}if(l.length===0)throw new Error("No private key was found in the PKCS#12 file.");return l.map((h,f)=>{const g=Pv(h,c,f);return{id:t.createId?.()??crypto.randomUUID?.()??String(Date.now()),label:h.friendlyName||h.localKeyId||void 0,privateKeyDer:Oh(h.privateKeyInfo),publicKeyDer:g?Oh(g.subjectPublicKeyInfo):void 0,certificateDer:g?Oh(g):void 0,sourceName:t.sourceName}})}async function qv(a,e){if(a.length===0)throw new Error("No key pair was selected.");const t=new TextEncoder().encode(e).buffer,s=[];for(const o of a){if(!o.privateKeyDer)throw new Error(`${o.label||"Selected key pair"} does not have a PrivateKey item.`);const l=hd(20),c=Lv(o.label,l),h=new Kt({parsedValue:nt.fromBER(dc(o.privateKeyDer))});await h.makeInternalValues({password:t,contentEncryptionAlgorithm:{name:"AES-CBC",length:256,iv:dc(hd(16))},hmacHashAlgorithm:"SHA-256",iterationCount:1e5}),s.push(new qt({bagId:jm,bagValue:h,bagAttributes:c})),o.certificateDer&&s.push(new qt({bagId:Fm,bagValue:new ws({parsedValue:X.fromBER(dc(o.certificateDer))}),bagAttributes:c}))}const n=new Tn({parsedValue:{safeContents:[{privacyMode:0,value:new Tt({safeBags:s})}]}});await n.makeInternalValues({safeContents:[{}]});const i=new $t({parsedValue:{integrityMode:0,authenticatedSafe:n}});return await i.makeInternalValues({password:t,iterations:1e5,pbkdf2HashAlgorithm:{name:"SHA-256"},hmacHashAlgorithm:"SHA-256"}),new Uint8Array(i.toSchema().toBER(!1))}function Rv(a){if(!fd(a)||!Array.isArray(a.safeContents))throw new Error("PKCS#12 safe contents were not parsed.");return a.safeContents.filter(e=>fd(e)&&e.value instanceof Tt)}async function Tv(a,e){await a.parseInternalValues({password:e})}function Dv(a){if(a.certId!==Hh)return null;if(a.parsedValue instanceof X)return a.parsedValue;throw new Error("PKCS#12 certificate bag did not contain an X.509 certificate.")}function Pv(a,e,t){if(e.length!==0){if(a.localKeyId){const s=e.find(n=>n.localKeyId===a.localKeyId);if(s)return s.certificate}return e[Math.min(t,e.length-1)].certificate}}function xh(a){const e=a.bagAttributes?.find(s=>s.type===Wm),[t]=e?.values??[];return t instanceof B?Uv(t.valueBlock.valueHexView):null}function ud(a){const e=a.bagAttributes?.find(s=>s.type===qm),[t]=e?.values??[];return t instanceof sr||t instanceof kt?t.valueBlock.value:null}function Lv(a,e){const t=[new oe({type:Wm,values:[new B({valueHex:dc(e)})]})];return a&&t.unshift(new oe({type:qm,values:[new sr({value:a})]})),t}function hd(a){const e=new Uint8Array(a);return crypto.getRandomValues(e),e}function Oh(a){return new Uint8Array(a.toSchema().toBER(!1))}function dc(a){const e=new ArrayBuffer(a.byteLength);return new Uint8Array(e).set(a),e}function Uv(a){return[...a].map(e=>e.toString(16).padStart(2,"0")).join("")}function fd(a){return typeof a=="object"&&a!==null}export{kn as AttributeTypeAndValue,qi as BasicConstraints,G as BitString,X as Certificate,Bt as CertificationRequest,xe as Extension,Fu as IA5String,S as Integer,T as ObjectIdentifier,Rt as PrintableString,re as RelativeDistinguishedNames,Ce as Time,kt as Utf8String,Be as fromBER,Fv as readPkcs12Keys,qv as writePkcs12Keys};
|