From 6c5da97c162202072f2abf77e03e72bf0759aad1 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 7 Apr 2020 15:25:31 +0200 Subject: [PATCH] code review --- .../internal/crypto/DefaultCryptoService.kt | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt index 3ddbf32ee7..ee96e45e85 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt @@ -240,7 +240,7 @@ internal class DefaultCryptoService @Inject constructor( override fun getDevicesList(callback: MatrixCallback) { getDevicesTask .configureWith { -// this.executionThread = TaskThread.CRYPTO + // this.executionThread = TaskThread.CRYPTO this.callback = callback } .executeBy(taskExecutor) @@ -636,7 +636,7 @@ internal class DefaultCryptoService @Inject constructor( */ @Throws(MXCryptoError::class) override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult { - return internalDecryptEvent(event, timeline) + return internalDecryptEvent(event, timeline) } /** @@ -767,23 +767,30 @@ internal class DefaultCryptoService @Inject constructor( return } - when (existingRequest.secretName) { + if (!handleSDKLevelGossip(existingRequest.secretName, secretContent.secretValue)) { + // TODO Ask to application layer? + Timber.v("## onSecretSend() : secret not handled by SDK") + } + } + + /** + * Returns true if handled by SDK, otherwise should be sent to application layer + */ + private fun handleSDKLevelGossip(secretName: String?, secretValue: String): Boolean { + return when (secretName) { SELF_SIGNING_KEY_SSSS_NAME -> { - crossSigningService.onSecretSSKGossip(secretContent.secretValue) - return + crossSigningService.onSecretSSKGossip(secretValue) + true } USER_SIGNING_KEY_SSSS_NAME -> { - crossSigningService.onSecretUSKGossip(secretContent.secretValue) - return + crossSigningService.onSecretUSKGossip(secretValue) + true } KEYBACKUP_SECRET_SSSS_NAME -> { - keysBackupService.onSecretKeyGossip(secretContent.secretValue) - return - } - else -> { - // Ask to application layer? - Timber.v("## onSecretSend() : secret not handled by SDK") + keysBackupService.onSecretKeyGossip(secretValue) + true } + else -> false } }