From 48904b3a1bb830fa04fffb69c3cbb0044a8c39a2 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 23 Dec 2020 10:52:39 +0100 Subject: [PATCH] fix: Cache the result of the self-signature check --- lib/src/utils/device_keys_list.dart | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/src/utils/device_keys_list.dart b/lib/src/utils/device_keys_list.dart index 04b3d911..f4cd4bfc 100644 --- a/lib/src/utils/device_keys_list.dart +++ b/lib/src/utils/device_keys_list.dart @@ -369,15 +369,19 @@ class DeviceKeys extends SignableKey { String get deviceDisplayName => unsigned != null ? unsigned['device_display_name'] : null; - bool get selfSigned => signatures - ?.tryGet>(userId) - ?.tryGet('ed25519:$deviceId') == - null - ? false - // without libolm we still want to be able to add devices. In that case we ofc just can't - // verify the signature - : _verifySignature(ed25519Key, signatures[userId]['ed25519:$deviceId'], - isSignatureWithoutLibolmValid: true); + bool _validSelfSignature; + bool get selfSigned => + _validSelfSignature ?? + (_validSelfSignature = (signatures + ?.tryGet>(userId) + ?.tryGet('ed25519:$deviceId') == + null + ? false + // without libolm we still want to be able to add devices. In that case we ofc just can't + // verify the signature + : _verifySignature( + ed25519Key, signatures[userId]['ed25519:$deviceId'], + isSignatureWithoutLibolmValid: true))); @override bool get blocked => super.blocked || !selfSigned;