Improve APIs, add tests
This commit is contained in:
parent
175bada0df
commit
7fd0ad09dc
22 changed files with 562 additions and 76 deletions
|
|
@ -18,6 +18,7 @@ package io.element.android.libraries.matrix.impl.encryption
|
|||
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.core.extensions.mapFailure
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.matrix.api.encryption.BackupState
|
||||
import io.element.android.libraries.matrix.api.encryption.BackupUploadState
|
||||
import io.element.android.libraries.matrix.api.encryption.EnableRecoveryProgress
|
||||
|
|
@ -55,6 +56,7 @@ internal class RustEncryptionService(
|
|||
private val dispatchers: CoroutineDispatchers,
|
||||
) : EncryptionService {
|
||||
private val service: Encryption = client.encryption()
|
||||
private val sessionId = SessionId(client.session().userId)
|
||||
|
||||
private val enableRecoveryProgressMapper = EnableRecoveryProgressMapper()
|
||||
private val backupUploadStateMapper = BackupUploadStateMapper()
|
||||
|
|
@ -201,6 +203,10 @@ internal class RustEncryptionService(
|
|||
}
|
||||
|
||||
override suspend fun startIdentityReset(): Result<IdentityResetHandle?> {
|
||||
return runCatching { service.resetIdentity()?.let(RustIdentityResetHandleFactory::create)?.getOrNull() }
|
||||
return runCatching {
|
||||
service.resetIdentity()?.let { handle ->
|
||||
RustIdentityResetHandleFactory.create(sessionId, handle)
|
||||
}?.getOrNull()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,21 +25,25 @@ import org.matrix.rustcomponents.sdk.AuthDataPasswordDetails
|
|||
import org.matrix.rustcomponents.sdk.CrossSigningResetAuthType
|
||||
|
||||
object RustIdentityResetHandleFactory {
|
||||
fun create(identityResetHandle: org.matrix.rustcomponents.sdk.IdentityResetHandle): Result<IdentityResetHandle> {
|
||||
fun create(
|
||||
userId: UserId,
|
||||
identityResetHandle: org.matrix.rustcomponents.sdk.IdentityResetHandle
|
||||
): Result<IdentityResetHandle> {
|
||||
return runCatching {
|
||||
when (val authType = identityResetHandle.authType()) {
|
||||
is CrossSigningResetAuthType.Oidc -> RustOidcIdentityResetHandle(identityResetHandle, authType.info.approvalUrl)
|
||||
// User interactive authentication (user + password)
|
||||
CrossSigningResetAuthType.Uiaa -> RustPasswordIdentityResetHandle(identityResetHandle)
|
||||
CrossSigningResetAuthType.Uiaa -> RustPasswordIdentityResetHandle(userId, identityResetHandle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RustPasswordIdentityResetHandle(
|
||||
private val userId: UserId,
|
||||
private val identityResetHandle: org.matrix.rustcomponents.sdk.IdentityResetHandle,
|
||||
) : IdentityPasswordResetHandle {
|
||||
override suspend fun resetPassword(userId: UserId, password: String): Result<Unit> {
|
||||
override suspend fun resetPassword(password: String): Result<Unit> {
|
||||
return runCatching { identityResetHandle.reset(AuthData.Password(AuthDataPasswordDetails(userId.value, password))) }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue