From 19990b27bb3d2174aebb9dc030d3a4a365320e5f Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 26 Mar 2020 10:52:02 +0100 Subject: [PATCH] Code review --- .../android/internal/crypto/MXOlmDevice.kt | 27 +++++++++---------- .../internal/crypto/store/IMXCryptoStore.kt | 5 ++-- .../crypto/store/db/RealmCryptoStore.kt | 6 ++--- .../internal/crypto/tasks/UploadKeysTask.kt | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt index cad2e8a8a3..0f48b5ecfb 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt @@ -89,7 +89,6 @@ internal class MXOlmDevice @Inject constructor( Timber.e(e, "MXOlmDevice : cannot initialize olmAccount") } - try { olmUtility = OlmUtility() } catch (e: Exception) { @@ -98,13 +97,13 @@ internal class MXOlmDevice @Inject constructor( } try { - deviceCurve25519Key = store.getAccount().identityKeys()[OlmAccount.JSON_KEY_IDENTITY_KEY] + deviceCurve25519Key = store.getOlmAccount().identityKeys()[OlmAccount.JSON_KEY_IDENTITY_KEY] } catch (e: Exception) { Timber.e(e, "## MXOlmDevice : cannot find ${OlmAccount.JSON_KEY_IDENTITY_KEY} with error") } try { - deviceEd25519Key = store.getAccount().identityKeys()[OlmAccount.JSON_KEY_FINGER_PRINT_KEY] + deviceEd25519Key = store.getOlmAccount().identityKeys()[OlmAccount.JSON_KEY_FINGER_PRINT_KEY] } catch (e: Exception) { Timber.e(e, "## MXOlmDevice : cannot find ${OlmAccount.JSON_KEY_FINGER_PRINT_KEY} with error") } @@ -115,7 +114,7 @@ internal class MXOlmDevice @Inject constructor( */ fun getOneTimeKeys(): Map>? { try { - return store.getAccount().oneTimeKeys() + return store.getOlmAccount().oneTimeKeys() } catch (e: Exception) { Timber.e(e, "## getOneTimeKeys() : failed") } @@ -127,7 +126,7 @@ internal class MXOlmDevice @Inject constructor( * @return The maximum number of one-time keys the olm account can store. */ fun getMaxNumberOfOneTimeKeys(): Long { - return store.getAccount().maxOneTimeKeys() + return store.getOlmAccount().maxOneTimeKeys() } /** @@ -145,7 +144,7 @@ internal class MXOlmDevice @Inject constructor( */ fun signMessage(message: String): String? { try { - return store.getAccount().signMessage(message) + return store.getOlmAccount().signMessage(message) } catch (e: Exception) { Timber.e(e, "## signMessage() : failed") } @@ -158,8 +157,8 @@ internal class MXOlmDevice @Inject constructor( */ fun markKeysAsPublished() { try { - store.getAccount().markOneTimeKeysAsPublished() - store.saveAccount() + store.getOlmAccount().markOneTimeKeysAsPublished() + store.saveOlmAccount() } catch (e: Exception) { Timber.e(e, "## markKeysAsPublished() : failed") } @@ -172,8 +171,8 @@ internal class MXOlmDevice @Inject constructor( */ fun generateOneTimeKeys(numKeys: Int) { try { - store.getAccount().generateOneTimeKeys(numKeys) - store.saveAccount() + store.getOlmAccount().generateOneTimeKeys(numKeys) + store.saveOlmAccount() } catch (e: Exception) { Timber.e(e, "## generateOneTimeKeys() : failed") } @@ -193,7 +192,7 @@ internal class MXOlmDevice @Inject constructor( try { olmSession = OlmSession() - olmSession.initOutboundSession(store.getAccount(), theirIdentityKey, theirOneTimeKey) + olmSession.initOutboundSession(store.getOlmAccount(), theirIdentityKey, theirOneTimeKey) val olmSessionWrapper = OlmSessionWrapper(olmSession, 0) @@ -233,7 +232,7 @@ internal class MXOlmDevice @Inject constructor( try { try { olmSession = OlmSession() - olmSession.initInboundSessionFrom(store.getAccount(), theirDeviceIdentityKey, ciphertext) + olmSession.initInboundSessionFrom(store.getOlmAccount(), theirDeviceIdentityKey, ciphertext) } catch (e: Exception) { Timber.e(e, "## createInboundSession() : the session creation failed") return null @@ -242,8 +241,8 @@ internal class MXOlmDevice @Inject constructor( Timber.v("## createInboundSession() : sessionId: ${olmSession.sessionIdentifier()}") try { - store.getAccount().removeOneTimeKeys(olmSession) - store.saveAccount() + store.getOlmAccount().removeOneTimeKeys(olmSession) + store.saveOlmAccount() } catch (e: Exception) { Timber.e(e, "## createInboundSession() : removeOneTimeKeys failed") } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/IMXCryptoStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/IMXCryptoStore.kt index 85b6a0744c..726d56a2f7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/IMXCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/IMXCryptoStore.kt @@ -49,8 +49,7 @@ internal interface IMXCryptoStore { /** * @return the olm account */ - fun getAccount(): OlmAccount - + fun getOlmAccount(): OlmAccount fun getOrCreateOlmAccount(): OlmAccount @@ -162,7 +161,7 @@ internal interface IMXCryptoStore { * * @param account the account to save */ - fun saveAccount() + fun saveOlmAccount() /** * Store a device for a user. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt index 521f1df6a2..7f136df54d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/RealmCryptoStore.kt @@ -122,7 +122,6 @@ internal class RealmCryptoStore @Inject constructor( .setRealmConfiguration(realmConfiguration) .build() - init { // Ensure CryptoMetadataEntity is inserted in DB doRealmTransaction(realmConfiguration) { realm -> @@ -205,13 +204,13 @@ internal class RealmCryptoStore @Inject constructor( }?.deviceId ?: "" } - override fun saveAccount() { + override fun saveOlmAccount() { doRealmTransaction(realmConfiguration) { it.where().findFirst()?.putOlmAccount(olmAccount) } } - override fun getAccount(): OlmAccount { + override fun getOlmAccount(): OlmAccount { return olmAccount!! } @@ -232,7 +231,6 @@ internal class RealmCryptoStore @Inject constructor( return olmAccount!! } - override fun storeUserDevice(userId: String?, deviceInfo: CryptoDeviceInfo?) { if (userId == null || deviceInfo == null) { return diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt index db8d4ccfde..6574132c7f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/tasks/UploadKeysTask.kt @@ -51,7 +51,7 @@ internal class DefaultUploadKeysTask @Inject constructor( oneTimeKeys = params.oneTimeKeys ) - Timber.i("## Uploading device keys -> ${body}") + Timber.i("## Uploading device keys -> $body") return executeRequest(eventBus) { apiCall = if (encodedDeviceId.isBlank()) {