mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
UUID-keyed lookups in SignalProtocolStore
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { strictAssert } from '../util/assert';
|
||||
|
||||
import { UUID, UUIDStringType } from './UUID';
|
||||
import { Address, AddressStringType } from './Address';
|
||||
|
||||
const QUALIFIED_ADDRESS_REGEXP = /^([0-9a-f-]+):([0-9a-f-]+).(\d+)$/i;
|
||||
|
||||
export type QualifiedAddressCreateOptionsType = Readonly<{
|
||||
ourUuid: string;
|
||||
uuid: string;
|
||||
deviceId: number;
|
||||
}>;
|
||||
|
||||
export type QualifiedAddressStringType = `${UUIDStringType}:${AddressStringType}`;
|
||||
|
||||
export class QualifiedAddress {
|
||||
constructor(
|
||||
public readonly ourUuid: UUID,
|
||||
public readonly address: Address
|
||||
) {}
|
||||
|
||||
public get uuid(): UUID {
|
||||
return this.address.uuid;
|
||||
}
|
||||
|
||||
public get deviceId(): number {
|
||||
return this.address.deviceId;
|
||||
}
|
||||
|
||||
public toString(): QualifiedAddressStringType {
|
||||
return `${this.ourUuid.toString()}:${this.address.toString()}`;
|
||||
}
|
||||
|
||||
public static parse(value: string): QualifiedAddress {
|
||||
const match = value.match(QUALIFIED_ADDRESS_REGEXP);
|
||||
strictAssert(match !== null, `Invalid QualifiedAddress: ${value}`);
|
||||
const [whole, ourUuid, uuid, deviceId] = match;
|
||||
strictAssert(whole === value, 'Integrity check');
|
||||
|
||||
return new QualifiedAddress(
|
||||
new UUID(ourUuid),
|
||||
Address.create(uuid, parseInt(deviceId, 10))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user