crypto: Remove the myDeviceInfoHolder

This commit is contained in:
Damir Jelić 2021-03-26 16:01:01 +01:00
parent d49bdbe016
commit 32cf645c5f
2 changed files with 40 additions and 2 deletions

View File

@ -130,7 +130,6 @@ internal class DefaultCryptoService @Inject constructor(
private val deviceId: String?,
@SessionFilesDirectory
private val dataDir: File,
private val myDeviceInfoHolder: Lazy<MyDeviceInfoHolder>,
// the crypto store
private val cryptoStore: IMXCryptoStore,
// Set of parameters used to configure/customize the end-to-end crypto.
@ -218,7 +217,7 @@ internal class DefaultCryptoService @Inject constructor(
}
override fun getMyDevice(): CryptoDeviceInfo {
return myDeviceInfoHolder.get().myDevice
return olmMachine!!.ownDevice()
}
override fun fetchDevicesList(callback: MatrixCallback<DevicesListResponse>) {

View File

@ -27,6 +27,9 @@ import org.matrix.android.sdk.internal.di.MoshiProvider
import org.matrix.android.sdk.internal.session.sync.model.DeviceListResponse
import org.matrix.android.sdk.internal.session.sync.model.DeviceOneTimeKeysCountSyncResponse
import org.matrix.android.sdk.internal.session.sync.model.ToDeviceSyncResponse
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel
import org.matrix.android.sdk.internal.crypto.model.rest.UnsignedDeviceInfo
import org.matrix.android.sdk.api.session.events.model.Content
import timber.log.Timber
import uniffi.olm.Device as InnerDevice
@ -67,6 +70,26 @@ class Device(inner: InnerDevice, machine: InnerMachine) {
fun startVerification(): InnerSas {
return this.machine.startVerification(this.inner)
}
fun toCryptoDeviceInfo(): CryptoDeviceInfo {
return CryptoDeviceInfo(
this.deviceId(),
this.userId(),
// TODO pass the algorithms here.
listOf(),
this.keys(),
// TODO pass the signatures here.
mapOf(),
// TODO pass the display name here.
UnsignedDeviceInfo(),
// TODO pass trust levels here
DeviceTrustLevel(false, false),
// TODO is the device blacklisted
false,
// TODO
null
)
}
}
internal class OlmMachine(user_id: String, device_id: String, path: File) {
@ -84,6 +107,22 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) {
return this.inner.identityKeys()
}
fun ownDevice(): CryptoDeviceInfo {
return CryptoDeviceInfo(
this.deviceId(),
this.userId(),
// TODO pass the algorithms here.
listOf(),
this.identityKeys(),
mapOf(),
UnsignedDeviceInfo(),
DeviceTrustLevel(false, true),
false,
null
)
}
suspend fun outgoingRequests(): List<Request> = withContext(Dispatchers.IO) {
inner.outgoingRequests()
}