Compare commits
2 Commits
fda06cef55
...
73613e266f
Author | SHA1 | Date | |
---|---|---|---|
73613e266f | |||
0a03483aaf |
@ -163,6 +163,23 @@ class Device {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a new device that is equal to this one with the exception that the new
|
||||||
|
/// device's id is a new number between 0 and 2**32 - 1.
|
||||||
|
@internal
|
||||||
|
Device withNewId() {
|
||||||
|
return Device(
|
||||||
|
jid,
|
||||||
|
generateRandom32BitNumber(),
|
||||||
|
ik,
|
||||||
|
spk,
|
||||||
|
spkId,
|
||||||
|
spkSignature,
|
||||||
|
oldSpk,
|
||||||
|
oldSpkId,
|
||||||
|
opks,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts this device into an OmemoBundle that could be used for publishing.
|
/// Converts this device into an OmemoBundle that could be used for publishing.
|
||||||
Future<OmemoBundle> toBundle() async {
|
Future<OmemoBundle> toBundle() async {
|
||||||
final encodedOpks = <int, String>{};
|
final encodedOpks = <int, String>{};
|
||||||
|
@ -457,6 +457,28 @@ class OmemoSessionManager {
|
|||||||
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
|
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates an entirely new device. May be useful when the user wants to reset their cryptographic
|
||||||
|
/// identity. Triggers an event to commit it to storage.
|
||||||
|
Future<void> regenerateDevice({ int opkAmount = 100 }) async {
|
||||||
|
await _deviceLock.synchronized(() async {
|
||||||
|
_device = await Device.generateNewDevice(_device.jid, opkAmount: opkAmount);
|
||||||
|
|
||||||
|
// Commit it
|
||||||
|
_eventStreamController.add(DeviceModifiedEvent(_device));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Make our device have a new identifier. Only useful before publishing it as a bundle
|
||||||
|
/// to make sure that our device has a id that is account unique.
|
||||||
|
Future<void> regenerateDeviceId() async {
|
||||||
|
await _deviceLock.synchronized(() async {
|
||||||
|
_device = _device.withNewId();
|
||||||
|
|
||||||
|
// Commit it
|
||||||
|
_eventStreamController.add(DeviceModifiedEvent(_device));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!;
|
||||||
|
Loading…
Reference in New Issue
Block a user