forked from olcxjas-softworks/LarpixClient
update electron to v43
This commit is contained in:
parent
68ac0beedf
commit
fb6c8b6ee9
5385 changed files with 513060 additions and 123058 deletions
22
electron/node_modules/@peculiar/asn1-schema/build/es2015/convert.js
generated
vendored
Normal file
22
electron/node_modules/@peculiar/asn1-schema/build/es2015/convert.js
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import * as asn1js from "asn1js";
|
||||
import { isBufferSource, toArrayBuffer, } from "@peculiar/utils/bytes";
|
||||
import { AsnParser } from "./parser.js";
|
||||
import { AsnSerializer } from "./serializer.js";
|
||||
export class AsnConvert {
|
||||
static serialize(obj) {
|
||||
return AsnSerializer.serialize(obj);
|
||||
}
|
||||
static parse(data, target, options) {
|
||||
return AsnParser.parse(data, target, options);
|
||||
}
|
||||
static toString(data, options) {
|
||||
const buf = isBufferSource(data)
|
||||
? toArrayBuffer(data)
|
||||
: AsnConvert.serialize(data);
|
||||
const asn = asn1js.fromBER(buf, options?.berOptions);
|
||||
if (asn.offset === -1) {
|
||||
throw new Error(`Cannot decode ASN.1 data. ${asn.result.error}`);
|
||||
}
|
||||
return asn.result.toString();
|
||||
}
|
||||
}
|
||||
139
electron/node_modules/@peculiar/asn1-schema/build/es2015/converters.js
generated
vendored
Normal file
139
electron/node_modules/@peculiar/asn1-schema/build/es2015/converters.js
generated
vendored
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
import * as asn1js from "asn1js";
|
||||
import { toArrayBuffer } from "@peculiar/utils/bytes";
|
||||
import { AsnPropTypes } from "./enums.js";
|
||||
import { OctetString } from "./types/index.js";
|
||||
export const AsnAnyConverter = {
|
||||
fromASN: (value) => value instanceof asn1js.Null
|
||||
? null
|
||||
: toArrayBuffer(value.valueBeforeDecodeView),
|
||||
toASN: (value) => {
|
||||
if (value === null) {
|
||||
return new asn1js.Null();
|
||||
}
|
||||
const schema = asn1js.fromBER(value);
|
||||
if (schema.result.error) {
|
||||
throw new Error(schema.result.error);
|
||||
}
|
||||
return schema.result;
|
||||
},
|
||||
};
|
||||
export const AsnIntegerConverter = {
|
||||
fromASN: (value) => value.valueBlock.valueHexView.byteLength >= 4
|
||||
? value.valueBlock.toString()
|
||||
: value.valueBlock.valueDec,
|
||||
toASN: (value) => new asn1js.Integer({ value: +value }),
|
||||
};
|
||||
export const AsnEnumeratedConverter = {
|
||||
fromASN: (value) => value.valueBlock.valueDec,
|
||||
toASN: (value) => new asn1js.Enumerated({ value }),
|
||||
};
|
||||
export const AsnIntegerArrayBufferConverter = {
|
||||
fromASN: (value) => toArrayBuffer(value.valueBlock.valueHexView),
|
||||
toASN: (value) => new asn1js.Integer({ valueHex: value }),
|
||||
};
|
||||
export const AsnIntegerBigIntConverter = {
|
||||
fromASN: (value) => value.toBigInt(),
|
||||
toASN: (value) => asn1js.Integer.fromBigInt(value),
|
||||
};
|
||||
export const AsnBitStringConverter = {
|
||||
fromASN: (value) => toArrayBuffer(value.valueBlock.valueHexView),
|
||||
toASN: (value) => new asn1js.BitString({ valueHex: value }),
|
||||
};
|
||||
export const AsnObjectIdentifierConverter = {
|
||||
fromASN: (value) => value.valueBlock.toString(),
|
||||
toASN: (value) => new asn1js.ObjectIdentifier({ value }),
|
||||
};
|
||||
export const AsnBooleanConverter = {
|
||||
fromASN: (value) => value.valueBlock.value,
|
||||
toASN: (value) => new asn1js.Boolean({ value }),
|
||||
};
|
||||
export const AsnOctetStringConverter = {
|
||||
fromASN: (value) => toArrayBuffer(value.valueBlock.valueHexView),
|
||||
toASN: (value) => new asn1js.OctetString({ valueHex: value }),
|
||||
};
|
||||
export const AsnConstructedOctetStringConverter = {
|
||||
fromASN: (value) => new OctetString(value.getValue()),
|
||||
toASN: (value) => value.toASN(),
|
||||
};
|
||||
function createStringConverter(Asn1Type) {
|
||||
return {
|
||||
fromASN: (value) => value.valueBlock.value,
|
||||
toASN: (value) => new Asn1Type({ value }),
|
||||
};
|
||||
}
|
||||
export const AsnUtf8StringConverter = createStringConverter(asn1js.Utf8String);
|
||||
export const AsnBmpStringConverter = createStringConverter(asn1js.BmpString);
|
||||
export const AsnUniversalStringConverter = createStringConverter(asn1js.UniversalString);
|
||||
export const AsnNumericStringConverter = createStringConverter(asn1js.NumericString);
|
||||
export const AsnPrintableStringConverter = createStringConverter(asn1js.PrintableString);
|
||||
export const AsnTeletexStringConverter = createStringConverter(asn1js.TeletexString);
|
||||
export const AsnVideotexStringConverter = createStringConverter(asn1js.VideotexString);
|
||||
export const AsnIA5StringConverter = createStringConverter(asn1js.IA5String);
|
||||
export const AsnGraphicStringConverter = createStringConverter(asn1js.GraphicString);
|
||||
export const AsnVisibleStringConverter = createStringConverter(asn1js.VisibleString);
|
||||
export const AsnGeneralStringConverter = createStringConverter(asn1js.GeneralString);
|
||||
export const AsnCharacterStringConverter = createStringConverter(asn1js.CharacterString);
|
||||
export const AsnUTCTimeConverter = {
|
||||
fromASN: (value) => value.toDate(),
|
||||
toASN: (value) => new asn1js.UTCTime({ valueDate: value }),
|
||||
};
|
||||
export const AsnGeneralizedTimeConverter = {
|
||||
fromASN: (value) => value.toDate(),
|
||||
toASN: (value) => new asn1js.GeneralizedTime({ valueDate: value }),
|
||||
};
|
||||
export const AsnNullConverter = {
|
||||
fromASN: () => null,
|
||||
toASN: () => {
|
||||
return new asn1js.Null();
|
||||
},
|
||||
};
|
||||
export function defaultConverter(type) {
|
||||
switch (type) {
|
||||
case AsnPropTypes.Any:
|
||||
return AsnAnyConverter;
|
||||
case AsnPropTypes.BitString:
|
||||
return AsnBitStringConverter;
|
||||
case AsnPropTypes.BmpString:
|
||||
return AsnBmpStringConverter;
|
||||
case AsnPropTypes.Boolean:
|
||||
return AsnBooleanConverter;
|
||||
case AsnPropTypes.CharacterString:
|
||||
return AsnCharacterStringConverter;
|
||||
case AsnPropTypes.Enumerated:
|
||||
return AsnEnumeratedConverter;
|
||||
case AsnPropTypes.GeneralString:
|
||||
return AsnGeneralStringConverter;
|
||||
case AsnPropTypes.GeneralizedTime:
|
||||
return AsnGeneralizedTimeConverter;
|
||||
case AsnPropTypes.GraphicString:
|
||||
return AsnGraphicStringConverter;
|
||||
case AsnPropTypes.IA5String:
|
||||
return AsnIA5StringConverter;
|
||||
case AsnPropTypes.Integer:
|
||||
return AsnIntegerConverter;
|
||||
case AsnPropTypes.Null:
|
||||
return AsnNullConverter;
|
||||
case AsnPropTypes.NumericString:
|
||||
return AsnNumericStringConverter;
|
||||
case AsnPropTypes.ObjectIdentifier:
|
||||
return AsnObjectIdentifierConverter;
|
||||
case AsnPropTypes.OctetString:
|
||||
return AsnOctetStringConverter;
|
||||
case AsnPropTypes.PrintableString:
|
||||
return AsnPrintableStringConverter;
|
||||
case AsnPropTypes.TeletexString:
|
||||
return AsnTeletexStringConverter;
|
||||
case AsnPropTypes.UTCTime:
|
||||
return AsnUTCTimeConverter;
|
||||
case AsnPropTypes.UniversalString:
|
||||
return AsnUniversalStringConverter;
|
||||
case AsnPropTypes.Utf8String:
|
||||
return AsnUtf8StringConverter;
|
||||
case AsnPropTypes.VideotexString:
|
||||
return AsnVideotexStringConverter;
|
||||
case AsnPropTypes.VisibleString:
|
||||
return AsnVisibleStringConverter;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
41
electron/node_modules/@peculiar/asn1-schema/build/es2015/decorators.js
generated
vendored
Normal file
41
electron/node_modules/@peculiar/asn1-schema/build/es2015/decorators.js
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import * as converters from "./converters.js";
|
||||
import { AsnTypeTypes } from "./enums.js";
|
||||
import { schemaStorage } from "./storage.js";
|
||||
export const AsnType = (options) => (target) => {
|
||||
let schema;
|
||||
if (!schemaStorage.has(target)) {
|
||||
schema = schemaStorage.createDefault(target);
|
||||
schemaStorage.set(target, schema);
|
||||
}
|
||||
else {
|
||||
schema = schemaStorage.get(target);
|
||||
}
|
||||
Object.assign(schema, options);
|
||||
};
|
||||
export const AsnChoiceType = () => AsnType({ type: AsnTypeTypes.Choice });
|
||||
export const AsnSetType = (options) => AsnType({
|
||||
type: AsnTypeTypes.Set, ...options,
|
||||
});
|
||||
export const AsnSequenceType = (options) => AsnType({
|
||||
type: AsnTypeTypes.Sequence, ...options,
|
||||
});
|
||||
export const AsnProp = (options) => (target, propertyKey) => {
|
||||
let schema;
|
||||
if (!schemaStorage.has(target.constructor)) {
|
||||
schema = schemaStorage.createDefault(target.constructor);
|
||||
schemaStorage.set(target.constructor, schema);
|
||||
}
|
||||
else {
|
||||
schema = schemaStorage.get(target.constructor);
|
||||
}
|
||||
const copyOptions = Object.assign({}, options);
|
||||
if (typeof copyOptions.type === "number" && !copyOptions.converter) {
|
||||
const defaultConverter = converters.defaultConverter(options.type);
|
||||
if (!defaultConverter) {
|
||||
throw new Error(`Cannot get default converter for property '${propertyKey}' of ${target.constructor.name}`);
|
||||
}
|
||||
copyOptions.converter = defaultConverter;
|
||||
}
|
||||
copyOptions.raw = options.raw;
|
||||
schema.items[propertyKey] = copyOptions;
|
||||
};
|
||||
36
electron/node_modules/@peculiar/asn1-schema/build/es2015/enums.js
generated
vendored
Normal file
36
electron/node_modules/@peculiar/asn1-schema/build/es2015/enums.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
export var AsnTypeTypes;
|
||||
(function (AsnTypeTypes) {
|
||||
AsnTypeTypes[AsnTypeTypes["Sequence"] = 0] = "Sequence";
|
||||
AsnTypeTypes[AsnTypeTypes["Set"] = 1] = "Set";
|
||||
AsnTypeTypes[AsnTypeTypes["Choice"] = 2] = "Choice";
|
||||
})(AsnTypeTypes || (AsnTypeTypes = {}));
|
||||
export var AsnPropTypes;
|
||||
(function (AsnPropTypes) {
|
||||
AsnPropTypes[AsnPropTypes["Any"] = 1] = "Any";
|
||||
AsnPropTypes[AsnPropTypes["Boolean"] = 2] = "Boolean";
|
||||
AsnPropTypes[AsnPropTypes["OctetString"] = 3] = "OctetString";
|
||||
AsnPropTypes[AsnPropTypes["BitString"] = 4] = "BitString";
|
||||
AsnPropTypes[AsnPropTypes["Integer"] = 5] = "Integer";
|
||||
AsnPropTypes[AsnPropTypes["Enumerated"] = 6] = "Enumerated";
|
||||
AsnPropTypes[AsnPropTypes["ObjectIdentifier"] = 7] = "ObjectIdentifier";
|
||||
AsnPropTypes[AsnPropTypes["Utf8String"] = 8] = "Utf8String";
|
||||
AsnPropTypes[AsnPropTypes["BmpString"] = 9] = "BmpString";
|
||||
AsnPropTypes[AsnPropTypes["UniversalString"] = 10] = "UniversalString";
|
||||
AsnPropTypes[AsnPropTypes["NumericString"] = 11] = "NumericString";
|
||||
AsnPropTypes[AsnPropTypes["PrintableString"] = 12] = "PrintableString";
|
||||
AsnPropTypes[AsnPropTypes["TeletexString"] = 13] = "TeletexString";
|
||||
AsnPropTypes[AsnPropTypes["VideotexString"] = 14] = "VideotexString";
|
||||
AsnPropTypes[AsnPropTypes["IA5String"] = 15] = "IA5String";
|
||||
AsnPropTypes[AsnPropTypes["GraphicString"] = 16] = "GraphicString";
|
||||
AsnPropTypes[AsnPropTypes["VisibleString"] = 17] = "VisibleString";
|
||||
AsnPropTypes[AsnPropTypes["GeneralString"] = 18] = "GeneralString";
|
||||
AsnPropTypes[AsnPropTypes["CharacterString"] = 19] = "CharacterString";
|
||||
AsnPropTypes[AsnPropTypes["UTCTime"] = 20] = "UTCTime";
|
||||
AsnPropTypes[AsnPropTypes["GeneralizedTime"] = 21] = "GeneralizedTime";
|
||||
AsnPropTypes[AsnPropTypes["DATE"] = 22] = "DATE";
|
||||
AsnPropTypes[AsnPropTypes["TimeOfDay"] = 23] = "TimeOfDay";
|
||||
AsnPropTypes[AsnPropTypes["DateTime"] = 24] = "DateTime";
|
||||
AsnPropTypes[AsnPropTypes["Duration"] = 25] = "Duration";
|
||||
AsnPropTypes[AsnPropTypes["TIME"] = 26] = "TIME";
|
||||
AsnPropTypes[AsnPropTypes["Null"] = 27] = "Null";
|
||||
})(AsnPropTypes || (AsnPropTypes = {}));
|
||||
1
electron/node_modules/@peculiar/asn1-schema/build/es2015/errors/index.js
generated
vendored
Normal file
1
electron/node_modules/@peculiar/asn1-schema/build/es2015/errors/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./schema_validation.js";
|
||||
3
electron/node_modules/@peculiar/asn1-schema/build/es2015/errors/schema_validation.js
generated
vendored
Normal file
3
electron/node_modules/@peculiar/asn1-schema/build/es2015/errors/schema_validation.js
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export class AsnSchemaValidationError extends Error {
|
||||
schemas = [];
|
||||
}
|
||||
39
electron/node_modules/@peculiar/asn1-schema/build/es2015/helper.js
generated
vendored
Normal file
39
electron/node_modules/@peculiar/asn1-schema/build/es2015/helper.js
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
export function isConvertible(target) {
|
||||
if (typeof target === "function" && target.prototype) {
|
||||
if (target.prototype.toASN && target.prototype.fromASN) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return isConvertible(target.prototype);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return !!(target && typeof target === "object" && "toASN" in target && "fromASN" in target);
|
||||
}
|
||||
}
|
||||
export function isTypeOfArray(target) {
|
||||
if (target) {
|
||||
const proto = Object.getPrototypeOf(target);
|
||||
if (proto?.prototype?.constructor === Array) {
|
||||
return true;
|
||||
}
|
||||
return isTypeOfArray(proto);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isArrayEqual(bytes1, bytes2) {
|
||||
if (!(bytes1 && bytes2)) {
|
||||
return false;
|
||||
}
|
||||
if (bytes1.byteLength !== bytes2.byteLength) {
|
||||
return false;
|
||||
}
|
||||
const b1 = new Uint8Array(bytes1);
|
||||
const b2 = new Uint8Array(bytes2);
|
||||
for (let i = 0; i < bytes1.byteLength; i++) {
|
||||
if (b1[i] !== b2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
9
electron/node_modules/@peculiar/asn1-schema/build/es2015/index.js
generated
vendored
Normal file
9
electron/node_modules/@peculiar/asn1-schema/build/es2015/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
export * from "./converters.js";
|
||||
export * from "./types/index.js";
|
||||
export { AsnProp, AsnType, AsnChoiceType, AsnSequenceType, AsnSetType, } from "./decorators.js";
|
||||
export { AsnTypeTypes, AsnPropTypes } from "./enums.js";
|
||||
export { AsnParser } from "./parser.js";
|
||||
export { AsnSerializer } from "./serializer.js";
|
||||
export * from "./errors/index.js";
|
||||
export * from "./objects.js";
|
||||
export * from "./convert.js";
|
||||
13
electron/node_modules/@peculiar/asn1-schema/build/es2015/objects.js
generated
vendored
Normal file
13
electron/node_modules/@peculiar/asn1-schema/build/es2015/objects.js
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export class AsnArray extends Array {
|
||||
constructor(items = []) {
|
||||
if (typeof items === "number") {
|
||||
super(items);
|
||||
}
|
||||
else {
|
||||
super();
|
||||
for (const item of items) {
|
||||
this.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
electron/node_modules/@peculiar/asn1-schema/build/es2015/package.json
generated
vendored
Normal file
3
electron/node_modules/@peculiar/asn1-schema/build/es2015/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"type": "module"
|
||||
}
|
||||
326
electron/node_modules/@peculiar/asn1-schema/build/es2015/parser.js
generated
vendored
Normal file
326
electron/node_modules/@peculiar/asn1-schema/build/es2015/parser.js
generated
vendored
Normal file
|
|
@ -0,0 +1,326 @@
|
|||
import * as asn1js from "asn1js";
|
||||
import { toArrayBuffer } from "@peculiar/utils/bytes";
|
||||
import { AsnPropTypes, AsnTypeTypes } from "./enums.js";
|
||||
import * as converters from "./converters.js";
|
||||
import { AsnSchemaValidationError } from "./errors/index.js";
|
||||
import { isConvertible, isTypeOfArray } from "./helper.js";
|
||||
import { schemaStorage } from "./storage.js";
|
||||
export class AsnParser {
|
||||
static parse(data, target, options) {
|
||||
const asn1Parsed = asn1js.fromBER(toArrayBuffer(data), options?.berOptions);
|
||||
if (asn1Parsed.result.error) {
|
||||
throw new Error(asn1Parsed.result.error);
|
||||
}
|
||||
const res = this.fromASN(asn1Parsed.result, target, options);
|
||||
return res;
|
||||
}
|
||||
static fromASN(asn1Schema, target, options) {
|
||||
try {
|
||||
if (isConvertible(target)) {
|
||||
const value = new target();
|
||||
return value.fromASN(asn1Schema);
|
||||
}
|
||||
const schema = schemaStorage.get(target);
|
||||
schemaStorage.cache(target);
|
||||
let targetSchema = schema.schema;
|
||||
const choiceResult = this.handleChoiceTypes(asn1Schema, schema, target, targetSchema, options);
|
||||
if (choiceResult?.result) {
|
||||
return choiceResult.result;
|
||||
}
|
||||
if (choiceResult?.targetSchema) {
|
||||
targetSchema = choiceResult.targetSchema;
|
||||
}
|
||||
const sequenceResult = this.handleSequenceTypes(asn1Schema, schema, target, targetSchema);
|
||||
const res = new target();
|
||||
if (isTypeOfArray(target)) {
|
||||
return this.handleArrayTypes(asn1Schema, schema, target, options);
|
||||
}
|
||||
this.processSchemaItems(schema, sequenceResult, res, options);
|
||||
return res;
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof AsnSchemaValidationError) {
|
||||
error.schemas.push(target.name);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
static handleChoiceTypes(asn1Schema, schema, target, targetSchema, options) {
|
||||
if (asn1Schema.constructor === asn1js.Constructed
|
||||
&& schema.type === AsnTypeTypes.Choice
|
||||
&& asn1Schema.idBlock.tagClass === 3) {
|
||||
for (const key in schema.items) {
|
||||
const schemaItem = schema.items[key];
|
||||
if (schemaItem.context === asn1Schema.idBlock.tagNumber && schemaItem.implicit) {
|
||||
if (typeof schemaItem.type === "function"
|
||||
&& schemaStorage.has(schemaItem.type)) {
|
||||
const fieldSchema = schemaStorage.get(schemaItem.type);
|
||||
if (fieldSchema && fieldSchema.type === AsnTypeTypes.Sequence) {
|
||||
const newSeq = new asn1js.Sequence();
|
||||
if ("value" in asn1Schema.valueBlock
|
||||
&& Array.isArray(asn1Schema.valueBlock.value)
|
||||
&& "value" in newSeq.valueBlock) {
|
||||
newSeq.valueBlock.value = asn1Schema.valueBlock.value;
|
||||
const fieldValue = this.fromASN(newSeq, schemaItem.type, options);
|
||||
const res = new target();
|
||||
res[key] = fieldValue;
|
||||
return { result: res };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (asn1Schema.constructor === asn1js.Constructed
|
||||
&& schema.type !== AsnTypeTypes.Choice) {
|
||||
const newTargetSchema = new asn1js.Constructed({
|
||||
idBlock: {
|
||||
tagClass: 3,
|
||||
tagNumber: asn1Schema.idBlock.tagNumber,
|
||||
},
|
||||
value: schema.schema.valueBlock.value,
|
||||
});
|
||||
for (const key in schema.items) {
|
||||
delete asn1Schema[key];
|
||||
}
|
||||
return { targetSchema: newTargetSchema };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static handleSequenceTypes(asn1Schema, schema, target, targetSchema) {
|
||||
if (schema.type === AsnTypeTypes.Sequence) {
|
||||
const asn1ComparedSchema = asn1js.compareSchema({}, asn1Schema, targetSchema);
|
||||
if (!asn1ComparedSchema.verified) {
|
||||
throw new AsnSchemaValidationError(`Data does not match to ${target.name} ASN1 schema.${asn1ComparedSchema.result.error ? ` ${asn1ComparedSchema.result.error}` : ""}`);
|
||||
}
|
||||
return asn1ComparedSchema;
|
||||
}
|
||||
else {
|
||||
const asn1ComparedSchema = asn1js.compareSchema({}, asn1Schema, targetSchema);
|
||||
if (!asn1ComparedSchema.verified) {
|
||||
throw new AsnSchemaValidationError(`Data does not match to ${target.name} ASN1 schema.${asn1ComparedSchema.result.error ? ` ${asn1ComparedSchema.result.error}` : ""}`);
|
||||
}
|
||||
return asn1ComparedSchema;
|
||||
}
|
||||
}
|
||||
static processRepeatedField(asn1Elements, asn1Index, schemaItem) {
|
||||
let elementsToProcess = asn1Elements.slice(asn1Index);
|
||||
if (elementsToProcess.length === 1 && elementsToProcess[0].constructor.name === "Sequence") {
|
||||
const seq = elementsToProcess[0];
|
||||
if (seq.valueBlock && seq.valueBlock.value && Array.isArray(seq.valueBlock.value)) {
|
||||
elementsToProcess = seq.valueBlock.value;
|
||||
}
|
||||
}
|
||||
if (typeof schemaItem.type === "number") {
|
||||
const converter = converters.defaultConverter(schemaItem.type);
|
||||
if (!converter)
|
||||
throw new Error(`No converter for ASN.1 type ${schemaItem.type}`);
|
||||
return elementsToProcess
|
||||
.filter((el) => el && el.valueBlock)
|
||||
.map((el) => {
|
||||
try {
|
||||
return converter.fromASN(el);
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
})
|
||||
.filter((v) => v !== undefined);
|
||||
}
|
||||
else {
|
||||
return elementsToProcess
|
||||
.filter((el) => el && el.valueBlock)
|
||||
.map((el) => {
|
||||
try {
|
||||
return this.fromASN(el, schemaItem.type);
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
})
|
||||
.filter((v) => v !== undefined);
|
||||
}
|
||||
}
|
||||
static processPrimitiveField(asn1Element, schemaItem) {
|
||||
const converter = converters.defaultConverter(schemaItem.type);
|
||||
if (!converter)
|
||||
throw new Error(`No converter for ASN.1 type ${schemaItem.type}`);
|
||||
return converter.fromASN(asn1Element);
|
||||
}
|
||||
static isOptionalChoiceField(schemaItem) {
|
||||
return (schemaItem.optional
|
||||
&& typeof schemaItem.type === "function"
|
||||
&& schemaStorage.has(schemaItem.type)
|
||||
&& schemaStorage.get(schemaItem.type).type === AsnTypeTypes.Choice);
|
||||
}
|
||||
static processOptionalChoiceField(asn1Element, schemaItem) {
|
||||
try {
|
||||
const value = this.fromASN(asn1Element, schemaItem.type);
|
||||
return {
|
||||
processed: true, value,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
if (err instanceof AsnSchemaValidationError
|
||||
&& /Wrong values for Choice type/.test(err.message)) {
|
||||
return { processed: false };
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
static handleArrayTypes(asn1Schema, schema, target, options) {
|
||||
if (!("value" in asn1Schema.valueBlock && Array.isArray(asn1Schema.valueBlock.value))) {
|
||||
throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");
|
||||
}
|
||||
const itemType = schema.itemType;
|
||||
if (typeof itemType === "number") {
|
||||
const converter = converters.defaultConverter(itemType);
|
||||
if (!converter) {
|
||||
throw new Error(`Cannot get default converter for array item of ${target.name} ASN1 schema`);
|
||||
}
|
||||
return target.from(asn1Schema.valueBlock.value, (element) => converter.fromASN(element));
|
||||
}
|
||||
else {
|
||||
return target.from(asn1Schema.valueBlock.value, (element) => this.fromASN(element, itemType, options));
|
||||
}
|
||||
}
|
||||
static processSchemaItems(schema, asn1ComparedSchema, res, options) {
|
||||
for (const key in schema.items) {
|
||||
const asn1SchemaValue = asn1ComparedSchema.result[key];
|
||||
if (!asn1SchemaValue) {
|
||||
continue;
|
||||
}
|
||||
const schemaItem = schema.items[key];
|
||||
const schemaItemType = schemaItem.type;
|
||||
let parsedValue;
|
||||
if (typeof schemaItemType === "number" || isConvertible(schemaItemType)) {
|
||||
parsedValue = this.processPrimitiveSchemaItem(asn1SchemaValue, schemaItem, schemaItemType, options);
|
||||
}
|
||||
else {
|
||||
parsedValue = this.processComplexSchemaItem(asn1SchemaValue, schemaItem, schemaItemType, options);
|
||||
}
|
||||
if (parsedValue
|
||||
&& typeof parsedValue === "object"
|
||||
&& "value" in parsedValue
|
||||
&& "raw" in parsedValue) {
|
||||
res[key] = parsedValue.value;
|
||||
res[`${key}Raw`] = parsedValue.raw;
|
||||
}
|
||||
else {
|
||||
res[key] = parsedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
static processPrimitiveSchemaItem(asn1SchemaValue, schemaItem, schemaItemType, options) {
|
||||
const converter = schemaItem.converter
|
||||
?? (isConvertible(schemaItemType)
|
||||
? new schemaItemType()
|
||||
: null);
|
||||
if (!converter) {
|
||||
throw new Error("Converter is empty");
|
||||
}
|
||||
if (schemaItem.repeated) {
|
||||
return this.processRepeatedPrimitiveItem(asn1SchemaValue, schemaItem, converter, options);
|
||||
}
|
||||
else {
|
||||
return this.processSinglePrimitiveItem(asn1SchemaValue, schemaItem, schemaItemType, converter, options);
|
||||
}
|
||||
}
|
||||
static processRepeatedPrimitiveItem(asn1SchemaValue, schemaItem, converter, options) {
|
||||
if (schemaItem.implicit) {
|
||||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set;
|
||||
const newItem = new Container();
|
||||
newItem.valueBlock = asn1SchemaValue.valueBlock;
|
||||
const newItemAsn = asn1js.fromBER(newItem.toBER(false), options?.berOptions);
|
||||
if (newItemAsn.offset === -1) {
|
||||
throw new Error(`Cannot parse the child item. ${newItemAsn.result.error}`);
|
||||
}
|
||||
if (!("value" in newItemAsn.result.valueBlock
|
||||
&& Array.isArray(newItemAsn.result.valueBlock.value))) {
|
||||
throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");
|
||||
}
|
||||
const value = newItemAsn.result.valueBlock.value;
|
||||
return Array.from(value, (element) => converter.fromASN(element));
|
||||
}
|
||||
else {
|
||||
return Array.from(asn1SchemaValue, (element) => converter.fromASN(element));
|
||||
}
|
||||
}
|
||||
static processSinglePrimitiveItem(asn1SchemaValue, schemaItem, schemaItemType, converter, options) {
|
||||
let value = asn1SchemaValue;
|
||||
if (schemaItem.implicit) {
|
||||
let newItem;
|
||||
if (isConvertible(schemaItemType)) {
|
||||
newItem = new schemaItemType().toSchema("");
|
||||
}
|
||||
else {
|
||||
const Asn1TypeName = AsnPropTypes[schemaItemType];
|
||||
const Asn1Type = asn1js[Asn1TypeName];
|
||||
if (!Asn1Type) {
|
||||
throw new Error(`Cannot get '${Asn1TypeName}' class from asn1js module`);
|
||||
}
|
||||
newItem = new Asn1Type();
|
||||
}
|
||||
newItem.valueBlock = value.valueBlock;
|
||||
value = asn1js.fromBER(newItem.toBER(false), options?.berOptions).result;
|
||||
}
|
||||
return converter.fromASN(value);
|
||||
}
|
||||
static processComplexSchemaItem(asn1SchemaValue, schemaItem, schemaItemType, options) {
|
||||
if (schemaItem.repeated) {
|
||||
if (!Array.isArray(asn1SchemaValue)) {
|
||||
throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");
|
||||
}
|
||||
return Array.from(asn1SchemaValue, (element) => this.fromASN(element, schemaItemType, options));
|
||||
}
|
||||
else {
|
||||
const valueToProcess = this.handleImplicitTagging(asn1SchemaValue, schemaItem, schemaItemType);
|
||||
if (this.isOptionalChoiceField(schemaItem)) {
|
||||
try {
|
||||
return this.fromASN(valueToProcess, schemaItemType, options);
|
||||
}
|
||||
catch (err) {
|
||||
if (err instanceof AsnSchemaValidationError
|
||||
&& /Wrong values for Choice type/.test(err.message)) {
|
||||
return undefined;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const parsedValue = this.fromASN(valueToProcess, schemaItemType, options);
|
||||
if (schemaItem.raw) {
|
||||
return {
|
||||
value: parsedValue,
|
||||
raw: asn1SchemaValue.valueBeforeDecodeView,
|
||||
};
|
||||
}
|
||||
return parsedValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
static handleImplicitTagging(asn1SchemaValue, schemaItem, schemaItemType) {
|
||||
if (schemaItem.implicit && typeof schemaItem.context === "number") {
|
||||
const schema = schemaStorage.get(schemaItemType);
|
||||
if (schema.type === AsnTypeTypes.Sequence) {
|
||||
const newSeq = new asn1js.Sequence();
|
||||
if ("value" in asn1SchemaValue.valueBlock
|
||||
&& Array.isArray(asn1SchemaValue.valueBlock.value)
|
||||
&& "value" in newSeq.valueBlock) {
|
||||
newSeq.valueBlock.value = asn1SchemaValue.valueBlock.value;
|
||||
return newSeq;
|
||||
}
|
||||
}
|
||||
else if (schema.type === AsnTypeTypes.Set) {
|
||||
const newSet = new asn1js.Set();
|
||||
if ("value" in asn1SchemaValue.valueBlock
|
||||
&& Array.isArray(asn1SchemaValue.valueBlock.value)
|
||||
&& "value" in newSet.valueBlock) {
|
||||
newSet.valueBlock.value = asn1SchemaValue.valueBlock.value;
|
||||
return newSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return asn1SchemaValue;
|
||||
}
|
||||
}
|
||||
151
electron/node_modules/@peculiar/asn1-schema/build/es2015/schema.js
generated
vendored
Normal file
151
electron/node_modules/@peculiar/asn1-schema/build/es2015/schema.js
generated
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
import * as asn1js from "asn1js";
|
||||
import { AsnPropTypes, AsnTypeTypes } from "./enums.js";
|
||||
import { isConvertible } from "./helper.js";
|
||||
export class AsnSchemaStorage {
|
||||
items = new WeakMap();
|
||||
has(target) {
|
||||
return this.items.has(target);
|
||||
}
|
||||
get(target, checkSchema = false) {
|
||||
const schema = this.items.get(target);
|
||||
if (!schema) {
|
||||
throw new Error(`Cannot get schema for '${target.prototype.constructor.name}' target`);
|
||||
}
|
||||
if (checkSchema && !schema.schema) {
|
||||
throw new Error(`Schema '${target.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
cache(target) {
|
||||
const schema = this.get(target);
|
||||
if (!schema.schema) {
|
||||
schema.schema = this.create(target, true);
|
||||
}
|
||||
}
|
||||
createDefault(target) {
|
||||
const schema = {
|
||||
type: AsnTypeTypes.Sequence, items: {},
|
||||
};
|
||||
const parentSchema = this.findParentSchema(target);
|
||||
if (parentSchema) {
|
||||
Object.assign(schema, parentSchema);
|
||||
schema.items = Object.assign({}, schema.items, parentSchema.items);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
create(target, useNames) {
|
||||
const schema = this.items.get(target) || this.createDefault(target);
|
||||
const asn1Value = [];
|
||||
for (const key in schema.items) {
|
||||
const item = schema.items[key];
|
||||
const name = useNames ? key : "";
|
||||
let asn1Item;
|
||||
if (typeof item.type === "number") {
|
||||
const Asn1TypeName = AsnPropTypes[item.type];
|
||||
const Asn1Type = asn1js[Asn1TypeName];
|
||||
if (!Asn1Type) {
|
||||
throw new Error(`Cannot get ASN1 class by name '${Asn1TypeName}'`);
|
||||
}
|
||||
asn1Item = new Asn1Type({ name });
|
||||
}
|
||||
else if (isConvertible(item.type)) {
|
||||
const instance = new item.type();
|
||||
asn1Item = instance.toSchema(name);
|
||||
}
|
||||
else if (item.optional) {
|
||||
const itemSchema = this.get(item.type);
|
||||
if (itemSchema.type === AsnTypeTypes.Choice) {
|
||||
asn1Item = new asn1js.Any({ name });
|
||||
}
|
||||
else {
|
||||
asn1Item = this.create(item.type, false);
|
||||
asn1Item.name = name;
|
||||
}
|
||||
}
|
||||
else {
|
||||
asn1Item = new asn1js.Any({ name });
|
||||
}
|
||||
const optional = !!item.optional || item.defaultValue !== undefined;
|
||||
if (item.repeated) {
|
||||
asn1Item.name = "";
|
||||
const Container = item.repeated === "set" ? asn1js.Set : asn1js.Sequence;
|
||||
asn1Item = new Container({
|
||||
name: "",
|
||||
value: [new asn1js.Repeated({
|
||||
name, value: asn1Item,
|
||||
})],
|
||||
});
|
||||
}
|
||||
if (item.context !== null && item.context !== undefined) {
|
||||
if (item.implicit) {
|
||||
if (typeof item.type === "number" || isConvertible(item.type)) {
|
||||
const Container = item.repeated ? asn1js.Constructed : asn1js.Primitive;
|
||||
asn1Value.push(new Container({
|
||||
name, optional, idBlock: {
|
||||
tagClass: 3, tagNumber: item.context,
|
||||
},
|
||||
}));
|
||||
}
|
||||
else {
|
||||
this.cache(item.type);
|
||||
const isRepeated = !!item.repeated;
|
||||
let value = !isRepeated ? this.get(item.type, true).schema : asn1Item;
|
||||
value
|
||||
= "valueBlock" in value
|
||||
? value.valueBlock.value
|
||||
: value.value;
|
||||
asn1Value.push(new asn1js.Constructed({
|
||||
name: !isRepeated ? name : "",
|
||||
optional,
|
||||
idBlock: {
|
||||
tagClass: 3, tagNumber: item.context,
|
||||
},
|
||||
value: value,
|
||||
}));
|
||||
}
|
||||
}
|
||||
else {
|
||||
asn1Value.push(new asn1js.Constructed({
|
||||
optional,
|
||||
idBlock: {
|
||||
tagClass: 3, tagNumber: item.context,
|
||||
},
|
||||
value: [asn1Item],
|
||||
}));
|
||||
}
|
||||
}
|
||||
else {
|
||||
asn1Item.optional = optional;
|
||||
asn1Value.push(asn1Item);
|
||||
}
|
||||
}
|
||||
switch (schema.type) {
|
||||
case AsnTypeTypes.Sequence:
|
||||
return new asn1js.Sequence({
|
||||
value: asn1Value, name: "",
|
||||
});
|
||||
case AsnTypeTypes.Set:
|
||||
return new asn1js.Set({
|
||||
value: asn1Value, name: "",
|
||||
});
|
||||
case AsnTypeTypes.Choice:
|
||||
return new asn1js.Choice({
|
||||
value: asn1Value, name: "",
|
||||
});
|
||||
default:
|
||||
throw new Error("Unsupported ASN1 type in use");
|
||||
}
|
||||
}
|
||||
set(target, schema) {
|
||||
this.items.set(target, schema);
|
||||
return this;
|
||||
}
|
||||
findParentSchema(target) {
|
||||
const parent = Object.getPrototypeOf(target);
|
||||
if (parent) {
|
||||
const schema = this.items.get(parent);
|
||||
return schema || this.findParentSchema(parent);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
151
electron/node_modules/@peculiar/asn1-schema/build/es2015/serializer.js
generated
vendored
Normal file
151
electron/node_modules/@peculiar/asn1-schema/build/es2015/serializer.js
generated
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
import * as asn1js from "asn1js";
|
||||
import { toArrayBuffer } from "@peculiar/utils/bytes";
|
||||
import * as converters from "./converters.js";
|
||||
import { AsnPropTypes, AsnTypeTypes } from "./enums.js";
|
||||
import { isConvertible, isArrayEqual } from "./helper.js";
|
||||
import { schemaStorage } from "./storage.js";
|
||||
export class AsnSerializer {
|
||||
static serialize(obj) {
|
||||
if (obj instanceof asn1js.BaseBlock) {
|
||||
return obj.toBER(false);
|
||||
}
|
||||
return this.toASN(obj).toBER(false);
|
||||
}
|
||||
static toASN(obj) {
|
||||
if (obj && typeof obj === "object" && isConvertible(obj)) {
|
||||
return obj.toASN();
|
||||
}
|
||||
if (!(obj && typeof obj === "object")) {
|
||||
throw new TypeError("Parameter 1 should be type of Object.");
|
||||
}
|
||||
const target = obj.constructor;
|
||||
const schema = schemaStorage.get(target);
|
||||
schemaStorage.cache(target);
|
||||
let asn1Value = [];
|
||||
if (schema.itemType) {
|
||||
if (!Array.isArray(obj)) {
|
||||
throw new TypeError("Parameter 1 should be type of Array.");
|
||||
}
|
||||
if (typeof schema.itemType === "number") {
|
||||
const converter = converters.defaultConverter(schema.itemType);
|
||||
if (!converter) {
|
||||
throw new Error(`Cannot get default converter for array item of ${target.name} ASN1 schema`);
|
||||
}
|
||||
asn1Value = obj.map((o) => converter.toASN(o));
|
||||
}
|
||||
else {
|
||||
asn1Value = obj.map((o) => this.toAsnItem({ type: schema.itemType }, "[]", target, o));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const key in schema.items) {
|
||||
const schemaItem = schema.items[key];
|
||||
const objProp = obj[key];
|
||||
if (objProp === undefined
|
||||
|| schemaItem.defaultValue === objProp
|
||||
|| (typeof schemaItem.defaultValue === "object"
|
||||
&& typeof objProp === "object"
|
||||
&& isArrayEqual(this.serialize(schemaItem.defaultValue), this.serialize(objProp)))) {
|
||||
continue;
|
||||
}
|
||||
const asn1Item = AsnSerializer.toAsnItem(schemaItem, key, target, objProp);
|
||||
if (typeof schemaItem.context === "number") {
|
||||
if (schemaItem.implicit) {
|
||||
if (!schemaItem.repeated
|
||||
&& (typeof schemaItem.type === "number" || isConvertible(schemaItem.type))) {
|
||||
const value = {};
|
||||
value.valueHex
|
||||
= asn1Item instanceof asn1js.Null
|
||||
? toArrayBuffer(asn1Item.valueBeforeDecodeView)
|
||||
: asn1Item.valueBlock.toBER();
|
||||
asn1Value.push(new asn1js.Primitive({
|
||||
optional: schemaItem.optional,
|
||||
idBlock: {
|
||||
tagClass: 3,
|
||||
tagNumber: schemaItem.context,
|
||||
},
|
||||
...value,
|
||||
}));
|
||||
}
|
||||
else {
|
||||
asn1Value.push(new asn1js.Constructed({
|
||||
optional: schemaItem.optional,
|
||||
idBlock: {
|
||||
tagClass: 3,
|
||||
tagNumber: schemaItem.context,
|
||||
},
|
||||
value: asn1Item.valueBlock.value,
|
||||
}));
|
||||
}
|
||||
}
|
||||
else {
|
||||
asn1Value.push(new asn1js.Constructed({
|
||||
optional: schemaItem.optional,
|
||||
idBlock: {
|
||||
tagClass: 3,
|
||||
tagNumber: schemaItem.context,
|
||||
},
|
||||
value: [asn1Item],
|
||||
}));
|
||||
}
|
||||
}
|
||||
else if (schemaItem.repeated) {
|
||||
asn1Value = asn1Value.concat(asn1Item);
|
||||
}
|
||||
else {
|
||||
asn1Value.push(asn1Item);
|
||||
}
|
||||
}
|
||||
}
|
||||
let asnSchema;
|
||||
switch (schema.type) {
|
||||
case AsnTypeTypes.Sequence:
|
||||
asnSchema = new asn1js.Sequence({ value: asn1Value });
|
||||
break;
|
||||
case AsnTypeTypes.Set:
|
||||
asnSchema = new asn1js.Set({ value: asn1Value });
|
||||
break;
|
||||
case AsnTypeTypes.Choice:
|
||||
if (!asn1Value[0]) {
|
||||
throw new Error(`Schema '${target.name}' has wrong data. Choice cannot be empty.`);
|
||||
}
|
||||
asnSchema = asn1Value[0];
|
||||
break;
|
||||
}
|
||||
return asnSchema;
|
||||
}
|
||||
static toAsnItem(schemaItem, key, target, objProp) {
|
||||
let asn1Item;
|
||||
if (typeof schemaItem.type === "number") {
|
||||
const converter = schemaItem.converter;
|
||||
if (!converter) {
|
||||
throw new Error(`Property '${key}' doesn't have converter for type ${AsnPropTypes[schemaItem.type]} in schema '${target.name}'`);
|
||||
}
|
||||
if (schemaItem.repeated) {
|
||||
if (!Array.isArray(objProp)) {
|
||||
throw new TypeError("Parameter 'objProp' should be type of Array.");
|
||||
}
|
||||
const items = Array.from(objProp, (element) => converter.toASN(element));
|
||||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set;
|
||||
asn1Item = new Container({ value: items });
|
||||
}
|
||||
else {
|
||||
asn1Item = converter.toASN(objProp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (schemaItem.repeated) {
|
||||
if (!Array.isArray(objProp)) {
|
||||
throw new TypeError("Parameter 'objProp' should be type of Array.");
|
||||
}
|
||||
const items = Array.from(objProp, (element) => this.toASN(element));
|
||||
const Container = schemaItem.repeated === "sequence" ? asn1js.Sequence : asn1js.Set;
|
||||
asn1Item = new Container({ value: items });
|
||||
}
|
||||
else {
|
||||
asn1Item = this.toASN(objProp);
|
||||
}
|
||||
}
|
||||
return asn1Item;
|
||||
}
|
||||
}
|
||||
2
electron/node_modules/@peculiar/asn1-schema/build/es2015/storage.js
generated
vendored
Normal file
2
electron/node_modules/@peculiar/asn1-schema/build/es2015/storage.js
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import { AsnSchemaStorage } from "./schema.js";
|
||||
export const schemaStorage = new AsnSchemaStorage();
|
||||
1
electron/node_modules/@peculiar/asn1-schema/build/es2015/types.js
generated
vendored
Normal file
1
electron/node_modules/@peculiar/asn1-schema/build/es2015/types.js
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export {};
|
||||
65
electron/node_modules/@peculiar/asn1-schema/build/es2015/types/bit_string.js
generated
vendored
Normal file
65
electron/node_modules/@peculiar/asn1-schema/build/es2015/types/bit_string.js
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import * as asn1js from "asn1js";
|
||||
import { isBufferSource, toArrayBuffer, } from "@peculiar/utils/bytes";
|
||||
export class BitString {
|
||||
unusedBits = 0;
|
||||
value = new ArrayBuffer(0);
|
||||
constructor(params, unusedBits = 0) {
|
||||
if (params) {
|
||||
if (typeof params === "number") {
|
||||
this.fromNumber(params);
|
||||
}
|
||||
else if (isBufferSource(params)) {
|
||||
this.unusedBits = unusedBits;
|
||||
this.value = toArrayBuffer(params);
|
||||
}
|
||||
else {
|
||||
throw TypeError("Unsupported type of 'params' argument for BitString");
|
||||
}
|
||||
}
|
||||
}
|
||||
fromASN(asn) {
|
||||
if (!(asn instanceof asn1js.BitString)) {
|
||||
throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");
|
||||
}
|
||||
this.unusedBits = asn.valueBlock.unusedBits;
|
||||
this.value = toArrayBuffer(asn.valueBlock.valueHex);
|
||||
return this;
|
||||
}
|
||||
toASN() {
|
||||
return new asn1js.BitString({
|
||||
unusedBits: this.unusedBits, valueHex: this.value,
|
||||
});
|
||||
}
|
||||
toSchema(name) {
|
||||
return new asn1js.BitString({ name });
|
||||
}
|
||||
toNumber() {
|
||||
let res = "";
|
||||
const uintArray = new Uint8Array(this.value);
|
||||
for (const octet of uintArray) {
|
||||
res += octet.toString(2).padStart(8, "0");
|
||||
}
|
||||
res = res.split("").reverse().join("");
|
||||
if (this.unusedBits) {
|
||||
res = res.slice(this.unusedBits).padStart(this.unusedBits, "0");
|
||||
}
|
||||
return parseInt(res, 2);
|
||||
}
|
||||
fromNumber(value) {
|
||||
let bits = value.toString(2);
|
||||
const octetSize = (bits.length + 7) >> 3;
|
||||
this.unusedBits = (octetSize << 3) - bits.length;
|
||||
const octets = new Uint8Array(octetSize);
|
||||
bits = bits
|
||||
.padStart(octetSize << 3, "0")
|
||||
.split("")
|
||||
.reverse()
|
||||
.join("");
|
||||
let index = 0;
|
||||
while (index < octetSize) {
|
||||
octets[index] = parseInt(bits.slice(index << 3, (index << 3) + 8), 2);
|
||||
index++;
|
||||
}
|
||||
this.value = octets.buffer;
|
||||
}
|
||||
}
|
||||
2
electron/node_modules/@peculiar/asn1-schema/build/es2015/types/index.js
generated
vendored
Normal file
2
electron/node_modules/@peculiar/asn1-schema/build/es2015/types/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./bit_string.js";
|
||||
export * from "./octet_string.js";
|
||||
40
electron/node_modules/@peculiar/asn1-schema/build/es2015/types/octet_string.js
generated
vendored
Normal file
40
electron/node_modules/@peculiar/asn1-schema/build/es2015/types/octet_string.js
generated
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import * as asn1js from "asn1js";
|
||||
import { isBufferSource, toArrayBuffer, } from "@peculiar/utils/bytes";
|
||||
export class OctetString {
|
||||
buffer;
|
||||
get byteLength() {
|
||||
return this.buffer.byteLength;
|
||||
}
|
||||
get byteOffset() {
|
||||
return 0;
|
||||
}
|
||||
constructor(param) {
|
||||
if (typeof param === "number") {
|
||||
this.buffer = new ArrayBuffer(param);
|
||||
}
|
||||
else {
|
||||
if (isBufferSource(param)) {
|
||||
this.buffer = toArrayBuffer(param);
|
||||
}
|
||||
else if (Array.isArray(param)) {
|
||||
this.buffer = new Uint8Array(param).buffer;
|
||||
}
|
||||
else {
|
||||
this.buffer = new ArrayBuffer(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
fromASN(asn) {
|
||||
if (!(asn instanceof asn1js.OctetString)) {
|
||||
throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");
|
||||
}
|
||||
this.buffer = toArrayBuffer(asn.valueBlock.valueHex);
|
||||
return this;
|
||||
}
|
||||
toASN() {
|
||||
return new asn1js.OctetString({ valueHex: this.buffer });
|
||||
}
|
||||
toSchema(name) {
|
||||
return new asn1js.OctetString({ name });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue