Files
libsignal/node/ts/zkgroup/internal/ByteArray.ts
Jordan Rose 734c0e02a3 node: Move TypeScript source files into ts/ directory
This way, files that reference the non-compiled Native.js/.d.ts can
consistently refer to it as '../Native' without having to copy
anything around.
2021-11-08 16:40:50 -08:00

38 lines
859 B
TypeScript

//
// Copyright 2020-2021 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
import { SignalClientErrorBase } from '../../Errors';
export default class ByteArray {
contents: Buffer;
constructor(contents: Buffer, checkValid: (contents: Buffer) => void) {
checkValid(contents);
this.contents = Buffer.from(contents);
}
protected static checkLength(
expectedLength: number
): (contents: Buffer) => void {
return contents => {
if (contents.length !== expectedLength) {
throw new SignalClientErrorBase(
`Length of array supplied was ${contents.length} expected ${expectedLength}`,
undefined,
this.name
);
}
};
}
public getContents(): Buffer {
return this.contents;
}
public serialize(): Buffer {
return Buffer.from(this.contents);
}
}