summaryrefslogtreecommitdiffstats
path: root/comm/third_party/asn1js/src/internals/LocalBaseBlock.ts
diff options
context:
space:
mode:
Diffstat (limited to 'comm/third_party/asn1js/src/internals/LocalBaseBlock.ts')
-rw-r--r--comm/third_party/asn1js/src/internals/LocalBaseBlock.ts93
1 files changed, 93 insertions, 0 deletions
diff --git a/comm/third_party/asn1js/src/internals/LocalBaseBlock.ts b/comm/third_party/asn1js/src/internals/LocalBaseBlock.ts
new file mode 100644
index 0000000000..c144c49d10
--- /dev/null
+++ b/comm/third_party/asn1js/src/internals/LocalBaseBlock.ts
@@ -0,0 +1,93 @@
+import * as pvtsutils from "pvtsutils";
+import { EMPTY_STRING, EMPTY_VIEW } from "./constants";
+
+export interface ILocalBaseBlock {
+ blockLength: number;
+ error: string;
+ warnings: string[];
+}
+
+export interface LocalBaseBlockJson extends ILocalBaseBlock {
+ blockName: string;
+ valueBeforeDecode: string;
+}
+
+export interface LocalBaseBlockParams extends Partial<ILocalBaseBlock> {
+ valueBeforeDecode?: pvtsutils.BufferSource;
+}
+
+export interface LocalBaseBlockConstructor<T extends LocalBaseBlock = LocalBaseBlock> {
+ new(...args: any[]): T;
+ prototype: T;
+ NAME: string;
+ blockName(): string;
+}
+
+/**
+ * Class used as a base block for all remaining ASN.1 classes
+ */
+export class LocalBaseBlock implements ILocalBaseBlock {
+
+ /**
+ * Name of the block
+ */
+ public static NAME = "baseBlock";
+ /**
+ * Aux function, need to get a block name. Need to have it here for inheritance
+ * @returns Returns name of the block
+ */
+ public static blockName(): string {
+ return this.NAME;
+ }
+
+ public blockLength: number;
+ public error: string;
+ public warnings: string[];
+ /**
+ * @deprecated since version 3.0.0
+ */
+ public get valueBeforeDecode(): ArrayBuffer {
+ return this.valueBeforeDecodeView.slice().buffer;
+ }
+ /**
+ * @deprecated since version 3.0.0
+ */
+ public set valueBeforeDecode(value: ArrayBuffer) {
+ this.valueBeforeDecodeView = new Uint8Array(value);
+ }
+ /**
+ * @since 3.0.0
+ */
+ public valueBeforeDecodeView: Uint8Array;
+
+ /**
+ * Creates and initializes an object instance of that class
+ * @param param0 Initialization parameters
+ */
+ constructor({
+ blockLength = 0,
+ error = EMPTY_STRING,
+ warnings = [],
+ valueBeforeDecode = EMPTY_VIEW,
+ }: LocalBaseBlockParams = {}) {
+ this.blockLength = blockLength;
+ this.error = error;
+ this.warnings = warnings;
+ this.valueBeforeDecodeView = pvtsutils.BufferSourceConverter.toUint8Array(valueBeforeDecode);
+ }
+
+ /**
+ * Returns a JSON representation of an object
+ * @returns JSON object
+ */
+ public toJSON(): LocalBaseBlockJson {
+ return {
+ blockName: (this.constructor as typeof LocalBaseBlock).NAME,
+ blockLength: this.blockLength,
+ error: this.error,
+ warnings: this.warnings,
+ valueBeforeDecode: pvtsutils.Convert.ToHex(this.valueBeforeDecodeView),
+ };
+ }
+
+}