/*! * Copyright (c) 2014, GlobalSign * Copyright (c) 2015-2019, 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 {organization} 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. *
*/
/*! * MIT License * * Copyright (c) 2017-2022 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. *
*/
const ARRAY_BUFFER_NAME = "[object ArrayBuffer]"; class BufferSourceConverter { static isArrayBuffer(data) { return Object.prototype.toString.call(data) === ARRAY_BUFFER_NAME;
} static toArrayBuffer(data) { if (this.isArrayBuffer(data)) { return data;
} if (data.byteLength === data.buffer.byteLength) { return data.buffer;
} returnthis.toUint8Array(data).slice().buffer;
} static toUint8Array(data) { returnthis.toView(data, Uint8Array);
} static toView(data, type) { if (data.constructor === type) { return data;
} if (this.isArrayBuffer(data)) { returnnew type(data);
} if (this.isArrayBufferView(data)) { returnnew type(data.buffer, data.byteOffset, data.byteLength);
} thrownew TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
} static isBufferSource(data) { returnthis.isArrayBufferView(data)
|| this.isArrayBuffer(data);
} static isArrayBufferView(data) { return ArrayBuffer.isView(data)
|| (data && this.isArrayBuffer(data.buffer));
} static isEqual(a, b) { const aView = BufferSourceConverter.toUint8Array(a); const bView = BufferSourceConverter.toUint8Array(b); if (aView.length !== bView.byteLength) { returnfalse;
} for (let i = 0; i < aView.length; i++) { if (aView[i] !== bView[i]) { returnfalse;
}
} returntrue;
} static concat(...args) { if (Array.isArray(args[0])) { const buffers = args[0];
let size = 0; for (const buffer of buffers) {
size += buffer.byteLength;
} const res = new Uint8Array(size);
let offset = 0; for (const buffer of buffers) { const view = this.toUint8Array(buffer);
res.set(view, offset);
offset += view.length;
} if (args[1]) { returnthis.toView(res, args[1]);
} return res.buffer;
} else { returnthis.concat(args);
}
}
}
class Utf8Converter { static fromString(text) { const s = unescape(encodeURIComponent(text)); const uintArray = new Uint8Array(s.length); for (let i = 0; i < s.length; i++) {
uintArray[i] = s.charCodeAt(i);
} return uintArray.buffer;
} static toString(buffer) { const buf = BufferSourceConverter.toUint8Array(buffer);
let encodedString = ""; for (let i = 0; i < buf.length; i++) {
encodedString += String.fromCharCode(buf[i]);
} const decodedString = decodeURIComponent(escape(encodedString)); return decodedString;
}
} class Utf16Converter { static toString(buffer, littleEndian = false) { const arrayBuffer = BufferSourceConverter.toArrayBuffer(buffer); const dataView = new DataView(arrayBuffer);
let res = ""; for (let i = 0; i < arrayBuffer.byteLength; i += 2) { const code = dataView.getUint16(i, littleEndian);
res += String.fromCharCode(code);
} return res;
} static fromString(text, littleEndian = false) { const res = new ArrayBuffer(text.length * 2); const dataView = new DataView(res); for (let i = 0; i < text.length; i++) {
dataView.setUint16(i * 2, text.charCodeAt(i), littleEndian);
} return res;
}
} class Convert { static isHex(data) { returntypeof data === "string"
&& /^[a-z0-9]+$/i.test(data);
} static isBase64(data) { returntypeof data === "string"
&& /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data);
} static isBase64Url(data) { returntypeof data === "string"
&& /^[a-zA-Z0-9-_]+$/i.test(data);
} static ToString(buffer, enc = "utf8") { const buf = BufferSourceConverter.toUint8Array(buffer); switch (enc.toLowerCase()) { case"utf8": returnthis.ToUtf8String(buf); case"binary": returnthis.ToBinary(buf); case"hex": returnthis.ToHex(buf); case"base64": returnthis.ToBase64(buf); case"base64url": returnthis.ToBase64Url(buf); case"utf16le": return Utf16Converter.toString(buf, true); case"utf16": case"utf16be": return Utf16Converter.toString(buf); default: thrownew Error(`Unknown type of encoding '${enc}'`);
}
} static FromString(str, enc = "utf8") { if (!str) { returnnew ArrayBuffer(0);
} switch (enc.toLowerCase()) { case"utf8": returnthis.FromUtf8String(str); case"binary": returnthis.FromBinary(str); case"hex": returnthis.FromHex(str); case"base64": returnthis.FromBase64(str); case"base64url": returnthis.FromBase64Url(str); case"utf16le": return Utf16Converter.fromString(str, true); case"utf16": case"utf16be": return Utf16Converter.fromString(str); default: thrownew Error(`Unknown type of encoding '${enc}'`);
}
} static ToBase64(buffer) { const buf = BufferSourceConverter.toUint8Array(buffer); if (typeof btoa !== "undefined") { const binary = this.ToString(buf, "binary"); return btoa(binary);
} else { return Buffer.from(buf).toString("base64");
}
} static FromBase64(base64) { const formatted = this.formatString(base64); if (!formatted) { returnnew ArrayBuffer(0);
} if (!Convert.isBase64(formatted)) { thrownew TypeError("Argument 'base64Text' is not Base64 encoded");
} if (typeof atob !== "undefined") { returnthis.FromBinary(atob(formatted));
} else { returnnew Uint8Array(Buffer.from(formatted, "base64")).buffer;
}
} static FromBase64Url(base64url) { const formatted = this.formatString(base64url); if (!formatted) { returnnew ArrayBuffer(0);
} if (!Convert.isBase64Url(formatted)) { thrownew TypeError("Argument 'base64url' is not Base64Url encoded");
} returnthis.FromBase64(this.Base64Padding(formatted.replace(/\-/g, "+").replace(/\_/g, "/")));
} static ToBase64Url(data) { returnthis.ToBase64(data).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
} static FromUtf8String(text, encoding = Convert.DEFAULT_UTF8_ENCODING) { switch (encoding) { case"ascii": returnthis.FromBinary(text); case"utf8": return Utf8Converter.fromString(text); case"utf16": case"utf16be": return Utf16Converter.fromString(text); case"utf16le": case"usc2": return Utf16Converter.fromString(text, true); default: thrownew Error(`Unknown type of encoding '${encoding}'`);
}
} static ToUtf8String(buffer, encoding = Convert.DEFAULT_UTF8_ENCODING) { switch (encoding) { case"ascii": returnthis.ToBinary(buffer); case"utf8": return Utf8Converter.toString(buffer); case"utf16": case"utf16be": return Utf16Converter.toString(buffer); case"utf16le": case"usc2": return Utf16Converter.toString(buffer, true); default: thrownew Error(`Unknown type of encoding '${encoding}'`);
}
} static FromBinary(text) { const stringLength = text.length; const resultView = new Uint8Array(stringLength); for (let i = 0; i < stringLength; i++) {
resultView[i] = text.charCodeAt(i);
} return resultView.buffer;
} static ToBinary(buffer) { const buf = BufferSourceConverter.toUint8Array(buffer);
let res = ""; for (let i = 0; i < buf.length; i++) {
res += String.fromCharCode(buf[i]);
} return res;
} static ToHex(buffer) { const buf = BufferSourceConverter.toUint8Array(buffer); const splitter = ""; const res = []; const len = buf.length; for (let i = 0; i < len; i++) { constchar = buf[i].toString(16).padStart(2, "0");
res.push(char);
} return res.join(splitter);
} static FromHex(hexString) {
let formatted = this.formatString(hexString); if (!formatted) { returnnew ArrayBuffer(0);
} if (!Convert.isHex(formatted)) { thrownew TypeError("Argument 'hexString' is not HEX encoded");
} if (formatted.length % 2) {
formatted = `0${formatted}`;
} const res = new Uint8Array(formatted.length / 2); for (let i = 0; i < formatted.length; i = i + 2) { const c = formatted.slice(i, i + 2);
res[i / 2] = parseInt(c, 16);
} return res.buffer;
} static ToUtf16String(buffer, littleEndian = false) { return Utf16Converter.toString(buffer, littleEndian);
} static FromUtf16String(text, littleEndian = false) { return Utf16Converter.fromString(text, littleEndian);
} static Base64Padding(base64) { const padCount = 4 - (base64.length % 4); if (padCount < 4) { for (let i = 0; i < padCount; i++) {
base64 += "=";
}
} return base64;
} static formatString(data) { return (data === null || data === void 0 ? void 0 : data.replace(/[\n\r\t ]/g, "")) || "";
}
}
Convert.DEFAULT_UTF8_ENCODING = "utf8";
/*! Copyright (c) Peculiar Ventures, LLC
*/ function getParametersValue(parameters, name, defaultValue) { var _a; if ((parameters instanceof Object) === false) { return defaultValue;
} return (_a = parameters[name]) !== null && _a !== void 0 ? _a : defaultValue;
} function bufferToHexCodes(inputBuffer, inputOffset = 0, inputLength = (inputBuffer.byteLength - inputOffset), insertSpace = false) {
let result = ""; for (const item of (new Uint8Array(inputBuffer, inputOffset, inputLength))) { const str = item.toString(16).toUpperCase(); if (str.length === 1) {
result += "0";
}
result += str; if (insertSpace) {
result += " ";
}
} return result.trim();
} function utilFromBase(inputBuffer, inputBase) {
let result = 0; if (inputBuffer.length === 1) { return inputBuffer[0];
} for (let i = (inputBuffer.length - 1); i >= 0; i--) {
result += inputBuffer[(inputBuffer.length - 1) - i] * Math.pow(2, inputBase * i);
} return result;
} function utilToBase(value, base, reserved = (-1)) { const internalReserved = reserved;
let internalValue = value;
let result = 0;
let biggest = Math.pow(2, base); for (let i = 1; i < 8; i++) { if (value < biggest) {
let retBuf; if (internalReserved < 0) {
retBuf = new ArrayBuffer(i);
result = i;
} else { if (internalReserved < i) { return (new ArrayBuffer(0));
}
retBuf = new ArrayBuffer(internalReserved);
result = internalReserved;
} const retView = new Uint8Array(retBuf); for (let j = (i - 1); j >= 0; j--) { const basis = Math.pow(2, j * base);
retView[result - j - 1] = Math.floor(internalValue / basis);
internalValue -= (retView[result - j - 1]) * basis;
} return retBuf;
}
biggest *= Math.pow(2, base);
} returnnew ArrayBuffer(0);
} function utilConcatBuf(...buffers) {
let outputLength = 0;
let prevLength = 0; for (const buffer of buffers) {
outputLength += buffer.byteLength;
} const retBuf = new ArrayBuffer(outputLength); const retView = new Uint8Array(retBuf); for (const buffer of buffers) {
retView.set(new Uint8Array(buffer), prevLength);
prevLength += buffer.byteLength;
} return retBuf;
} function utilConcatView(...views) {
let outputLength = 0;
let prevLength = 0; for (const view of views) {
outputLength += view.length;
} const retBuf = new ArrayBuffer(outputLength); const retView = new Uint8Array(retBuf); for (const view of views) {
retView.set(view, prevLength);
prevLength += view.length;
} return retView;
} function utilDecodeTC() { const buf = new Uint8Array(this.valueHex); if (this.valueHex.byteLength >= 2) { const condition1 = (buf[0] === 0xFF) && (buf[1] & 0x80); const condition2 = (buf[0] === 0x00) && ((buf[1] & 0x80) === 0x00); if (condition1 || condition2) { this.warnings.push("Needlessly long format");
}
} const bigIntBuffer = new ArrayBuffer(this.valueHex.byteLength); const bigIntView = new Uint8Array(bigIntBuffer); for (let i = 0; i < this.valueHex.byteLength; i++) {
bigIntView[i] = 0;
}
bigIntView[0] = (buf[0] & 0x80); const bigInt = utilFromBase(bigIntView, 8); const smallIntBuffer = new ArrayBuffer(this.valueHex.byteLength); const smallIntView = new Uint8Array(smallIntBuffer); for (let j = 0; j < this.valueHex.byteLength; j++) {
smallIntView[j] = buf[j];
}
smallIntView[0] &= 0x7F; const smallInt = utilFromBase(smallIntView, 8); return (smallInt - bigInt);
} function utilEncodeTC(value) { const modValue = (value < 0) ? (value * (-1)) : value;
let bigInt = 128; for (let i = 1; i < 8; i++) { if (modValue <= bigInt) { if (value < 0) { const smallInt = bigInt - modValue; const retBuf = utilToBase(smallInt, 8, i); const retView = new Uint8Array(retBuf);
retView[0] |= 0x80; return retBuf;
}
let retBuf = utilToBase(modValue, 8, i);
let retView = new Uint8Array(retBuf); if (retView[0] & 0x80) { const tempBuf = retBuf.slice(0); const tempView = new Uint8Array(tempBuf);
retBuf = new ArrayBuffer(retBuf.byteLength + 1);
retView = new Uint8Array(retBuf); for (let k = 0; k < tempBuf.byteLength; k++) {
retView[k + 1] = tempView[k];
}
retView[0] = 0x00;
} return retBuf;
}
bigInt *= Math.pow(2, 8);
} return (new ArrayBuffer(0));
} function isEqualBuffer(inputBuffer1, inputBuffer2) { if (inputBuffer1.byteLength !== inputBuffer2.byteLength) { returnfalse;
} const view1 = new Uint8Array(inputBuffer1); const view2 = new Uint8Array(inputBuffer2); for (let i = 0; i < view1.length; i++) { if (view1[i] !== view2[i]) { returnfalse;
}
} returntrue;
} function padNumber(inputNumber, fullLength) { const str = inputNumber.toString(10); if (fullLength < str.length) { return"";
} const dif = fullLength - str.length; const padding = new Array(dif); for (let i = 0; i < dif; i++) {
padding[i] = "0";
} const paddingString = padding.join(""); return paddingString.concat(str);
} const base64Template = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; const base64UrlTemplate = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="; function toBase64(input, useUrlTemplate = false, skipPadding = false, skipLeadingZeros = false) {
let i = 0;
let flag1 = 0;
let flag2 = 0;
let output = ""; const template = (useUrlTemplate) ? base64UrlTemplate : base64Template; if (skipLeadingZeros) {
let nonZeroPosition = 0; for (let i = 0; i < input.length; i++) { if (input.charCodeAt(i) !== 0) {
nonZeroPosition = i; break;
}
}
input = input.slice(nonZeroPosition);
} while (i < input.length) { const chr1 = input.charCodeAt(i++); if (i >= input.length) {
flag1 = 1;
} const chr2 = input.charCodeAt(i++); if (i >= input.length) {
flag2 = 1;
} const chr3 = input.charCodeAt(i++); const enc1 = chr1 >> 2; const enc2 = ((chr1 & 0x03) << 4) | (chr2 >> 4);
let enc3 = ((chr2 & 0x0F) << 2) | (chr3 >> 6);
let enc4 = chr3 & 0x3F; if (flag1 === 1) {
enc3 = enc4 = 64;
} else { if (flag2 === 1) {
enc4 = 64;
}
} if (skipPadding) { if (enc3 === 64) {
output += `${template.charAt(enc1)}${template.charAt(enc2)}`;
} else { if (enc4 === 64) {
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}`;
} else {
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
}
}
} else {
output += `${template.charAt(enc1)}${template.charAt(enc2)}${template.charAt(enc3)}${template.charAt(enc4)}`;
}
} return output;
} function fromBase64(input, useUrlTemplate = false, cutTailZeros = false) { const template = (useUrlTemplate) ? base64UrlTemplate : base64Template; function indexOf(toSearch) { for (let i = 0; i < 64; i++) { if (template.charAt(i) === toSearch) return i;
} return 64;
} function test(incoming) { return ((incoming === 64) ? 0x00 : incoming);
}
let i = 0;
let output = ""; while (i < input.length) { const enc1 = indexOf(input.charAt(i++)); const enc2 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++)); const enc3 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++)); const enc4 = (i >= input.length) ? 0x00 : indexOf(input.charAt(i++)); const chr1 = (test(enc1) << 2) | (test(enc2) >> 4); const chr2 = ((test(enc2) & 0x0F) << 4) | (test(enc3) >> 2); const chr3 = ((test(enc3) & 0x03) << 6) | test(enc4);
output += String.fromCharCode(chr1); if (enc3 !== 64) {
output += String.fromCharCode(chr2);
} if (enc4 !== 64) {
output += String.fromCharCode(chr3);
}
} if (cutTailZeros) { const outputLength = output.length;
let nonZeroStart = (-1); for (let i = (outputLength - 1); i >= 0; i--) { if (output.charCodeAt(i) !== 0) {
nonZeroStart = i; break;
}
} if (nonZeroStart !== (-1)) {
output = output.slice(0, nonZeroStart + 1);
} else {
output = "";
}
} return output;
} function arrayBufferToString(buffer) {
let resultString = ""; const view = new Uint8Array(buffer); for (const element of view) {
resultString += String.fromCharCode(element);
} return resultString;
} function stringToArrayBuffer(str) { const stringLength = str.length; const resultBuffer = new ArrayBuffer(stringLength); const resultView = new Uint8Array(resultBuffer); for (let i = 0; i < stringLength; i++) {
resultView[i] = str.charCodeAt(i);
} return resultBuffer;
} const log2 = Math.log(2); function nearestPowerOf2(length) { const base = (Math.log(length) / log2); const floor = Math.floor(base); const round = Math.round(base); return ((floor === round) ? floor : round);
} function clearProps(object, propsArray) { for (const prop of propsArray) { delete object[prop];
}
}
/*! * 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 assertBigInt() { if (typeof BigInt === "undefined") { thrownew Error("BigInt is not defined. Your environment doesn't implement BigInt.");
}
} function concat(buffers) {
let outputLength = 0;
let prevLength = 0; for (let i = 0; i < buffers.length; i++) { const buffer = buffers[i];
outputLength += buffer.byteLength;
} const retView = new Uint8Array(outputLength); for (let i = 0; i < buffers.length; i++) { const buffer = buffers[i];
retView.set(new Uint8Array(buffer), prevLength);
prevLength += buffer.byteLength;
} return retView.buffer;
} function checkBufferParams(baseBlock, inputBuffer, inputOffset, inputLength) { if (!(inputBuffer instanceof Uint8Array)) {
baseBlock.error = "Wrong parameter: inputBuffer must be 'Uint8Array'"; returnfalse;
} if (!inputBuffer.byteLength) {
baseBlock.error = "Wrong parameter: inputBuffer has zero length"; returnfalse;
} if (inputOffset < 0) {
baseBlock.error = "Wrong parameter: inputOffset less than zero"; returnfalse;
} if (inputLength < 0) {
baseBlock.error = "Wrong parameter: inputLength less than zero"; returnfalse;
} if ((inputBuffer.byteLength - inputOffset - inputLength) < 0) {
baseBlock.error = "End of input reached before message was fully decoded (inconsistent offset and length values)"; returnfalse;
} returntrue;
}
class ValueBlock extends LocalBaseBlock {
fromBER(inputBuffer, inputOffset, inputLength) { throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
}
toBER(sizeOnly, writer) { throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
}
}
ValueBlock.NAME = "valueBlock";
class LocalIdentificationBlock extends HexBlock(LocalBaseBlock) {
constructor({ idBlock = {}, } = {}) { var _a, _b, _c, _d; super(); if (idBlock) { this.isHexOnly = (_a = idBlock.isHexOnly) !== null && _a !== void 0 ? _a : false; this.valueHexView = idBlock.valueHex ? BufferSourceConverter.toUint8Array(idBlock.valueHex) : EMPTY_VIEW; this.tagClass = (_b = idBlock.tagClass) !== null && _b !== void 0 ? _b : -1; this.tagNumber = (_c = idBlock.tagNumber) !== null && _c !== void 0 ? _c : -1; this.isConstructed = (_d = idBlock.isConstructed) !== null && _d !== void 0 ? _d : false;
} else { this.tagClass = -1; this.tagNumber = -1; this.isConstructed = false;
}
}
toBER(sizeOnly = false) {
let firstOctet = 0; switch (this.tagClass) { case 1:
firstOctet |= 0x00; break; case 2:
firstOctet |= 0x40; break; case 3:
firstOctet |= 0x80; break; case 4:
firstOctet |= 0xC0; break; default: this.error = "Unknown tag class"; return EMPTY_BUFFER$1;
} if (this.isConstructed)
firstOctet |= 0x20; if (this.tagNumber < 31 && !this.isHexOnly) { const retView = new Uint8Array(1); if (!sizeOnly) {
let number = this.tagNumber;
number &= 0x1F;
firstOctet |= number;
retView[0] = firstOctet;
} return retView.buffer;
} if (!this.isHexOnly) { const encodedBuf = utilToBase(this.tagNumber, 7); const encodedView = new Uint8Array(encodedBuf); const size = encodedBuf.byteLength; const retView = new Uint8Array(size + 1);
retView[0] = (firstOctet | 0x1F); if (!sizeOnly) { for (let i = 0; i < (size - 1); i++)
retView[i + 1] = encodedView[i] | 0x80;
retView[size] = encodedView[size - 1];
} return retView.buffer;
} const retView = new Uint8Array(this.valueHexView.byteLength + 1);
retView[0] = (firstOctet | 0x1F); if (!sizeOnly) { const curView = this.valueHexView; for (let i = 0; i < (curView.length - 1); i++)
retView[i + 1] = curView[i] | 0x80;
retView[this.valueHexView.byteLength] = curView[curView.length - 1];
} return retView.buffer;
}
fromBER(inputBuffer, inputOffset, inputLength) { const inputView = BufferSourceConverter.toUint8Array(inputBuffer); if (!checkBufferParams(this, inputView, inputOffset, inputLength)) { return -1;
} const intBuffer = inputView.subarray(inputOffset, inputOffset + inputLength); if (intBuffer.length === 0) { this.error = "Zero buffer length"; return -1;
} const tagClassMask = intBuffer[0] & 0xC0; switch (tagClassMask) { case 0x00: this.tagClass = (1); break; case 0x40: this.tagClass = (2); break; case 0x80: this.tagClass = (3); break; case 0xC0: this.tagClass = (4); break; default: this.error = "Unknown tag class"; return -1;
} this.isConstructed = (intBuffer[0] & 0x20) === 0x20; this.isHexOnly = false; const tagNumberMask = intBuffer[0] & 0x1F; if (tagNumberMask !== 0x1F) { this.tagNumber = (tagNumberMask); this.blockLength = 1;
} else {
let count = 1;
let intTagNumberBuffer = this.valueHexView = new Uint8Array(255);
let tagNumberBufferMaxLength = 255;
while (intBuffer[count] & 0x80) {
intTagNumberBuffer[count - 1] = intBuffer[count] & 0x7F;
count++;
if (count >= intBuffer.length) {
this.error = "End of input reached before message was fully decoded";
return -1;
}
if (count === tagNumberBufferMaxLength) {
tagNumberBufferMaxLength += 255;
const tempBufferView = new Uint8Array(tagNumberBufferMaxLength);
for (let i = 0; i < intTagNumberBuffer.length; i++)
tempBufferView[i] = intTagNumberBuffer[i];
intTagNumberBuffer = this.valueHexView = new Uint8Array(tagNumberBufferMaxLength);
}
}
this.blockLength = (count + 1);
intTagNumberBuffer[count - 1] = intBuffer[count] & 0x7F;
const tempBufferView = new Uint8Array(count);
for (let i = 0; i < count; i++)
tempBufferView[i] = intTagNumberBuffer[i];
intTagNumberBuffer = this.valueHexView = new Uint8Array(count);
intTagNumberBuffer.set(tempBufferView);
if (this.blockLength <= 9)
this.tagNumber = utilFromBase(intTagNumberBuffer, 7);
else {
this.isHexOnly = true;
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:
this.error = "Constructed encoding used for primitive type";
return -1;
}
}
return (inputOffset + this.blockLength);
}
toJSON() {
return {
...super.toJSON(),
tagClass: this.tagClass,
tagNumber: this.tagNumber,
isConstructed: this.isConstructed,
};
}
}
LocalIdentificationBlock.NAME = "identificationBlock";
class LocalLengthBlock extends LocalBaseBlock {
constructor({ lenBlock = {}, } = {}) {
var _a, _b, _c;
super();
this.isIndefiniteForm = (_a = lenBlock.isIndefiniteForm) !== null && _a !== void 0 ? _a : false;
this.longFormUsed = (_b = lenBlock.longFormUsed) !== null && _b !== void 0 ? _b : false;
this.length = (_c = lenBlock.length) !== null && _c !== void 0 ? _c : 0;
}
fromBER(inputBuffer, inputOffset, inputLength) {
const view = BufferSourceConverter.toUint8Array(inputBuffer);
if (!checkBufferParams(this, view, inputOffset, inputLength)) {
return -1;
}
const intBuffer = view.subarray(inputOffset, inputOffset + inputLength);
if (intBuffer.length === 0) {
this.error = "Zero buffer length";
return -1;
}
if (intBuffer[0] === 0xFF) {
this.error = "Length block 0xFF is reserved by standard";
return -1;
}
this.isIndefiniteForm = intBuffer[0] === 0x80;
if (this.isIndefiniteForm) {
this.blockLength = 1;
return (inputOffset + this.blockLength);
}
this.longFormUsed = !!(intBuffer[0] & 0x80);
if (this.longFormUsed === false) {
this.length = (intBuffer[0]);
this.blockLength = 1;
return (inputOffset + this.blockLength);
}
const count = intBuffer[0] & 0x7F;
if (count > 8) {
this.error = "Too big integer";
return -1;
}
if ((count + 1) > intBuffer.length) {
this.error = "End of input reached before message was fully decoded";
return -1;
}
const lenOffset = inputOffset + 1;
const lengthBufferView = view.subarray(lenOffset, lenOffset + count);
if (lengthBufferView[count - 1] === 0x00)
this.warnings.push("Needlessly long encoded length");
this.length = utilFromBase(lengthBufferView, 8);
if (this.longFormUsed && (this.length <= 127))
this.warnings.push("Unnecessary usage of long length form");
this.blockLength = count + 1;
return (inputOffset + this.blockLength);
}
toBER(sizeOnly = false) {
let retBuf;
let retView;
if (this.length > 127)
this.longFormUsed = true;
if (this.isIndefiniteForm) {
retBuf = new ArrayBuffer(1);
if (sizeOnly === false) {
retView = new Uint8Array(retBuf);
retView[0] = 0x80;
}
return retBuf;
}
if (this.longFormUsed) {
const encodedBuf = utilToBase(this.length, 8);
if (encodedBuf.byteLength > 127) {
this.error = "Too big length";
return (EMPTY_BUFFER$1);
}
retBuf = new ArrayBuffer(encodedBuf.byteLength + 1);
if (sizeOnly)
return retBuf;
const encodedView = new Uint8Array(encodedBuf);
retView = new Uint8Array(retBuf);
retView[0] = encodedBuf.byteLength | 0x80;
for (let i = 0; i < encodedBuf.byteLength; i++)
retView[i + 1] = encodedView[i];
return retBuf;
}
retBuf = new ArrayBuffer(1);
if (sizeOnly === false) {
retView = new Uint8Array(retBuf);
retView[0] = this.length;
}
return retBuf;
}
toJSON() {
return {
...super.toJSON(),
isIndefiniteForm: this.isIndefiniteForm,
longFormUsed: this.longFormUsed,
length: this.length,
};
}
}
LocalLengthBlock.NAME = "lengthBlock";
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.66Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.