summaryrefslogtreecommitdiffstats
path: root/comm/third_party/asn1js/src/RawData.ts
diff options
context:
space:
mode:
Diffstat (limited to 'comm/third_party/asn1js/src/RawData.ts')
-rw-r--r--comm/third_party/asn1js/src/RawData.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/comm/third_party/asn1js/src/RawData.ts b/comm/third_party/asn1js/src/RawData.ts
new file mode 100644
index 0000000000..86228739fc
--- /dev/null
+++ b/comm/third_party/asn1js/src/RawData.ts
@@ -0,0 +1,51 @@
+import * as pvtsutils from "pvtsutils";
+import { IBerConvertible } from "./types";
+import { EMPTY_VIEW } from "./internals/constants";
+
+export interface IRawData {
+ data: ArrayBuffer;
+}
+
+export type RawDataParams = Partial<IRawData>;
+
+/**
+ * Special class providing ability to have "toBER/fromBER" for raw ArrayBuffer
+ */
+export class RawData implements IBerConvertible {
+
+
+ /**
+ * @deprecated Since v3.0.0
+ */
+ public get data(): ArrayBuffer {
+ return this.dataView.slice().buffer;
+ }
+
+ /**
+ * @deprecated Since v3.0.0
+ */
+ public set data(value: ArrayBuffer) {
+ this.dataView = pvtsutils.BufferSourceConverter.toUint8Array(value);
+ }
+
+ /**
+ * @since 3.0.0
+ */
+ public dataView: Uint8Array;
+
+ constructor({ data = EMPTY_VIEW }: RawDataParams = {}) {
+ this.dataView = pvtsutils.BufferSourceConverter.toUint8Array(data);
+ }
+
+ public fromBER(inputBuffer: ArrayBuffer | Uint8Array, inputOffset: number, inputLength: number): number {
+ const endLength = inputOffset + inputLength;
+ this.dataView = pvtsutils.BufferSourceConverter.toUint8Array(inputBuffer).subarray(inputOffset, endLength);
+
+ return endLength;
+ }
+
+ public toBER(sizeOnly?: boolean): ArrayBuffer {
+ return this.dataView.slice().buffer;
+ }
+
+}