fix: Fix occurence of not using synchronized's return

This commit is contained in:
PapaTutuWawa 2022-09-15 13:46:52 +02:00
parent 96d9c55c87
commit 0480e9156f

View File

@ -97,12 +97,7 @@ class OmemoSessionManager {
/// Returns our own device. /// Returns our own device.
Future<Device> getDevice() async { Future<Device> getDevice() async {
Device? dev; return _deviceLock.synchronized(() => _device);
await _deviceLock.synchronized(() async {
dev = _device;
});
return dev!;
} }
/// Returns the id attribute of our own device. This is just a short-hand for /// Returns the id attribute of our own device. This is just a short-hand for
@ -177,14 +172,14 @@ class OmemoSessionManager {
Future<void> _addSessionFromKeyExchange(String jid, int deviceId, OmemoKeyExchange kex) async { Future<void> _addSessionFromKeyExchange(String jid, int deviceId, OmemoKeyExchange kex) async {
// Pick the correct SPK // Pick the correct SPK
final device = await getDevice(); final device = await getDevice();
OmemoKeyPair? spk; final spk = await _lock.synchronized(() async {
await _lock.synchronized(() async {
if (kex.spkId == _device.spkId) { if (kex.spkId == _device.spkId) {
spk = _device.spk; return _device.spk;
} else if (kex.spkId == _device.oldSpkId) { } else if (kex.spkId == _device.oldSpkId) {
spk = _device.oldSpk; return _device.oldSpk;
} }
return null;
}); });
if (spk == null) { if (spk == null) {
throw UnknownSignedPrekeyException(); throw UnknownSignedPrekeyException();
@ -196,12 +191,12 @@ class OmemoSessionManager {
OmemoPublicKey.fromBytes(kex.ek!, KeyPairType.x25519), OmemoPublicKey.fromBytes(kex.ek!, KeyPairType.x25519),
kex.pkId!, kex.pkId!,
), ),
spk!, spk,
device.opks.values.elementAt(kex.pkId!), device.opks.values.elementAt(kex.pkId!),
device.ik, device.ik,
); );
final ratchet = await OmemoDoubleRatchet.acceptNewSession( final ratchet = await OmemoDoubleRatchet.acceptNewSession(
spk!, spk,
OmemoPublicKey.fromBytes(kex.ik!, KeyPairType.ed25519), OmemoPublicKey.fromBytes(kex.ik!, KeyPairType.ed25519),
kexResult.sk, kexResult.sk,
kexResult.ad, kexResult.ad,