crypto: Remove some redundant methods from the verification service

This commit is contained in:
Damir Jelić 2021-07-22 11:25:29 +02:00
parent 3fa9fc5b7b
commit 3993d2d4f2
2 changed files with 18 additions and 18 deletions

View file

@ -34,6 +34,13 @@ import timber.log.Timber
import uniffi.olm.OlmMachine import uniffi.olm.OlmMachine
import uniffi.olm.VerificationRequest 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( internal class VerificationRequest(
private val machine: OlmMachine, private val machine: OlmMachine,
private var inner: VerificationRequest, private var inner: VerificationRequest,

View file

@ -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.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.message.MessageRelationContent 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.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.OlmMachine
import org.matrix.android.sdk.internal.crypto.RequestSender import org.matrix.android.sdk.internal.crypto.RequestSender
import org.matrix.android.sdk.internal.crypto.SasVerification import org.matrix.android.sdk.internal.crypto.SasVerification
@ -143,7 +142,7 @@ internal class RustVerificationService(
val sender = event.senderId ?: return val sender = event.senderId ?: return
val flowId = getFlowId(event) ?: return val flowId = getFlowId(event) ?: return
this.getVerificationRequest(sender, flowId)?.dispatchRequestUpdated() this.olmMachine.getVerificationRequest(sender, flowId)?.dispatchRequestUpdated()
val verification = this.getExistingTransaction(sender, flowId) ?: return val verification = this.getExistingTransaction(sender, flowId) ?: return
dispatchTxUpdated(verification) dispatchTxUpdated(verification)
} }
@ -153,7 +152,7 @@ internal class RustVerificationService(
val flowId = getFlowId(event) ?: return val flowId = getFlowId(event) ?: return
val verification = this.getExistingTransaction(sender, flowId) ?: 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 (request != null && request.isReady()) {
// If this is a SAS verification originating from a `m.key.verification.request` // If this is a SAS verification originating from a `m.key.verification.request`
@ -185,18 +184,10 @@ internal class RustVerificationService(
dispatchRequestAdded(request) 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) { override fun markedLocallyAsManuallyVerified(userId: String, deviceID: String) {
// TODO this doesn't seem to be used anymore? // TODO this doesn't seem to be used anymore?
runBlocking { runBlocking {
val device = getDevice(userId, deviceID) val device = olmMachine.getDevice(userId, deviceID)
device?.markAsTrusted() device?.markAsTrusted()
} }
} }
@ -225,7 +216,7 @@ internal class RustVerificationService(
tid: String? tid: String?
): PendingVerificationRequest? { ): PendingVerificationRequest? {
return if (tid != null) { return if (tid != null) {
this.getVerificationRequest(otherUserId, tid)?.toPendingVerificationRequest() this.olmMachine.getVerificationRequest(otherUserId, tid)?.toPendingVerificationRequest()
} else { } else {
null null
} }
@ -303,7 +294,7 @@ internal class RustVerificationService(
otherUserId: String, otherUserId: String,
transactionId: String transactionId: String
): Boolean { ): Boolean {
val request = this.getVerificationRequest(otherUserId, transactionId) val request = this.olmMachine.getVerificationRequest(otherUserId, transactionId)
return if (request != null) { return if (request != null) {
runBlocking { request.acceptWithMethods(methods) } runBlocking { request.acceptWithMethods(methods) }
@ -341,7 +332,7 @@ internal class RustVerificationService(
): String? { ): String? {
return if (method == VerificationMethod.SAS) { return if (method == VerificationMethod.SAS) {
if (transactionId != null) { if (transactionId != null) {
val request = this.getVerificationRequest(otherUserId, transactionId) val request = this.olmMachine.getVerificationRequest(otherUserId, transactionId)
runBlocking { runBlocking {
val sas = request?.startSasVerification() val sas = request?.startSasVerification()
@ -360,7 +351,7 @@ internal class RustVerificationService(
// DeviceListBottomSheetViewModel triggers this, interestingly the method that // DeviceListBottomSheetViewModel triggers this, interestingly the method that
// triggers this is called `manuallyVerify()` // triggers this is called `manuallyVerify()`
runBlocking { runBlocking {
val verification = getDevice(otherUserId, otherDeviceId)?.startVerification() val verification = olmMachine.getDevice(otherUserId, otherDeviceId)?.startVerification()
if (verification != null) { if (verification != null) {
dispatchTxAdded(verification) dispatchTxAdded(verification)
verification.transactionId verification.transactionId
@ -388,7 +379,9 @@ internal class RustVerificationService(
} }
override fun cancelVerificationRequest(request: PendingVerificationRequest) { 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() } runBlocking { verificationRequest?.cancel() }
} }
@ -397,7 +390,7 @@ internal class RustVerificationService(
transactionId: String, transactionId: String,
roomId: String roomId: String
) { ) {
val verificationRequest = this.getVerificationRequest(otherUserId, transactionId) val verificationRequest = this.olmMachine.getVerificationRequest(otherUserId, transactionId)
runBlocking { verificationRequest?.cancel() } runBlocking { verificationRequest?.cancel() }
} }
} }