From 2858401a12d035a4fe328e603355f2f5706c6418 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 13 Apr 2022 18:52:20 +0200 Subject: [PATCH] Immutable data class. var -> val, MutableList -> List --- .../crypto/keysbackup/KeysBackupVersionTrust.kt | 5 ++--- .../keysbackup/DefaultKeysBackupService.kt | 17 +++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupVersionTrust.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupVersionTrust.kt index 042a626d28..37a36f78a7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupVersionTrust.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupVersionTrust.kt @@ -18,17 +18,16 @@ package org.matrix.android.sdk.api.session.crypto.keysbackup /** * Data model for response to [KeysBackup.getKeysBackupTrust()]. - * TODO Members should be only val */ data class KeysBackupVersionTrust( /** * Flag to indicate if the backup is trusted. * true if there is a signature that is valid & from a trusted device. */ - var usable: Boolean = false, + val usable: Boolean = false, /** * Signatures found in the backup version. */ - var signatures: MutableList = ArrayList() + val signatures: List = emptyList() ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt index f1929dea53..9a4868aa2b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt @@ -409,20 +409,22 @@ internal class DefaultKeysBackupService @Inject constructor( */ @WorkerThread private fun getKeysBackupTrustBg(keysBackupVersion: KeysVersionResult): KeysBackupVersionTrust { - val keysBackupVersionTrust = KeysBackupVersionTrust() val authData = keysBackupVersion.getAuthDataAsMegolmBackupAuthData() if (authData == null || authData.publicKey.isEmpty() || authData.signatures.isNullOrEmpty()) { Timber.v("getKeysBackupTrust: Key backup is absent or missing required data") - return keysBackupVersionTrust + return KeysBackupVersionTrust() } val mySigs = authData.signatures[userId] if (mySigs.isNullOrEmpty()) { Timber.v("getKeysBackupTrust: Ignoring key backup because it lacks any signatures from this user") - return keysBackupVersionTrust + return KeysBackupVersionTrust() } + var keysBackupVersionTrustIsUsable = false + val keysBackupVersionTrustSignatures = mutableListOf() + for ((keyId, mySignature) in mySigs) { // XXX: is this how we're supposed to get the device id? var deviceId: String? = null @@ -449,7 +451,7 @@ internal class DefaultKeysBackupService @Inject constructor( } if (isSignatureValid && device.isVerified) { - keysBackupVersionTrust.usable = true + keysBackupVersionTrustIsUsable = true } } @@ -457,11 +459,14 @@ internal class DefaultKeysBackupService @Inject constructor( signature.device = device signature.valid = isSignatureValid signature.deviceId = deviceId - keysBackupVersionTrust.signatures.add(signature) + keysBackupVersionTrustSignatures.add(signature) } } - return keysBackupVersionTrust + return KeysBackupVersionTrust( + usable = keysBackupVersionTrustIsUsable, + signatures = keysBackupVersionTrustSignatures + ) } override fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult,