Support PNI in QualifiedAddress.parse
This commit is contained in:
parent
0b629c9f70
commit
7bad05f5a0
3 changed files with 18 additions and 15 deletions
|
@ -48,6 +48,7 @@ const {
|
||||||
|
|
||||||
describe('SignalProtocolStore', () => {
|
describe('SignalProtocolStore', () => {
|
||||||
const ourAci = generateAci();
|
const ourAci = generateAci();
|
||||||
|
const ourPni = generatePni();
|
||||||
const theirAci = generateAci();
|
const theirAci = generateAci();
|
||||||
let store: SignalProtocolStore;
|
let store: SignalProtocolStore;
|
||||||
let identityKey: KeyPairType;
|
let identityKey: KeyPairType;
|
||||||
|
@ -1385,6 +1386,21 @@ describe('SignalProtocolStore', () => {
|
||||||
await store.archiveSiblingSessions(id.address, { zone });
|
await store.archiveSiblingSessions(id.address, { zone });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not throw in archiveSession on PNI', async () => {
|
||||||
|
const id = new QualifiedAddress(ourPni, new Address(theirAci, 1));
|
||||||
|
|
||||||
|
await store.storeSession(id, getSessionRecord(true));
|
||||||
|
|
||||||
|
await store.archiveSession(id);
|
||||||
|
|
||||||
|
const { devices, emptyServiceIds } = await store.getOpenDevices(ourPni, [
|
||||||
|
theirAci,
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.deepEqual(devices, []);
|
||||||
|
assert.deepEqual(emptyServiceIds, [theirAci]);
|
||||||
|
});
|
||||||
|
|
||||||
it('can be concurrently re-entered after waiting', async () => {
|
it('can be concurrently re-entered after waiting', async () => {
|
||||||
const a = new Zone('a');
|
const a = new Zone('a');
|
||||||
const b = new Zone('b');
|
const b = new Zone('b');
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { strictAssert } from '../util/assert';
|
|
||||||
|
|
||||||
import type { ServiceIdString } from './ServiceId';
|
import type { ServiceIdString } from './ServiceId';
|
||||||
import { isServiceIdString } from './ServiceId';
|
|
||||||
|
|
||||||
export type AddressStringType = `${ServiceIdString}.${number}`;
|
export type AddressStringType = `${ServiceIdString}.${number}`;
|
||||||
|
|
||||||
const ADDRESS_REGEXP = /^([:0-9a-f-]+).(\d+)$/i;
|
|
||||||
|
|
||||||
export class Address {
|
export class Address {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly serviceId: ServiceIdString,
|
public readonly serviceId: ServiceIdString,
|
||||||
|
@ -20,15 +15,6 @@ export class Address {
|
||||||
return `${this.serviceId}.${this.deviceId}`;
|
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 {
|
public static create(serviceId: ServiceIdString, deviceId: number): Address {
|
||||||
return new Address(serviceId, deviceId);
|
return new Address(serviceId, deviceId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@ import { isServiceIdString } from './ServiceId';
|
||||||
import type { AddressStringType } from './Address';
|
import type { AddressStringType } from './Address';
|
||||||
import { Address } from './Address';
|
import { Address } from './Address';
|
||||||
|
|
||||||
const QUALIFIED_ADDRESS_REGEXP = /^([:0-9a-f-]+):([:0-9a-f-]+).(\d+)$/i;
|
const QUALIFIED_ADDRESS_REGEXP =
|
||||||
|
/^((?:PNI:)?[:0-9a-f-]+):((?:PNI:)?[:0-9a-f-]+).(\d+)$/i;
|
||||||
|
|
||||||
export type QualifiedAddressCreateOptionsType = Readonly<{
|
export type QualifiedAddressCreateOptionsType = Readonly<{
|
||||||
ourServiceId: ServiceIdString;
|
ourServiceId: ServiceIdString;
|
||||||
|
|
Loading…
Add table
Reference in a new issue