refactor: capture member variables as finals

This commit is contained in:
Lukas Lihotzki 2021-09-30 15:10:59 +02:00
parent 41d905ca60
commit 85004e1faf
3 changed files with 19 additions and 13 deletions

View File

@ -687,31 +687,35 @@ class OpenSSSS {
} }
Future<String> getStored(String type) async { Future<String> getStored(String type) async {
final privateKey = this.privateKey;
if (privateKey == null) { if (privateKey == null) {
throw Exception('SSSS not unlocked'); throw Exception('SSSS not unlocked');
} }
return await ssss.getStored(type, keyId, privateKey!); return await ssss.getStored(type, keyId, privateKey);
} }
Future<void> store(String type, String secret, {bool add = false}) async { Future<void> store(String type, String secret, {bool add = false}) async {
final privateKey = this.privateKey;
if (privateKey == null) { if (privateKey == null) {
throw Exception('SSSS not unlocked'); throw Exception('SSSS not unlocked');
} }
await ssss.store(type, secret, keyId, privateKey!, add: add); await ssss.store(type, secret, keyId, privateKey, add: add);
} }
Future<void> validateAndStripOtherKeys(String type, String secret) async { Future<void> validateAndStripOtherKeys(String type, String secret) async {
final privateKey = this.privateKey;
if (privateKey == null) { if (privateKey == null) {
throw Exception('SSSS not unlocked'); throw Exception('SSSS not unlocked');
} }
await ssss.validateAndStripOtherKeys(type, secret, keyId, privateKey!); await ssss.validateAndStripOtherKeys(type, secret, keyId, privateKey);
} }
Future<void> maybeCacheAll() async { Future<void> maybeCacheAll() async {
final privateKey = this.privateKey;
if (privateKey == null) { if (privateKey == null) {
throw Exception('SSSS not unlocked'); throw Exception('SSSS not unlocked');
} }
await ssss.maybeCacheAll(keyId, privateKey!); await ssss.maybeCacheAll(keyId, privateKey);
} }
Future<void> _postUnlock() async { Future<void> _postUnlock() async {

View File

@ -232,10 +232,10 @@ class Bootstrap {
void migrateOldSsss() { void migrateOldSsss() {
final keys = allNeededKeys(); final keys = allNeededKeys();
oldSsssKeys = <String, OpenSSSS>{}; final oldSsssKeys = this.oldSsssKeys = {};
try { try {
for (final key in keys) { for (final key in keys) {
oldSsssKeys![key] = encryption.ssss.open(key); oldSsssKeys[key] = encryption.ssss.open(key);
} }
} catch (e, s) { } catch (e, s) {
Logs().e('[Bootstrapping] Error construction ssss key', e, s); Logs().e('[Bootstrapping] Error construction ssss key', e, s);
@ -312,15 +312,15 @@ class Bootstrap {
} }
Future<void> openExistingSsss() async { Future<void> openExistingSsss() async {
final newSsssKey_ = newSsssKey; final newSsssKey = this.newSsssKey;
if (state != BootstrapState.openExistingSsss || newSsssKey_ == null) { if (state != BootstrapState.openExistingSsss || newSsssKey == null) {
throw BootstrapBadStateException(); throw BootstrapBadStateException();
} }
if (!newSsssKey_.isUnlocked) { if (!newSsssKey.isUnlocked) {
throw BootstrapBadStateException('Key not unlocked'); throw BootstrapBadStateException('Key not unlocked');
} }
Logs().v('Maybe cache all...'); Logs().v('Maybe cache all...');
await newSsssKey_.maybeCacheAll(); await newSsssKey.maybeCacheAll();
checkCrossSigning(); checkCrossSigning();
} }

View File

@ -252,8 +252,9 @@ class KeyVerification {
// as such, we better set it *before* we send our start // as such, we better set it *before* we send our start
lastStep = type; lastStep = type;
// TODO: Pick method? // TODO: Pick method?
method = _makeVerificationMethod(possibleMethods.first, this); final method = this.method =
await method!.sendStart(); _makeVerificationMethod(possibleMethods.first, this);
await method.sendStart();
setState(KeyVerificationState.waitingAccept); setState(KeyVerificationState.waitingAccept);
break; break;
case EventTypes.KeyVerificationStart: case EventTypes.KeyVerificationStart:
@ -320,8 +321,9 @@ class KeyVerification {
setState(KeyVerificationState.error); setState(KeyVerificationState.error);
break; break;
default: default:
final method = this.method;
if (method != null) { if (method != null) {
await method!.handlePayload(type, payload); await method.handlePayload(type, payload);
} else { } else {
await cancel('m.invalid_message'); await cancel('m.invalid_message');
} }