From 6e371b7d2d7d152d86cbce291e1b1e6317d6fe1b Mon Sep 17 00:00:00 2001 From: valere Date: Wed, 30 Nov 2022 16:01:11 +0100 Subject: [PATCH] code quality --- .../crypto/crosssigning/CrossSigningService.kt | 12 ++++++------ .../session/crypto/keysbackup/KeysBackupService.kt | 2 -- .../api/session/crypto/model/ImportRoomKeysResult.kt | 2 +- .../android/sdk/internal/crypto/api/CryptoApi.kt | 2 +- .../sdk/internal/crypto/RustCrossSigningService.kt | 8 ++++---- .../crypto/verification/VerificationRequest.kt | 11 +++-------- .../setup/KeysBackupSetupSharedViewModel.kt | 1 + .../verification/user/UserVerificationBottomSheet.kt | 2 +- 8 files changed, 17 insertions(+), 23 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/crosssigning/CrossSigningService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/crosssigning/CrossSigningService.kt index 0ccc752574..8c9be3fd78 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/crosssigning/CrossSigningService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/crosssigning/CrossSigningService.kt @@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.util.Optional interface CrossSigningService { /** - * Is our own device signed by our own cross signing identity + * Is our own device signed by our own cross signing identity. */ suspend fun isCrossSigningVerified(): Boolean @@ -62,7 +62,7 @@ interface CrossSigningService { sskPrivateKey: String?): UserTrustResult /** - * Get the public cross signing keys for the given user + * Get the public cross signing keys for the given user. * * @param otherUserId The ID of the user for which we would like to fetch the cross signing keys. */ @@ -70,10 +70,10 @@ interface CrossSigningService { fun getLiveCrossSigningKeys(userId: String): LiveData> - /** Get our own public cross signing keys */ + /** Get our own public cross signing keys. */ suspend fun getMyCrossSigningKeys(): MXCrossSigningInfo? - /** Get our own private cross signing keys */ + /** Get our own private cross signing keys. */ suspend fun getCrossSigningPrivateKeys(): PrivateKeysInfo? fun getLiveCrossSigningPrivateKeys(): LiveData> @@ -88,10 +88,10 @@ interface CrossSigningService { /** Do we have all our private cross signing keys in storage? */ fun allPrivateKeysKnown(): Boolean - /** Mark a user identity as trusted and sign and upload signatures of our user-signing key to the server */ + /** Mark a user identity as trusted and sign and upload signatures of our user-signing key to the server. */ suspend fun trustUser(otherUserId: String) - /** Mark our own master key as trusted */ + /** Mark our own master key as trusted. */ suspend fun markMyMasterKeyAsTrusted() /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupService.kt index 194f1891f0..4a7fe277c8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupService.kt @@ -107,7 +107,6 @@ interface KeysBackupService { * @param password an optional passphrase string that can be entered by the user * when restoring the backup as an alternative to entering the recovery key. * @param progressListener a progress listener, as generating private key from password may take a while - * @param callback Asynchronous callback */ suspend fun prepareKeysBackupVersion(password: String?, progressListener: ProgressListener?): MegolmBackupCreationInfo @@ -165,7 +164,6 @@ interface KeysBackupService { * @param roomId the id of the room to get backup data from. * @param sessionId the id of the session to restore. * @param stepProgressListener the step progress listener - * @param callback Callback. It provides the number of found keys and the number of successfully imported keys. */ suspend fun restoreKeysWithRecoveryKey( keysVersionResult: KeysVersionResult, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/model/ImportRoomKeysResult.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/model/ImportRoomKeysResult.kt index 7ef475bba1..b273215e5a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/model/ImportRoomKeysResult.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/model/ImportRoomKeysResult.kt @@ -19,6 +19,6 @@ package org.matrix.android.sdk.api.session.crypto.model data class ImportRoomKeysResult( val totalNumberOfKeys: Int, val successfullyNumberOfImportedKeys: Int, - /**It's a map from room id to a map of the sender key to a list of session*/ + /* It's a map from room id to a map of the sender key to a list of session. */ val importedSessionInfo: Map>> ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt index b7a46fb48f..d496d14780 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/api/CryptoApi.kt @@ -56,7 +56,7 @@ internal interface CryptoApi { suspend fun getDeviceInfo(@Path("deviceId") deviceId: String): DeviceInfo /** - * Upload device and one-time keys + * Upload device and one-time keys. * @param body the keys to be sent. */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "keys/upload") diff --git a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt index ac071beae7..d008b09bbc 100644 --- a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt +++ b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCrossSigningService.kt @@ -109,12 +109,12 @@ internal class RustCrossSigningService @Inject constructor( return olmMachine.getLiveUserIdentity(userId) } - /** Get our own public cross signing keys */ + /** Get our own public cross signing keys. */ override suspend fun getMyCrossSigningKeys(): MXCrossSigningInfo? { return getUserCrossSigningKeys(olmMachine.userId()) } - /** Get our own private cross signing keys */ + /** Get our own private cross signing keys. */ override suspend fun getCrossSigningPrivateKeys(): PrivateKeysInfo? { return olmMachine.exportCrossSigningKeys() } @@ -140,7 +140,7 @@ internal class RustCrossSigningService @Inject constructor( return status.hasMaster && status.hasSelfSigning && status.hasUserSigning } - /** Mark a user identity as trusted and sign and upload signatures of our user-signing key to the server */ + /** Mark a user identity as trusted and sign and upload signatures of our user-signing key to the server. */ override suspend fun trustUser(otherUserId: String) { // This is only used in a test val userIdentity = olmMachine.getIdentity(otherUserId) @@ -151,7 +151,7 @@ internal class RustCrossSigningService @Inject constructor( } } - /** Mark our own master key as trusted */ + /** Mark our own master key as trusted. */ override suspend fun markMyMasterKeyAsTrusted() { // This doesn't seem to be used? trustUser(olmMachine.userId()) diff --git a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationRequest.kt b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationRequest.kt index 34e05f436a..f4e991b75c 100644 --- a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationRequest.kt +++ b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationRequest.kt @@ -197,7 +197,7 @@ internal class VerificationRequest @AssistedInject constructor( requestSender.sendVerificationRequest(result.request) sasVerificationFactory.create(result.sas) } catch (failure: Throwable) { - cancel(CancelCode.UserError) + cancel() null } } @@ -225,7 +225,7 @@ internal class VerificationRequest @AssistedInject constructor( try { requestSender.sendVerificationRequest(result.request) } catch (failure: Throwable) { - cancel(CancelCode.UserError) + cancel() return null } return qrCodeVerificationFactory.create(result.qr) @@ -241,14 +241,9 @@ internal class VerificationRequest @AssistedInject constructor( * * The method turns into a noop, if the verification flow has already been cancelled. */ - internal suspend fun cancel(cancelCode: CancelCode = CancelCode.User) = withContext(NonCancellable) { + internal suspend fun cancel() = withContext(NonCancellable) { // TODO damir how to add the code? val request = innerVerificationRequest.cancel() ?: return@withContext -// val request = innerOlmMachine.cancelVerification( -// innerVerificationRequest.otherUserId, -// innerVerificationRequest.flowId, -// cancelCode.value -// ) ?: return@withContext dispatchRequestUpdated() tryOrNull("Fail to send cancel request") { requestSender.sendVerificationRequest(request, retryCount = Int.MAX_VALUE) diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupSharedViewModel.kt index a7a462de02..72a071bd0f 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupSharedViewModel.kt @@ -168,6 +168,7 @@ class KeysBackupSetupSharedViewModel @Inject constructor( navigateEvent.postValue(LiveEvent(NAVIGATE_PROMPT_REPLACE)) } } catch (failure: Throwable) { + Timber.w(failure, "Failed to createKeysBackup") } } } diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationBottomSheet.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationBottomSheet.kt index b13261b7b0..658eda8468 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationBottomSheet.kt @@ -40,7 +40,7 @@ import javax.inject.Inject import kotlin.reflect.KClass /** - * Specific to other users verification (not self verification) + * Specific to other users verification (not self verification). */ @AndroidEntryPoint class UserVerificationBottomSheet : VectorBaseBottomSheetDialogFragment() {