Immutable data class. var -> val, MutableList -> List
This commit is contained in:
parent
91c896f566
commit
2858401a12
|
@ -18,17 +18,16 @@ package org.matrix.android.sdk.api.session.crypto.keysbackup
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data model for response to [KeysBackup.getKeysBackupTrust()].
|
* Data model for response to [KeysBackup.getKeysBackupTrust()].
|
||||||
* TODO Members should be only val
|
|
||||||
*/
|
*/
|
||||||
data class KeysBackupVersionTrust(
|
data class KeysBackupVersionTrust(
|
||||||
/**
|
/**
|
||||||
* Flag to indicate if the backup is trusted.
|
* Flag to indicate if the backup is trusted.
|
||||||
* true if there is a signature that is valid & from a trusted device.
|
* 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.
|
* Signatures found in the backup version.
|
||||||
*/
|
*/
|
||||||
var signatures: MutableList<KeysBackupVersionTrustSignature> = ArrayList()
|
val signatures: List<KeysBackupVersionTrustSignature> = emptyList()
|
||||||
)
|
)
|
||||||
|
|
|
@ -409,20 +409,22 @@ internal class DefaultKeysBackupService @Inject constructor(
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private fun getKeysBackupTrustBg(keysBackupVersion: KeysVersionResult): KeysBackupVersionTrust {
|
private fun getKeysBackupTrustBg(keysBackupVersion: KeysVersionResult): KeysBackupVersionTrust {
|
||||||
val keysBackupVersionTrust = KeysBackupVersionTrust()
|
|
||||||
val authData = keysBackupVersion.getAuthDataAsMegolmBackupAuthData()
|
val authData = keysBackupVersion.getAuthDataAsMegolmBackupAuthData()
|
||||||
|
|
||||||
if (authData == null || authData.publicKey.isEmpty() || authData.signatures.isNullOrEmpty()) {
|
if (authData == null || authData.publicKey.isEmpty() || authData.signatures.isNullOrEmpty()) {
|
||||||
Timber.v("getKeysBackupTrust: Key backup is absent or missing required data")
|
Timber.v("getKeysBackupTrust: Key backup is absent or missing required data")
|
||||||
return keysBackupVersionTrust
|
return KeysBackupVersionTrust()
|
||||||
}
|
}
|
||||||
|
|
||||||
val mySigs = authData.signatures[userId]
|
val mySigs = authData.signatures[userId]
|
||||||
if (mySigs.isNullOrEmpty()) {
|
if (mySigs.isNullOrEmpty()) {
|
||||||
Timber.v("getKeysBackupTrust: Ignoring key backup because it lacks any signatures from this user")
|
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) {
|
for ((keyId, mySignature) in mySigs) {
|
||||||
// XXX: is this how we're supposed to get the device id?
|
// XXX: is this how we're supposed to get the device id?
|
||||||
var deviceId: String? = null
|
var deviceId: String? = null
|
||||||
|
@ -449,7 +451,7 @@ internal class DefaultKeysBackupService @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSignatureValid && device.isVerified) {
|
if (isSignatureValid && device.isVerified) {
|
||||||
keysBackupVersionTrust.usable = true
|
keysBackupVersionTrustIsUsable = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,11 +459,14 @@ internal class DefaultKeysBackupService @Inject constructor(
|
||||||
signature.device = device
|
signature.device = device
|
||||||
signature.valid = isSignatureValid
|
signature.valid = isSignatureValid
|
||||||
signature.deviceId = deviceId
|
signature.deviceId = deviceId
|
||||||
keysBackupVersionTrust.signatures.add(signature)
|
keysBackupVersionTrustSignatures.add(signature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return keysBackupVersionTrust
|
return KeysBackupVersionTrust(
|
||||||
|
usable = keysBackupVersionTrustIsUsable,
|
||||||
|
signatures = keysBackupVersionTrustSignatures
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult,
|
override fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult,
|
||||||
|
|
Loading…
Reference in New Issue