mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 06:28:45 +03:00
crypto: Remove the higher level Device since it's unlikely we'll be using it
This commit is contained in:
parent
9296cab4fc
commit
99477914df
2 changed files with 20 additions and 39 deletions
|
@ -57,7 +57,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
|||
import org.matrix.android.sdk.api.util.JsonDict
|
||||
import org.matrix.android.sdk.internal.crypto.OlmMachine
|
||||
import org.matrix.android.sdk.internal.crypto.setRustLogger
|
||||
import org.matrix.android.sdk.internal.crypto.actions.MegolmSessionDataImporter
|
||||
import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService
|
||||
import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel
|
||||
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
|
||||
|
@ -132,7 +131,6 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
|
||||
private val crossSigningService: DefaultCrossSigningService,
|
||||
// Actions
|
||||
private val megolmSessionDataImporter: MegolmSessionDataImporter,
|
||||
private val warnOnUnknownDevicesRepository: WarnOnUnknownDeviceRepository,
|
||||
// Tasks
|
||||
private val deleteDeviceTask: DeleteDeviceTask,
|
||||
|
@ -403,7 +401,7 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
override fun getDeviceInfo(userId: String, deviceId: String?): CryptoDeviceInfo? {
|
||||
return if (userId.isNotEmpty() && !deviceId.isNullOrEmpty()) {
|
||||
runBlocking {
|
||||
olmMachine?.getDevice(userId, deviceId)?.toCryptoDeviceInfo()
|
||||
olmMachine?.getDevice(userId, deviceId)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.matrix.android.sdk.internal.session.sync.model.DeviceOneTimeKeysCount
|
|||
import org.matrix.android.sdk.internal.session.sync.model.ToDeviceSyncResponse
|
||||
import timber.log.Timber
|
||||
import uniffi.olm.CryptoStoreErrorException
|
||||
import uniffi.olm.Device as InnerDevice
|
||||
import uniffi.olm.Device
|
||||
import uniffi.olm.DeviceLists
|
||||
import uniffi.olm.Logger
|
||||
import uniffi.olm.OlmMachine as InnerMachine
|
||||
|
@ -68,7 +68,7 @@ internal class LiveDevice(
|
|||
userIds: List<String>,
|
||||
observer: DeviceUpdateObserver
|
||||
) : MutableLiveData<List<CryptoDeviceInfo>>() {
|
||||
var userIds: List<String> = userIds
|
||||
internal var userIds: List<String> = userIds
|
||||
private var observer: DeviceUpdateObserver = observer
|
||||
|
||||
override fun onActive() {
|
||||
|
@ -84,42 +84,25 @@ fun setRustLogger() {
|
|||
setLogger(CryptoLogger() as Logger)
|
||||
}
|
||||
|
||||
class Device(inner: InnerDevice, machine: InnerMachine) {
|
||||
private val machine: InnerMachine = machine
|
||||
private val inner: InnerDevice = inner
|
||||
|
||||
fun userId(): String {
|
||||
return this.inner.userId
|
||||
}
|
||||
|
||||
fun deviceId(): String {
|
||||
return this.inner.deviceId
|
||||
}
|
||||
|
||||
fun keys(): Map<String, String> {
|
||||
return this.inner.keys
|
||||
}
|
||||
|
||||
fun startVerification(): InnerSas {
|
||||
return this.machine.startVerification(this.inner)
|
||||
}
|
||||
|
||||
fun toCryptoDeviceInfo(): CryptoDeviceInfo {
|
||||
return CryptoDeviceInfo(
|
||||
this.deviceId(),
|
||||
this.userId(),
|
||||
this.inner.algorithms,
|
||||
this.keys(),
|
||||
// TODO pass the signatures here, do we need this?
|
||||
/**
|
||||
* Convert a Rust Device into a Kotlin CryptoDeviceInfo
|
||||
*/
|
||||
private fun toCryptoDeviceInfo(device: Device): CryptoDeviceInfo {
|
||||
return CryptoDeviceInfo(
|
||||
device.deviceId,
|
||||
device.userId,
|
||||
device.algorithms,
|
||||
device.keys,
|
||||
// TODO pass the signatures here, do we need this, why should the
|
||||
// Kotlin side care about signatures?
|
||||
mapOf(),
|
||||
UnsignedDeviceInfo(this.inner.displayName),
|
||||
UnsignedDeviceInfo(device.displayName),
|
||||
// TODO pass trust levels here
|
||||
DeviceTrustLevel(false, false),
|
||||
this.inner.isBlocked,
|
||||
device.isBlocked,
|
||||
// TODO
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal class DeviceUpdateObserver() {
|
||||
|
@ -417,10 +400,10 @@ internal class OlmMachine(user_id: String, device_id: String, path: File, device
|
|||
*
|
||||
* @return The Device if it found one.
|
||||
*/
|
||||
suspend fun getDevice(userId: String, deviceId: String): Device? = withContext(Dispatchers.IO) {
|
||||
when (val device: InnerDevice? = inner.getDevice(userId, deviceId)) {
|
||||
suspend fun getDevice(userId: String, deviceId: String): CryptoDeviceInfo? = withContext(Dispatchers.IO) {
|
||||
when (val device: Device? = inner.getDevice(userId, deviceId)) {
|
||||
null -> null
|
||||
else -> Device(device, inner)
|
||||
else -> toCryptoDeviceInfo(device)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,7 +415,7 @@ internal class OlmMachine(user_id: String, device_id: String, path: File, device
|
|||
* @return The list of Devices or an empty list if there aren't any.
|
||||
*/
|
||||
suspend fun getUserDevices(userId: String): List<CryptoDeviceInfo> {
|
||||
return inner.getUserDevices(userId).map { Device(it, inner).toCryptoDeviceInfo() }
|
||||
return inner.getUserDevices(userId).map { toCryptoDeviceInfo(it) }
|
||||
}
|
||||
|
||||
suspend fun getUserDevicesMap(userIds: List<String>): MXUsersDevicesMap<CryptoDeviceInfo> {
|
||||
|
|
Loading…
Reference in a new issue