blob: 86228739fcc3b29b48b44a8bc134a9021894fd4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
}
}
|