From f01e2460e1acc809e2b00d0bacec5d19dd364c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 11 Feb 2021 12:01:49 +0100 Subject: [PATCH] crypto: Enable the use of unsigned ints for now and update the bindings wrapper --- build.gradle | 1 + .../sdk/internal/crypto/DefaultCryptoService.kt | 15 ++++++++++----- .../org/matrix/android/sdk/internal/newCrypto.kt | 14 +++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 625ed348be..370006d1c9 100644 --- a/build.gradle +++ b/build.gradle @@ -70,6 +70,7 @@ allprojects { // Warnings are potential errors, so stop ignoring them // You can override by passing `-PallWarningsAsErrors=false` in the command line kotlinOptions.allWarningsAsErrors = project.getProperties().getOrDefault("allWarningsAsErrors", "true").toBoolean() + kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes" } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index d230008b71..257f1c9a05 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -84,6 +84,7 @@ import org.matrix.android.sdk.internal.crypto.tasks.UploadKeysTask import org.matrix.android.sdk.internal.crypto.verification.DefaultVerificationService import org.matrix.android.sdk.internal.di.DeviceId import org.matrix.android.sdk.internal.di.MoshiProvider +import org.matrix.android.sdk.internal.di.SessionFilesDirectory import org.matrix.android.sdk.internal.di.UserId import org.matrix.android.sdk.internal.extensions.foldToCallback import org.matrix.android.sdk.internal.session.SessionScope @@ -97,6 +98,7 @@ import org.matrix.android.sdk.internal.util.JsonCanonicalizer import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers import org.matrix.olm.OlmManager import timber.log.Timber +import java.io.File import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject import kotlin.jvm.Throws @@ -120,6 +122,8 @@ internal class DefaultCryptoService @Inject constructor( private val userId: String, @DeviceId private val deviceId: String?, + @SessionFilesDirectory + private val dataDir: File, private val myDeviceInfoHolder: Lazy, // the crypto store private val cryptoStore: IMXCryptoStore, @@ -171,6 +175,7 @@ internal class DefaultCryptoService @Inject constructor( private val isStarting = AtomicBoolean(false) private val isStarted = AtomicBoolean(false) + private var olmMachine: OlmMachine? = null fun onStateEvent(roomId: String, event: Event) { when (event.getClearType()) { @@ -310,7 +315,7 @@ internal class DefaultCryptoService @Inject constructor( * devices. * */ - fun start() { + suspend fun start() { cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { internalStart() } @@ -363,14 +368,14 @@ internal class DefaultCryptoService @Inject constructor( return } isStarting.set(true) + Timber.v("HELLLO WORLD STARTING CRYPTO") + try { - val dataDir = "/data/data/im.vector.app.debug/files" - val olmMachine = OlmMachine("@example:localhost", "DEVICEID", dataDir) - Timber.v("HELLLO WORLD STARTING CRYPTO ${olmMachine.identityKeys()}") + olmMachine = OlmMachine(userId, deviceId!!, dataDir) + Timber.v("HELLLO WORLD STARTING CRYPTO ${olmMachine?.identityKeys()}") } catch (throwable: Throwable) { Timber.v("HELLLO WORLD FAILED CRYPTO $throwable") } - Timber.v("HELLLO WORLD STARTING CRYPTO") // Open the store cryptoStore.open() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt index e48bc0f1f7..2e1308f4b6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/newCrypto.kt @@ -16,11 +16,11 @@ package org.matrix.android.sdk.internal -import kotlinx.coroutines.withContext +import java.io.File import kotlinx.coroutines.Dispatchers - -import uniffi.olm.OlmMachine as InnerMachine +import kotlinx.coroutines.withContext import uniffi.olm.Device as InnerDevice +import uniffi.olm.OlmMachine as InnerMachine import uniffi.olm.Sas as InnerSas class Device(inner: InnerDevice, machine: InnerMachine) { @@ -44,8 +44,8 @@ class Device(inner: InnerDevice, machine: InnerMachine) { } } -class OlmMachine(user_id: String, device_id: String, path: String) { - private val inner: InnerMachine = InnerMachine(user_id, device_id, path) +class OlmMachine(user_id: String, device_id: String, path: File) { + private val inner: InnerMachine = InnerMachine(user_id, device_id, path.toString()) fun userId(): String { return this.inner.userId() @@ -59,10 +59,6 @@ class OlmMachine(user_id: String, device_id: String, path: String) { return this.inner.identityKeys() } - suspend fun slowUserId(): String = withContext(Dispatchers.Default) { - inner.slowUserId() - } - suspend fun getDevice(user_id: String, device_id: String): Device? = withContext(Dispatchers.IO) { when (val device: InnerDevice? = inner.getDevice(user_id, device_id)) { null -> null