Immutable data class. var -> val, MutableList -> List

This commit is contained in:
Benoit Marty 2022-04-13 18:52:20 +02:00
parent 91c896f566
commit 2858401a12
2 changed files with 13 additions and 9 deletions

View File

@ -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<KeysBackupVersionTrustSignature> = ArrayList()
val signatures: List<KeysBackupVersionTrustSignature> = emptyList()
)

View File

@ -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<KeysBackupVersionTrustSignature>()
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,