mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-19 16:08:34 +01:00
Support PNI in QualifiedAddress.parse
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { strictAssert } from '../util/assert';
|
||||
|
||||
import type { ServiceIdString } from './ServiceId';
|
||||
import { isServiceIdString } from './ServiceId';
|
||||
|
||||
export type AddressStringType = `${ServiceIdString}.${number}`;
|
||||
|
||||
const ADDRESS_REGEXP = /^([:0-9a-f-]+).(\d+)$/i;
|
||||
|
||||
export class Address {
|
||||
constructor(
|
||||
public readonly serviceId: ServiceIdString,
|
||||
@@ -20,15 +15,6 @@ export class Address {
|
||||
return `${this.serviceId}.${this.deviceId}`;
|
||||
}
|
||||
|
||||
public static parse(value: string): Address {
|
||||
const match = value.match(ADDRESS_REGEXP);
|
||||
strictAssert(match != null, `Invalid Address: ${value}`);
|
||||
const [whole, serviceId, deviceId] = match;
|
||||
strictAssert(whole === value, 'Integrity check');
|
||||
strictAssert(isServiceIdString(serviceId), 'Their service id is incorrect');
|
||||
return Address.create(serviceId, parseInt(deviceId, 10));
|
||||
}
|
||||
|
||||
public static create(serviceId: ServiceIdString, deviceId: number): Address {
|
||||
return new Address(serviceId, deviceId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user