From 3993d2d4f2dbce2e64223d55bb014cf483b9e534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 22 Jul 2021 11:25:29 +0200 Subject: [PATCH] crypto: Remove some redundant methods from the verification service --- .../internal/crypto/VerificationRequest.kt | 7 +++++ .../verification/RustVerificationService.kt | 29 +++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/VerificationRequest.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/VerificationRequest.kt index 540b429db1..dcad660fd4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/VerificationRequest.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/VerificationRequest.kt @@ -34,6 +34,13 @@ import timber.log.Timber import uniffi.olm.OlmMachine import uniffi.olm.VerificationRequest +/** A verification request object + * + * This represents a verification flow that starts with a m.key.verification.request event + * + * Once the VerificationRequest gets to a ready state users can transition into the different + * concrete verification flows. + */ internal class VerificationRequest( private val machine: OlmMachine, private var inner: VerificationRequest, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/RustVerificationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/RustVerificationService.kt index babecfea70..c3fdc3a314 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/RustVerificationService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/verification/RustVerificationService.kt @@ -30,7 +30,6 @@ import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.message.MessageRelationContent import org.matrix.android.sdk.api.session.room.model.message.MessageType -import org.matrix.android.sdk.internal.crypto.Device import org.matrix.android.sdk.internal.crypto.OlmMachine import org.matrix.android.sdk.internal.crypto.RequestSender import org.matrix.android.sdk.internal.crypto.SasVerification @@ -143,7 +142,7 @@ internal class RustVerificationService( val sender = event.senderId ?: return val flowId = getFlowId(event) ?: return - this.getVerificationRequest(sender, flowId)?.dispatchRequestUpdated() + this.olmMachine.getVerificationRequest(sender, flowId)?.dispatchRequestUpdated() val verification = this.getExistingTransaction(sender, flowId) ?: return dispatchTxUpdated(verification) } @@ -153,7 +152,7 @@ internal class RustVerificationService( val flowId = getFlowId(event) ?: return val verification = this.getExistingTransaction(sender, flowId) ?: return - val request = this.getVerificationRequest(sender, flowId) + val request = this.olmMachine.getVerificationRequest(sender, flowId) if (request != null && request.isReady()) { // If this is a SAS verification originating from a `m.key.verification.request` @@ -185,18 +184,10 @@ internal class RustVerificationService( dispatchRequestAdded(request) } - private fun getVerificationRequest(otherUserId: String, transactionId: String): VerificationRequest? { - return this.olmMachine.getVerificationRequest(otherUserId, transactionId) - } - - private suspend fun getDevice(userId: String, deviceID: String): Device? { - return this.olmMachine.getDevice(userId, deviceID) - } - override fun markedLocallyAsManuallyVerified(userId: String, deviceID: String) { // TODO this doesn't seem to be used anymore? runBlocking { - val device = getDevice(userId, deviceID) + val device = olmMachine.getDevice(userId, deviceID) device?.markAsTrusted() } } @@ -225,7 +216,7 @@ internal class RustVerificationService( tid: String? ): PendingVerificationRequest? { return if (tid != null) { - this.getVerificationRequest(otherUserId, tid)?.toPendingVerificationRequest() + this.olmMachine.getVerificationRequest(otherUserId, tid)?.toPendingVerificationRequest() } else { null } @@ -303,7 +294,7 @@ internal class RustVerificationService( otherUserId: String, transactionId: String ): Boolean { - val request = this.getVerificationRequest(otherUserId, transactionId) + val request = this.olmMachine.getVerificationRequest(otherUserId, transactionId) return if (request != null) { runBlocking { request.acceptWithMethods(methods) } @@ -341,7 +332,7 @@ internal class RustVerificationService( ): String? { return if (method == VerificationMethod.SAS) { if (transactionId != null) { - val request = this.getVerificationRequest(otherUserId, transactionId) + val request = this.olmMachine.getVerificationRequest(otherUserId, transactionId) runBlocking { val sas = request?.startSasVerification() @@ -360,7 +351,7 @@ internal class RustVerificationService( // DeviceListBottomSheetViewModel triggers this, interestingly the method that // triggers this is called `manuallyVerify()` runBlocking { - val verification = getDevice(otherUserId, otherDeviceId)?.startVerification() + val verification = olmMachine.getDevice(otherUserId, otherDeviceId)?.startVerification() if (verification != null) { dispatchTxAdded(verification) verification.transactionId @@ -388,7 +379,9 @@ internal class RustVerificationService( } override fun cancelVerificationRequest(request: PendingVerificationRequest) { - val verificationRequest = request.transactionId?.let { this.getVerificationRequest(request.otherUserId, it) } + val verificationRequest = request.transactionId?.let { + this.olmMachine.getVerificationRequest(request.otherUserId, it) + } runBlocking { verificationRequest?.cancel() } } @@ -397,7 +390,7 @@ internal class RustVerificationService( transactionId: String, roomId: String ) { - val verificationRequest = this.getVerificationRequest(otherUserId, transactionId) + val verificationRequest = this.olmMachine.getVerificationRequest(otherUserId, transactionId) runBlocking { verificationRequest?.cancel() } } }