mirror of
https://github.com/signalapp/libsignal.git
synced 2026-04-26 01:35:22 +02:00
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.
38 lines
859 B
TypeScript
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);
|
|
}
|
|
}
|