@peculiar/x509
Version:
@peculiar/x509 is an easy to use TypeScript/Javascript library based on @peculiar/asn1-schema that makes generating X.509 Certificates and Certificate Requests as well as validating certificate chains easy
85 lines • 195 kB
JavaScript
/*!
* MIT License
*
* Copyright (c) Peculiar Ventures. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
var x509=function(e){"use strict";
/*!
* MIT License
*
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/class t{static isArrayBuffer(e){return"[object ArrayBuffer]"===Object.prototype.toString.call(e)}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||0===e.byteOffset&&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,r){const i=t.toUint8Array(e),s=t.toUint8Array(r);if(i.length!==s.byteLength)return!1;for(let e=0;e<i.length;e++)if(i[e]!==s[e])return!1;return!0}static concat(...e){let t;t=!Array.isArray(e[0])||e[1]instanceof Function?Array.isArray(e[0])&&e[1]instanceof Function?e[0]:e[e.length-1]instanceof Function?e.slice(0,e.length-1):e:e[0];let r=0;for(const e of t)r+=e.byteLength;const i=new Uint8Array(r);let s=0;for(const e of t){const t=this.toUint8Array(e);i.set(t,s),s+=t.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}}const r="string",i=/^[0-9a-f\s]+$/i,s=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,n=/^[a-zA-Z0-9-_]+$/;class o{static fromString(e){const t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return r.buffer}static toString(e){const r=t.toUint8Array(e);let i="";for(let e=0;e<r.length;e++)i+=String.fromCharCode(r[e]);return decodeURIComponent(escape(i))}}class a{static toString(e,r=!1){const i=t.toArrayBuffer(e),s=new DataView(i);let n="";for(let e=0;e<i.byteLength;e+=2){const t=s.getUint16(e,r);n+=String.fromCharCode(t)}return n}static fromString(e,t=!1){const r=new ArrayBuffer(2*e.length),i=new DataView(r);for(let r=0;r<e.length;r++)i.setUint16(2*r,e.charCodeAt(r),t);return r}}class c{static isHex(e){return typeof e===r&&i.test(e)}static isBase64(e){return typeof e===r&&s.test(e)}static isBase64Url(e){return typeof e===r&&n.test(e)}static ToString(e,r="utf8"){const i=t.toUint8Array(e);switch(r.toLowerCase()){case"utf8":return this.ToUtf8String(i);case"binary":return this.ToBinary(i);case"hex":return this.ToHex(i);case"base64":return this.ToBase64(i);case"base64url":return this.ToBase64Url(i);case"utf16le":return a.toString(i,!0);case"utf16":case"utf16be":return a.toString(i);default:throw new Error(`Unknown type of encoding '${r}'`)}}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 a.fromString(e,!0);case"utf16":case"utf16be":return a.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const r=t.toUint8Array(e);if("undefined"!=typeof btoa){const e=this.ToString(r,"binary");return btoa(e)}return Buffer.from(r).toString("base64")}static FromBase64(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!c.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return"undefined"!=typeof atob?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(!c.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=c.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return o.fromString(e);case"utf16":case"utf16be":return a.fromString(e);case"utf16le":case"usc2":return a.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=c.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return o.toString(e);case"utf16":case"utf16be":return a.toString(e);case"utf16le":case"usc2":return a.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){const t=e.length,r=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);return r.buffer}static ToBinary(e){const r=t.toUint8Array(e);let i="";for(let e=0;e<r.length;e++)i+=String.fromCharCode(r[e]);return i}static ToHex(e){const r=t.toUint8Array(e);let i="";const s=r.length;for(let e=0;e<s;e++){const t=r[e];t<16&&(i+="0"),i+=t.toString(16)}return i}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!c.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);const r=new Uint8Array(t.length/2);for(let e=0;e<t.length;e+=2){const i=t.slice(e,e+2);r[e/2]=parseInt(i,16)}return r.buffer}static ToUtf16String(e,t=!1){return a.toString(e,t)}static FromUtf16String(e,t=!1){return a.fromString(e,t)}static Base64Padding(e){const t=4-e.length%4;if(t<4)for(let r=0;r<t;r++)e+="=";return e}static formatString(e){return(null==e?void 0:e.replace(/[\n\r\t ]/g,""))||""}}function l(e,t){if(!e||!t)return!1;if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let t=0;t<e.byteLength;t++)if(r[t]!==i[t])return!1;return!0}
/*!
Copyright (c) Peculiar Ventures, LLC
*/function u(e,t){let r=0;if(1===e.length)return e[0];for(let i=e.length-1;i>=0;i--)r+=e[e.length-1-i]*Math.pow(2,t*i);return r}function h(e,t,r=-1){const i=r;let s=e,n=0,o=Math.pow(2,t);for(let r=1;r<8;r++){if(e<o){let e;if(i<0)e=new ArrayBuffer(r),n=r;else{if(i<r)return new ArrayBuffer(0);e=new ArrayBuffer(i),n=i}const o=new Uint8Array(e);for(let e=r-1;e>=0;e--){const r=Math.pow(2,e*t);o[n-e-1]=Math.floor(s/r),s-=o[n-e-1]*r}return e}o*=Math.pow(2,t)}return new ArrayBuffer(0)}function p(...e){let t=0,r=0;for(const r of e)t+=r.length;const i=new ArrayBuffer(t),s=new Uint8Array(i);for(const t of e)s.set(t,r),r+=t.length;return s}function f(){const e=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const t=255===e[0]&&128&e[1],r=0===e[0]&&!(128&e[1]);(t||r)&&this.warnings.push("Needlessly long format")}const t=new ArrayBuffer(this.valueHex.byteLength),r=new Uint8Array(t);for(let e=0;e<this.valueHex.byteLength;e++)r[e]=0;r[0]=128&e[0];const i=u(r,8),s=new ArrayBuffer(this.valueHex.byteLength),n=new Uint8Array(s);for(let t=0;t<this.valueHex.byteLength;t++)n[t]=e[t];n[0]&=127;return u(n,8)-i}function y(e,t){const r=e.toString(10);if(t<r.length)return"";const i=t-r.length,s=new Array(i);for(let e=0;e<i;e++)s[e]="0";return s.join("").concat(r)}
/*!
* Copyright (c) 2014, GMO GlobalSign
* Copyright (c) 2015-2022, Peculiar Ventures
* All rights reserved.
*
* Author 2014-2019, Yury Strozhevsky
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/function g(){if("undefined"==typeof BigInt)throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function d(e){let t=0,r=0;for(let r=0;r<e.length;r++){t+=e[r].byteLength}const i=new Uint8Array(t);for(let t=0;t<e.length;t++){const s=e[t];i.set(new Uint8Array(s),r),r+=s.byteLength}return i.buffer}function v(e,t,r,i){return t instanceof Uint8Array?t.byteLength?r<0?(e.error="Wrong parameter: inputOffset less than zero",!1):i<0?(e.error="Wrong parameter: inputLength less than zero",!1):!(t.byteLength-r-i<0)||(e.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):(e.error="Wrong parameter: inputBuffer has zero length",!1):(e.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}c.DEFAULT_UTF8_ENCODING="utf8";class m{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return d(this.items)}}const b=[new Uint8Array([1])],w="0123456789",A="name",S="valueHexView",B="",x=new ArrayBuffer(0),k=new Uint8Array(0),C="EndOfContent",E="OCTET STRING",N="BIT STRING";function O(e){var r;return(r=class extends e{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(e){this.valueHexView=new Uint8Array(e)}constructor(...e){var r;super(...e);const i=e[0]||{};this.isHexOnly=null!==(r=i.isHexOnly)&&void 0!==r&&r,this.valueHexView=i.valueHex?t.toUint8Array(i.valueHex):k}fromBER(e,t,r){const i=e instanceof ArrayBuffer?new Uint8Array(e):e;if(!v(this,i,t,r))return-1;const s=t+r;return this.valueHexView=i.subarray(t,s),this.valueHexView.length?(this.blockLength=r,s):(this.warnings.push("Zero buffer length"),t)}toBER(e=!1){return this.isHexOnly?e?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",x)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:c.ToHex(this.valueHexView)}}}).NAME="hexBlock",r}class I{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:r="",warnings:i=[],valueBeforeDecode:s=k}={}){this.blockLength=e,this.error=r,this.warnings=i,this.valueBeforeDecodeView=t.toUint8Array(s)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:c.ToHex(this.valueBeforeDecodeView)}}}I.NAME="baseBlock";class T extends I{fromBER(e,t,r){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'")}}T.NAME="valueBlock";class j extends(O(I)){constructor({idBlock:e={}}={}){var r,i,s,n;super(),e?(this.isHexOnly=null!==(r=e.isHexOnly)&&void 0!==r&&r,this.valueHexView=e.valueHex?t.toUint8Array(e.valueHex):k,this.tagClass=null!==(i=e.tagClass)&&void 0!==i?i:-1,this.tagNumber=null!==(s=e.tagNumber)&&void 0!==s?s:-1,this.isConstructed=null!==(n=e.isConstructed)&&void 0!==n&&n):(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",x}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const r=new Uint8Array(1);if(!e){let e=this.tagNumber;e&=31,t|=e,r[0]=t}return r.buffer}if(!this.isHexOnly){const r=h(this.tagNumber,7),i=new Uint8Array(r),s=r.byteLength,n=new Uint8Array(s+1);if(n[0]=31|t,!e){for(let e=0;e<s-1;e++)n[e+1]=128|i[e];n[s]=i[s-1]}return n.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=31|t,!e){const e=this.valueHexView;for(let t=0;t<e.length-1;t++)r[t+1]=128|e[t];r[this.valueHexView.byteLength]=e[e.length-1]}return r.buffer}fromBER(e,r,i){const s=t.toUint8Array(e);if(!v(this,s,r,i))return-1;const n=s.subarray(r,r+i);if(0===n.length)return this.error="Zero buffer length",-1;switch(192&n[0]){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=!(32&~n[0]),this.isHexOnly=!1;const o=31&n[0];if(31!==o)this.tagNumber=o,this.blockLength=1;else{let e=1,t=this.valueHexView=new Uint8Array(255),r=255;for(;128&n[e];){if(t[e-1]=127&n[e],e++,e>=n.length)return this.error="End of input reached before message was fully decoded",-1;if(e===r){r+=255;const e=new Uint8Array(r);for(let r=0;r<t.length;r++)e[r]=t[r];t=this.valueHexView=new Uint8Array(r)}}this.blockLength=e+1,t[e-1]=127&n[e];const i=new Uint8Array(e);for(let r=0;r<e;r++)i[r]=t[r];t=this.valueHexView=new Uint8Array(e),t.set(i),this.blockLength<=9?this.tagNumber=u(t,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(1===this.tagClass&&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 r+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}j.NAME="identificationBlock";class U extends I{constructor({lenBlock:e={}}={}){var t,r,i;super(),this.isIndefiniteForm=null!==(t=e.isIndefiniteForm)&&void 0!==t&&t,this.longFormUsed=null!==(r=e.longFormUsed)&&void 0!==r&&r,this.length=null!==(i=e.length)&&void 0!==i?i:0}fromBER(e,r,i){const s=t.toUint8Array(e);if(!v(this,s,r,i))return-1;const n=s.subarray(r,r+i);if(0===n.length)return this.error="Zero buffer length",-1;if(255===n[0])return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=128===n[0],this.isIndefiniteForm)return this.blockLength=1,r+this.blockLength;if(this.longFormUsed=!!(128&n[0]),!1===this.longFormUsed)return this.length=n[0],this.blockLength=1,r+this.blockLength;const o=127&n[0];if(o>8)return this.error="Too big integer",-1;if(o+1>n.length)return this.error="End of input reached before message was fully decoded",-1;const a=r+1,c=s.subarray(a,a+o);return 0===c[o-1]&&this.warnings.push("Needlessly long encoded length"),this.length=u(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,r+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),!1===e&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){const i=h(this.length,8);if(i.byteLength>127)return this.error="Too big length",x;if(t=new ArrayBuffer(i.byteLength+1),e)return t;const s=new Uint8Array(i);r=new Uint8Array(t),r[0]=128|i.byteLength;for(let e=0;e<i.byteLength;e++)r[e+1]=s[e];return t}return t=new ArrayBuffer(1),!1===e&&(r=new Uint8Array(t),r[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}U.NAME="lengthBlock";const R={};class V extends I{constructor({name:e="",optional:t=!1,primitiveSchema:r,...i}={},s){super(i),this.name=e,this.optional=t,r&&(this.primitiveSchema=r),this.idBlock=new j(i),this.lenBlock=new U(i),this.valueBlock=s?new s(i):new T(i)}fromBER(e,t,r){const i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===i?(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 r=t||new m;t||P(this);const i=this.idBlock.toBER(e);if(r.write(i),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const t=this.valueBlock.toBER(e);this.lenBlock.length=t.byteLength;const i=this.lenBlock.toBER(e);r.write(i),r.write(t)}return t?x:r.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"ascii"===e?this.onAsciiEncoding():c.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${c.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;return function(e,t){if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),i=new Uint8Array(t);for(let e=0;e<r.length;e++)if(r[e]!==i[e])return!1;return!0}(this.toBER(),e.toBER())}}function P(e){var t;if(e instanceof R.Constructed)for(const t of e.valueBlock.value)P(t)&&(e.lenBlock.isIndefiniteForm=!0);return!!(null===(t=e.lenBlock)||void 0===t?void 0:t.isIndefiniteForm)}V.NAME="BaseBlock";class L extends V{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e="",...t}={},r){super(t,r),e&&this.fromString(e)}fromBER(e,t,r){const i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===i?(this.error=this.valueBlock.error,i):(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),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}L.NAME="BaseStringBlock";class D extends(O(T)){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}var H,M,$,K,F,W;D.NAME="PrimitiveValueBlock";class z extends V{constructor(e={}){super(e,D),this.idBlock.isConstructed=!1}}function q(e,t=0,r=e.length){const i=t;let s=new V({},T);const n=new I;if(!v(n,e,t,r))return s.error=n.error,{offset:-1,result:s};if(!e.subarray(t,t+r).length)return s.error="Zero buffer length",{offset:-1,result:s};let o=s.idBlock.fromBER(e,t,r);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),-1===o)return s.error=s.idBlock.error,{offset:-1,result:s};if(t=o,r-=s.idBlock.blockLength,o=s.lenBlock.fromBER(e,t,r),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),-1===o)return s.error=s.lenBlock.error,{offset:-1,result:s};if(t=o,r-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let a=V;if(1===s.idBlock.tagClass){if(s.idBlock.tagNumber>=37&&!1===s.idBlock.isHexOnly)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};a=R.EndOfContent;break;case 1:a=R.Boolean;break;case 2:a=R.Integer;break;case 3:a=R.BitString;break;case 4:a=R.OctetString;break;case 5:a=R.Null;break;case 6:a=R.ObjectIdentifier;break;case 10:a=R.Enumerated;break;case 12:a=R.Utf8String;break;case 13:a=R.RelativeObjectIdentifier;break;case 14:a=R.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:a=R.Sequence;break;case 17:a=R.Set;break;case 18:a=R.NumericString;break;case 19:a=R.PrintableString;break;case 20:a=R.TeletexString;break;case 21:a=R.VideotexString;break;case 22:a=R.IA5String;break;case 23:a=R.UTCTime;break;case 24:a=R.GeneralizedTime;break;case 25:a=R.GraphicString;break;case 26:a=R.VisibleString;break;case 27:a=R.GeneralString;break;case 28:a=R.UniversalString;break;case 29:a=R.CharacterString;break;case 30:a=R.BmpString;break;case 31:a=R.DATE;break;case 32:a=R.TimeOfDay;break;case 33:a=R.DateTime;break;case 34:a=R.Duration;break;default:{const e=s.idBlock.isConstructed?new R.Constructed:new R.Primitive;e.idBlock=s.idBlock,e.lenBlock=s.lenBlock,e.warnings=s.warnings,s=e}}}else a=s.idBlock.isConstructed?R.Constructed:R.Primitive;return s=function(e,t){if(e instanceof t)return e;const r=new t;return r.idBlock=e.idBlock,r.lenBlock=e.lenBlock,r.warnings=e.warnings,r.valueBeforeDecodeView=e.valueBeforeDecodeView,r}(s,a),o=s.fromBER(e,t,s.lenBlock.isIndefiniteForm?r:s.lenBlock.length),s.valueBeforeDecodeView=e.subarray(i,i+s.blockLength),{offset:o,result:s}}function G(e){if(!e.byteLength){const e=new V({},T);return e.error="Input buffer has zero length",{offset:-1,result:e}}return q(t.toUint8Array(e).slice(),0,e.byteLength)}function J(e,t){return e?1:t}H=z,R.Primitive=H,z.NAME="PRIMITIVE";class _ extends T{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,r,i){const s=t.toUint8Array(e);if(!v(this,s,r,i))return-1;if(this.valueBeforeDecodeView=s.subarray(r,r+i),0===this.valueBeforeDecodeView.length)return this.warnings.push("Zero buffer length"),r;let n=r;for(;J(this.isIndefiniteForm,i)>0;){const e=q(s,n,i);if(-1===e.offset)return this.error=e.result.error,this.warnings.concat(e.result.warnings),-1;if(n=e.offset,this.blockLength+=e.result.blockLength,i-=e.result.blockLength,this.value.push(e.result),this.isIndefiniteForm&&e.result.constructor.NAME===C)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===C?this.value.pop():this.warnings.push("No EndOfContent block encoded")),n}toBER(e,t){const r=t||new m;for(let t=0;t<this.value.length;t++)this.value[t].toBER(e,r);return t?x:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const t of this.value)e.value.push(t.toJSON());return e}}_.NAME="ConstructedValueBlock";class X extends V{constructor(e={}){super(e,_),this.idBlock.isConstructed=!0}fromBER(e,t,r){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return-1===i?(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 t of this.valueBlock.value)e.push(t.toString("ascii").split("\n").map(e=>` ${e}`).join("\n"));const t=3===this.idBlock.tagClass?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :\n${e.join("\n")}`:`${t} :`}}M=X,R.Constructed=M,X.NAME="CONSTRUCTED";class Z extends T{fromBER(e,t,r){return t}toBER(e){return x}}Z.override="EndOfContentValueBlock";class Y extends V{constructor(e={}){super(e,Z),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}$=Y,R.EndOfContent=$,Y.NAME=C;class Q extends V{constructor(e={}){super(e,T),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){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+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){const r=new ArrayBuffer(2);if(!e){const e=new Uint8Array(r);e[0]=5,e[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}K=Q,R.Null=K,Q.NAME="NULL";class ee extends(O(T)){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,...r}={}){super(r),r.valueHex?this.valueHexView=t.toUint8Array(r.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,r,i){const s=t.toUint8Array(e);return v(this,s,r,i)?(this.valueHexView=s.subarray(r,r+i),i>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,f.call(this),this.blockLength=i,r+i):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}ee.NAME="BooleanValueBlock";class te extends V{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,ee),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}F=te,R.Boolean=F,te.NAME="BOOLEAN";class re extends(O(_)){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=_.prototype.fromBER.call(this,e,t,r),-1===i)return i;for(let e=0;e<this.value.length;e++){const t=this.value[e].constructor.NAME;if(t===C){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(t!==E)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,t,r),this.blockLength=r;return i}toBER(e,t){return this.isConstructed?_.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}re.NAME="OctetStringValueBlock";let ie=class extends V{constructor({idBlock:e={},lenBlock:t={},...r}={}){var i,s;null!==(i=r.isConstructed)&&void 0!==i||(r.isConstructed=!!(null===(s=r.value)||void 0===s?void 0:s.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},re),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,r){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,0===r)return 0===this.idBlock.error.length&&(this.blockLength+=this.idBlock.blockLength),0===this.lenBlock.error.length&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+r);try{if(i.byteLength){const e=q(i,0,i.byteLength);-1!==e.offset&&e.offset===r&&(this.valueBlock.value=[e.result])}}catch(e){}}return super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return X.prototype.onAsciiEncoding.call(this);return`${this.constructor.NAME} : ${c.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof W&&e.push(t.valueBlock.valueHexView);return t.concat(e)}};W=ie,R.OctetString=W,ie.NAME=E;class se extends(O(_)){constructor({unusedBits:e=0,isConstructed:t=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,r,i){if(!i)return r;let s=-1;if(this.isConstructed){if(s=_.prototype.fromBER.call(this,e,r,i),-1===s)return s;for(const e of this.value){const t=e.constructor.NAME;if(t===C){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(t!==N)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const r=e.valueBlock;if(this.unusedBits>0&&r.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=r.unusedBits}return s}const n=t.toUint8Array(e);if(!v(this,n,r,i))return-1;const o=n.subarray(r,r+i);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const e=o.subarray(1);try{if(e.byteLength){const t=q(e,0,e.byteLength);-1!==t.offset&&t.offset===i-1&&(this.value=[t.result])}}catch(e){}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,r+i}toBER(e,t){if(this.isConstructed)return _.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return x;const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}var ne;se.NAME="BitStringValueBlock";let oe=class extends V{constructor({idBlock:e={},lenBlock:t={},...r}={}){var i,s;null!==(i=r.isConstructed)&&void 0!==i||(r.isConstructed=!!(null===(s=r.value)||void 0===s?void 0:s.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},se),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return X.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const r of t)e.push(r.toString(2).padStart(8,"0"));const r=e.join("");return`${this.constructor.NAME} : ${r.substring(0,r.length-this.valueBlock.unusedBits)}`}}};var ae,ce,le,ue,he,pe,fe;function ye(e,t){const r=new Uint8Array([0]),i=new Uint8Array(e),s=new Uint8Array(t);let n=i.slice(0);const o=n.length-1,a=s.slice(0),c=a.length-1;let l=0;let u=0;for(let e=c<o?o:c;e>=0;e--,u++){if(!0==u<a.length)l=n[o-u]+a[c-u]+r[0];else l=n[o-u]+r[0];if(r[0]=l/10,!0==u>=n.length)n=p(new Uint8Array([l%10]),n);else n[o-u]=l%10}return r[0]>0&&(n=p(r,n)),n}function ge(e){if(e>=b.length)for(let t=b.length;t<=e;t++){const e=new Uint8Array([0]);let r=b[t-1].slice(0);for(let t=r.length-1;t>=0;t--){const i=new Uint8Array([(r[t]<<1)+e[0]]);e[0]=i[0]/10,r[t]=i[0]%10}e[0]>0&&(r=p(e,r)),b.push(r)}return b[e]}function de(e,t){let r=0;const i=new Uint8Array(e),s=new Uint8Array(t),n=i.slice(0),o=n.length-1,a=s.slice(0),c=a.length-1;let l,u=0;for(let e=c;e>=0;e--,u++)if(l=n[o-u]-a[c-u]-r,!0==l<0)r=1,n[o-u]=l+10;else r=0,n[o-u]=l;if(r>0)for(let e=o-c+1;e>=0;e--,u++){if(l=n[o-u]-r,!(l<0)){r=0,n[o-u]=l;break}r=1,n[o-u]=l+10}return n.slice()}ne=oe,R.BitString=ne,oe.NAME=N;class ve extends(O(T)){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=f.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),void 0!==e&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(function(e){const t=e<0?-1*e:e;let r=128;for(let i=1;i<8;i++){if(t<=r){if(e<0){const e=h(r-t,8,i);return new Uint8Array(e)[0]|=128,e}let s=h(t,8,i),n=new Uint8Array(s);if(128&n[0]){const e=s.slice(0),t=new Uint8Array(e);s=new ArrayBuffer(s.byteLength+1),n=new Uint8Array(s);for(let r=0;r<e.byteLength;r++)n[r+1]=t[r];n[0]=0}return s}r*=Math.pow(2,8)}return new ArrayBuffer(0)}(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,i=0){const s=this.fromBER(e,t,r);if(-1===s)return s;const n=this.valueHexView;return 0===n[0]&&128&n[1]?this.valueHexView=n.subarray(1):0!==i&&n.length<i&&(i-n.length>1&&(i=n.length+1),this.valueHexView=n.subarray(i-n.length)),s}toDER(e=!1){const t=this.valueHexView;switch(!0){case!!(128&t[0]):{const e=new Uint8Array(this.valueHexView.length+1);e[0]=0,e.set(t,1),this.valueHexView=e}break;case 0===t[0]&&!(128&t[1]):this.valueHexView=this.valueHexView.subarray(1)}return this.toBER(e)}fromBER(e,t,r){const i=super.fromBER(e,t,r);return-1===i||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=8*this.valueHexView.length-1;let t,r=new Uint8Array(8*this.valueHexView.length/3),i=0;const s=this.valueHexView;let n="",o=!1;for(let o=s.byteLength-1;o>=0;o--){t=s[o];for(let s=0;s<8;s++){if(!(1&~t))if(i===e)r=de(ge(i),r),n="-";else r=ye(r,ge(i));i++,t>>=1}}for(let e=0;e<r.length;e++)r[e]&&(o=!0),o&&(n+=w.charAt(r[e]));return!1===o&&(n+=w.charAt(0)),n}}ae=ve,ve.NAME="IntegerValueBlock",Object.defineProperty(ae.prototype,"valueHex",{set:function(e){this.valueHexView=new Uint8Array(e),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});class me extends V{constructor(e={}){super(e,ve),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return g(),BigInt(this.valueBlock.toString())}static fromBigInt(e){g();const r=BigInt(e),i=new m,s=r.toString(16).replace(/^-/,""),n=new Uint8Array(c.FromHex(s));if(r<0){const e=new Uint8Array(n.length+(128&n[0]?1:0));e[0]|=128;const s=BigInt(`0x${c.ToHex(e)}`)+r,o=t.toUint8Array(c.FromHex(s.toString(16)));o[0]|=128,i.write(o)}else 128&n[0]&&i.write(new Uint8Array([0])),i.write(n);return new ce({valueHex:i.final()})}convertToDER(){const e=new ce({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new ce({valueHex:0===this.valueBlock.valueHexView[0]?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}ce=me,R.Integer=ce,me.NAME="INTEGER";class be extends me{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}le=be,R.Enumerated=le,be.NAME="ENUMERATED";class we extends(O(T)){constructor({valueDec:e=-1,isFirstSid:t=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=t}fromBER(e,r,i){if(!i)return r;const s=t.toUint8Array(e);if(!v(this,s,r,i))return-1;const n=s.subarray(r,r+i);this.valueHexView=new Uint8Array(i);for(let e=0;e<i&&(this.valueHexView[e]=127&n[e],this.blockLength++,128&n[e]);e++);const o=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength;e++)o[e]=this.valueHexView[e];return this.valueHexView=o,128&n[this.blockLength-1]?(this.error="End of input reached before message was fully decoded",-1):(0===this.valueHexView[0]&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=u(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),r+this.blockLength)}set valueBigInt(e){g();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const r=new Uint8Array(t.length/7);for(let e=0;e<r.length;e++)r[e]=parseInt(t.slice(7*e,7*e+7),2)+(e+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const t=this.valueHexView,r=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength-1;e++)r[e]=128|t[e];return r[this.blockLength-1]=t[this.blockLength-1],r.buffer}const t=h(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",x;const r=new Uint8Array(t.byteLength);if(!e){const e=new Uint8Array(t),i=t.byteLength-1;for(let t=0;t<i;t++)r[t]=128|e[t];r[i]=e[i]}return r}toString(){let e="";if(this.isHexOnly)e=c.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}}}we.NAME="sidBlock";class Ae extends T{constructor({value:e="",...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let i=t;for(;r>0;){const t=new we;if(i=t.fromBER(e,i,r),-1===i)return this.blockLength=0,this.error=t.error,i;0===this.value.length&&(t.isFirstSid=!0),this.blockLength+=t.blockLength,r-=t.blockLength,this.value.push(t)}return i}toBER(e){const t=[];for(let r=0;r<this.value.length;r++){const i=this.value[r].toBER(e);if(0===i.byteLength)return this.error=this.value[r].error,x;t.push(i)}return d(t)}fromString(e){this.value=[];let t=0,r=0,i="",s=!1;do{if(r=e.indexOf(".",t),i=-1===r?e.substring(t):e.substring(t,r),t=r+1,s){const e=this.value[0];let t=0;switch(e.valueDec){case 0:break;case 1:t=40;break;case 2:t=80;break;default:return void(this.value=[])}const r=parseInt(i,10);if(isNaN(r))return;e.valueDec=r+t,s=!1}else{const e=new we;if(i>Number.MAX_SAFE_INTEGER){g();const t=BigInt(i);e.valueBigInt=t}else if(e.valueDec=parseInt(i,10),isNaN(e.valueDec))return;this.value.length||(e.isFirstSid=!0,s=!0),this.value.push(e)}}while(-1!==r)}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let i=this.value[r].toString();0!==r&&(e=`${e}.`),t?(i=`{${i}}`,this.value[r].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}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}}Ae.NAME="ObjectIdentifierValueBlock";class Se extends V{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Ae),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}ue=Se,R.ObjectIdentifier=ue,Se.NAME="OBJECT IDENTIFIER";class Be extends(O(I)){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,r,i){if(0===i)return r;const s=t.toUint8Array(e);if(!v(this,s,r,i))return-1;const n=s.subarray(r,r+i);this.valueHexView=new Uint8Array(i);for(let e=0;e<i&&(this.valueHexView[e]=127&n[e],this.blockLength++,128&n[e]);e++);const o=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength;e++)o[e]=this.valueHexView[e];return this.valueHexView=o,128&n[this.blockLength-1]?(this.error="End of input reached before message was fully decoded",-1):(0===this.valueHexView[0]&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=u(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),r+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const t=this.valueHexView,r=new Uint8Array(this.blockLength);for(let e=0;e<this.blockLength-1;e++)r[e]=128|t[e];return r[this.blockLength-1]=t[this.blockLength-1],r.buffer}const t=h(this.valueDec,7);if(0===t.byteLength)return this.error="Error during encoding SID value",x;const r=new Uint8Array(t.byteLength);if(!e){const e=new Uint8Array(t),i=t.byteLength-1;for(let t=0;t<i;t++)r[t]=128|e[t];r[i]=e[i]}return r.buffer}toString(){let e="";return e=this.isHexOnly?c.ToHex(this.valueHexView):this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Be.NAME="relativeSidBlock";class xe extends T{constructor({value:e="",...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let i=t;for(;r>0;){const t=new Be;if(i=t.fromBER(e,i,r),-1===i)return this.blockLength=0,this.error=t.error,i;this.blockLength+=t.blockLength,r-=t.blockLength,this.value.push(t)}return i}toBER(e,t){const r=[];for(let t=0;t<this.value.length;t++){const i=this.value[t].toBER(e);if(0===i.byteLength)return this.error=this.value[t].error,x;r.push(i)}return d(r)}fromString(e){this.value=[];let t=0,r=0,i="";do{r=e.indexOf(".",t),i=-1===r?e.substring(t):e.substring(t,r),t=r+1;const s=new Be;if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return!0;this.value.push(s)}while(-1!==r);return!0}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let i=this.value[r].toString();0!==r&&(e=`${e}.`),t?(i=`{${i}}`,e+=i):e+=i}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}}xe.NAME="RelativeObjectIdentifierValueBlock";class ke extends V{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,xe),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}he=ke,R.RelativeObjectIdentifier=he,ke.NAME="RelativeObjectIdentifier";class Ce extends X{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}pe=Ce,R.Sequence=pe,Ce.NAME="SEQUENCE";let Ee=class extends X{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};fe=Ee,R.Set=fe,Ee.NAME="SET";class Ne extends(O(T)){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=B}toJSON(){return{...super.toJSON(),value:this.value}}}Ne.NAME="StringValueBlock";class Oe extends Ne{}Oe.NAME="SimpleStringValueBlock";class Ie extends L{constructor({...e}={}){super(e,Oe)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,t.toUint8Array(e))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t);for(let i=0;i<t;i++)r[i]=e.charCodeAt(i);this.valueBlock.value=e}}Ie.NAME="SIMPLE STRING";class Te extends Ie{fromBuffer(e){this.valueBlock.valueHexView=t.toUint8Array(e);try{this.valueBlock.value=c.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=c.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(c.FromUtf8String(e)),this.valueBlock.value=e}}var je,Ue,Re,Ve,Pe,Le,De,He,Me,$e,Ke,Fe,We,ze,qe,Ge,Je,_e,Xe;Te.NAME="Utf8StringValueBlock";class Ze extends Te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}je=Ze,R.Utf8String=je,Ze.NAME="UTF8String";class Ye extends Ie{fromBuffer(e){this.valueBlock.value=c.ToUtf16String(e),this.valueBlock.valueHexView=t.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(c.FromUtf16String(e))}}Ye.NAME="BmpStringValueBlock";class Qe extends Ye{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}Ue=Qe,R.BmpString=Ue,Qe.NAME="BMPString";class et extends Ie{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(t);for(let e=0;e<r.length;e+=4)r[e]=r[e+3],r[e+1]=r[e+2],r[e+2]=0,r[e+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(4*t);for(let i=0;i<t;i++){const t=h(e.charCodeAt(i),8),s=new Uint8Array(t);if(s.length>4)continue;const n=4-s.length;for(let e=s.length-1;e>=0;e--)r[4*i+e+n]=s[e]}this.valueBlock.value=e}}et.NAME="UniversalStringValueBlock";class tt extends et{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}Re=tt,R.UniversalString=Re,tt.NAME="UniversalString";class rt extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}Ve=rt,R.NumericString=Ve,rt.NAME="NumericString";class it extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}Pe=it,R.PrintableString=Pe,it.NAME="PrintableString";class st extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}Le=st,R.TeletexString=Le,st.NAME="TeletexString";class nt extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}De=nt,R.VideotexString=De,nt.NAME="VideotexString";class ot extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}He=ot,R.IA5String=He,ot.NAME="IA5String";class at extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}Me=at,R.GraphicString=Me,at.NAME="GraphicString";class ct extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}$e=ct,R.VisibleString=$e,ct.NAME="VisibleString";class lt extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Ke=lt,R.GeneralString=Ke,lt.NAME="GeneralString";class ut extends Ie{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}Fe=ut,R.CharacterString=Fe,ut.NAME="CharacterString";class ht extends ct{constructor({value:e,valueDate:t,...r}={}){if(super(r),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 t=0;t<e.length;t++)this.valueBlock.valueHexView[t]=e.charCodeAt(t)}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,t.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);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 t=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/gi.exec(e);if(null===t)return void(this.error="Wrong input string for conversion");const r=parseInt(t[1],10);this.year=r>=50?1900+r:2e3+r,this.month=parseInt(t[2],10),this.day=parseInt(t[3],10),this.hour=parseInt(t[4],10),this.minute=parseInt(t[5],10),this.second=parseInt(t[6],10)}toString(e="iso"){if("iso"===e){const e=new Array(7);return e[0]=y(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=y(this.month,2),e[2]=y(this.day,2),e[3]=y(this.hour,2),e[4]=y(this.minute,2),e[5]=y(this.second,2),e[6]="Z",e.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}}}We=ht,R.UTCTime=We,ht.NAME="UTCTime";class pt extends ht{constructor(e={}){var t;super(e),null!==(t=this.millisecond)&&void 0!==t||(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,r=!1,i="",s="",n=0,o=0,a=0;if("Z"===e[e.length-1])i=e.substring(0,e.length-1),r=!0;else{const t=new Number(e[e.length-1]);if(isNaN(t.valueOf()))throw new Error("Wrong input string for conversion");i=e}if(r){if(-1!==i.indexOf("+"))throw new Error("Wrong input string for conversion");if(-1!==i.indexOf("-"))throw new Error("Wrong input string for conversion")}else{let e=1,t=i.indexOf("+"),r="";if(-1===t&&(t=i.indexOf("-"),e=-1),-1!==t){if(r=i.substring(t+1),i=i.substring(0,t),2!==r.length&&4!==r.length)throw new Error("Wrong input string for conversion");let s=parseInt(r.substring(0,2),10);if(isNaN(s.valueOf()))throw new Error("Wrong input string for conversion");if(o=e*s,4===r.length){if(s=parseInt(r.substring(2,4),10),isNaN(s.valueOf()))