From 85004e1faf1c2c43b87bc55bbd10aa9e30bb4b94 Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Thu, 30 Sep 2021 15:10:59 +0200 Subject: [PATCH] refactor: capture member variables as finals --- lib/encryption/ssss.dart | 12 ++++++++---- lib/encryption/utils/bootstrap.dart | 12 ++++++------ lib/encryption/utils/key_verification.dart | 8 +++++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart index f04602cd..79c1309d 100644 --- a/lib/encryption/ssss.dart +++ b/lib/encryption/ssss.dart @@ -687,31 +687,35 @@ class OpenSSSS { } Future getStored(String type) async { + final privateKey = this.privateKey; if (privateKey == null) { throw Exception('SSSS not unlocked'); } - return await ssss.getStored(type, keyId, privateKey!); + return await ssss.getStored(type, keyId, privateKey); } Future store(String type, String secret, {bool add = false}) async { + final privateKey = this.privateKey; if (privateKey == null) { throw Exception('SSSS not unlocked'); } - await ssss.store(type, secret, keyId, privateKey!, add: add); + await ssss.store(type, secret, keyId, privateKey, add: add); } Future validateAndStripOtherKeys(String type, String secret) async { + final privateKey = this.privateKey; if (privateKey == null) { throw Exception('SSSS not unlocked'); } - await ssss.validateAndStripOtherKeys(type, secret, keyId, privateKey!); + await ssss.validateAndStripOtherKeys(type, secret, keyId, privateKey); } Future maybeCacheAll() async { + final privateKey = this.privateKey; if (privateKey == null) { throw Exception('SSSS not unlocked'); } - await ssss.maybeCacheAll(keyId, privateKey!); + await ssss.maybeCacheAll(keyId, privateKey); } Future _postUnlock() async { diff --git a/lib/encryption/utils/bootstrap.dart b/lib/encryption/utils/bootstrap.dart index ea33dcf3..e784d900 100644 --- a/lib/encryption/utils/bootstrap.dart +++ b/lib/encryption/utils/bootstrap.dart @@ -232,10 +232,10 @@ class Bootstrap { void migrateOldSsss() { final keys = allNeededKeys(); - oldSsssKeys = {}; + final oldSsssKeys = this.oldSsssKeys = {}; try { for (final key in keys) { - oldSsssKeys![key] = encryption.ssss.open(key); + oldSsssKeys[key] = encryption.ssss.open(key); } } catch (e, s) { Logs().e('[Bootstrapping] Error construction ssss key', e, s); @@ -312,15 +312,15 @@ class Bootstrap { } Future openExistingSsss() async { - final newSsssKey_ = newSsssKey; - if (state != BootstrapState.openExistingSsss || newSsssKey_ == null) { + final newSsssKey = this.newSsssKey; + if (state != BootstrapState.openExistingSsss || newSsssKey == null) { throw BootstrapBadStateException(); } - if (!newSsssKey_.isUnlocked) { + if (!newSsssKey.isUnlocked) { throw BootstrapBadStateException('Key not unlocked'); } Logs().v('Maybe cache all...'); - await newSsssKey_.maybeCacheAll(); + await newSsssKey.maybeCacheAll(); checkCrossSigning(); } diff --git a/lib/encryption/utils/key_verification.dart b/lib/encryption/utils/key_verification.dart index 795675ad..27c6b931 100644 --- a/lib/encryption/utils/key_verification.dart +++ b/lib/encryption/utils/key_verification.dart @@ -252,8 +252,9 @@ class KeyVerification { // as such, we better set it *before* we send our start lastStep = type; // TODO: Pick method? - method = _makeVerificationMethod(possibleMethods.first, this); - await method!.sendStart(); + final method = this.method = + _makeVerificationMethod(possibleMethods.first, this); + await method.sendStart(); setState(KeyVerificationState.waitingAccept); break; case EventTypes.KeyVerificationStart: @@ -320,8 +321,9 @@ class KeyVerification { setState(KeyVerificationState.error); break; default: + final method = this.method; if (method != null) { - await method!.handlePayload(type, payload); + await method.handlePayload(type, payload); } else { await cancel('m.invalid_message'); }