From 8051d9e3be792356bbc752d9e26ad1efcb95d114 Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 12 Mar 2020 16:09:41 +0100 Subject: [PATCH] cleaning --- .../crypto/gossiping/KeyShareTests.kt | 11 --- .../crypto/IncomingRoomKeyRequestManager.kt | 12 +-- .../internal/crypto/ShareRequestState.kt | 79 ------------------- .../internal/crypto/store/IMXCryptoStore.kt | 36 --------- .../crypto/store/db/RealmCryptoStore.kt | 6 +- .../model/OutgoingGossipingRequestEntity.kt | 6 +- 6 files changed, 15 insertions(+), 135 deletions(-) delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareRequestState.kt diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/gossiping/KeyShareTests.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/gossiping/KeyShareTests.kt index 01f6ab0f22..1dc0907b65 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/gossiping/KeyShareTests.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/gossiping/KeyShareTests.kt @@ -48,17 +48,6 @@ class KeyShareTests : InstrumentedTest { private val mTestHelper = CommonTestHelper(context()) -// @Before -// fun setup() { -// mockkStatic(Log::class) -// every { Log.v(any(), any()) } returns 0 -// every { Log.d(any(), any()) } returns 0 -// every { Log.i(any(), any()) } returns 0 -// every { Log.e(any(), any()) } returns 0 -// // every { Log.println(any(), any(), any()) } returns 0 -// // every { Log.wtf(any(), any(), any()) } returns 0 -// } - @Test fun test_DoNotSelfShareIfNotTrusted() { val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true)) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt index b1de344d03..0bb89154f1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/IncomingRoomKeyRequestManager.kt @@ -41,14 +41,14 @@ internal class IncomingRoomKeyRequestManager @Inject constructor( // list of IncomingRoomKeyRequests/IncomingRoomKeyRequestCancellations // we received in the current sync. - private val receiveGossipingRequests = ArrayList() + private val receivedGossipingRequests = ArrayList() private val receivedRequestCancellations = ArrayList() // the listeners private val gossipingRequestListeners: MutableSet = HashSet() init { - receiveGossipingRequests.addAll(cryptoStore.getPendingIncomingGossipingRequests()) + receivedGossipingRequests.addAll(cryptoStore.getPendingIncomingGossipingRequests()) } /** @@ -71,7 +71,7 @@ internal class IncomingRoomKeyRequestManager @Inject constructor( } else { // save in DB cryptoStore.storeIncomingGossipingRequest(it, ageLocalTs) - receiveGossipingRequests.add(it) + receivedGossipingRequests.add(it) } } } else if (event.getClearType() == EventType.ROOM_KEY_REQUEST) { @@ -81,7 +81,7 @@ internal class IncomingRoomKeyRequestManager @Inject constructor( Timber.v("## onGossipingRequestEvent type ${event.type} ignore remote echo") } else { cryptoStore.storeIncomingGossipingRequest(it, ageLocalTs) - receiveGossipingRequests.add(it) + receivedGossipingRequests.add(it) } } } @@ -105,8 +105,8 @@ internal class IncomingRoomKeyRequestManager @Inject constructor( fun processReceivedGossipingRequests() { Timber.v("## processReceivedGossipingRequests()") - val roomKeyRequestsToProcess = receiveGossipingRequests.toList() - receiveGossipingRequests.clear() + val roomKeyRequestsToProcess = receivedGossipingRequests.toList() + receivedGossipingRequests.clear() for (request in roomKeyRequestsToProcess) { if (request is IncomingRoomKeyRequest) { processIncomingRoomKeyRequest(request) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareRequestState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareRequestState.kt deleted file mode 100644 index 7d3ff72e9b..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/ShareRequestState.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2020 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.matrix.android.internal.crypto - -/** - * possible states for a room key request - * - * - * The state machine looks like: - *
- *
- *      |
- *      V
- *    UNSENT  -----------------------------+
- *      |                                  |
- *      | (send successful)                | (cancellation requested)
- *      V                                  |
- *     SENT                                |
- *      |--------------------------------  |  --------------+
- *      |                                  |                |
- *      |                                  |                | (cancellation requested with intent
- *      |                                  |                | to resend a new request)
- *      | (cancellation requested)         |                |
- *      V                                  |                V
- *  CANCELLATION_PENDING                   | CANCELLATION_PENDING_AND_WILL_RESEND
- *      |                                  |                |
- *      | (cancellation sent)              |                | (cancellation sent. Create new request
- *      |                                  |                |  in the UNSENT state)
- *      V                                  |                |
- *  (deleted)  <---------------------------+----------------+
- *  
- */ - -enum class ShareRequestState { - /** - * request not yet sent - */ - UNSENT, - /** - * request sent, awaiting reply - */ - SENT, - /** - * reply received, cancellation not yet sent - */ - CANCELLATION_PENDING, - /** - * Cancellation not yet sent, once sent, a new request will be done - */ - CANCELLATION_PENDING_AND_WILL_RESEND, - /** - * sending failed - */ - FAILED; - - companion object { - fun from(state: Int) = when (state) { - 0 -> UNSENT - 1 -> SENT - 2 -> CANCELLATION_PENDING - 3 -> CANCELLATION_PENDING_AND_WILL_RESEND - else /*4*/ -> 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 5f118ff695..29efc02fdb 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 @@ -361,42 +361,6 @@ internal interface IMXCryptoStore { fun getOrAddOutgoingSecretShareRequest(secretName: String, recipients: Map>): OutgoingSecretRequest? fun saveGossipingEvent(event: Event) - /** - * Look for room key requests by state. - * - * @param states the states - * @return an OutgoingRoomKeyRequest or null - */ -// fun getOutgoingRoomKeyRequestByState(states: Set): OutgoingRoomKeyRequest? -// fun getOutgoingSecretShareRequestByState(states: Set): OutgoingSecretRequest? - - /** - * Update an existing outgoing request. - * - * @param request the request - */ -// fun updateOutgoingRoomKeyRequest(request: OutgoingRoomKeyRequest) - - /** - * Delete an outgoing room key request. - * - * @param transactionId the transaction id. - */ -// fun deleteOutgoingRoomKeyRequest(transactionId: String) - - /** - * Store an incomingRoomKeyRequest instance - * - * @param incomingRoomKeyRequest the incoming key request - */ -// fun storeIncomingRoomKeyRequest(incomingRoomKeyRequest: IncomingRoomKeyRequest?) - - /** - * Delete an incomingRoomKeyRequest instance - * - * @param incomingRoomKeyRequest the incoming key request - */ -// fun deleteIncomingRoomKeyRequest(incomingRoomKeyRequest: IncomingShareRequestCommon) fun updateGossipingRequestState(request: IncomingShareRequestCommon, state: GossipingRequestState) 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 d4e188b048..542b8a25de 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 @@ -1240,7 +1240,8 @@ internal class RealmCryptoStore @Inject constructor( .equalTo(OutgoingGossipingRequestEntityFields.TYPE_STR, GossipRequestType.KEY.name) }, { entity -> entity.toOutgoingGossipingRequest() as? OutgoingRoomKeyRequest - }).filterNotNull() + }) + .filterNotNull() } override fun getOutgoingSecretKeyRequests(): List { @@ -1250,7 +1251,8 @@ internal class RealmCryptoStore @Inject constructor( .equalTo(OutgoingGossipingRequestEntityFields.TYPE_STR, GossipRequestType.SECRET.name) }, { entity -> entity.toOutgoingGossipingRequest() as? OutgoingSecretRequest - }).filterNotNull() + }) + .filterNotNull() } override fun getCrossSigningInfo(userId: String): MXCrossSigningInfo? { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt index 4a14ad3baa..19049c099c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt @@ -66,7 +66,11 @@ internal open class OutgoingGossipingRequestEntity( companion object { private val recipientsDataMapper: JsonAdapter>> = - MoshiProvider.providesMoshi().adapter>>(Types.newParameterizedType(Map::class.java, String::class.java, List::class.java)) + MoshiProvider + .providesMoshi() + .adapter>>( + Types.newParameterizedType(Map::class.java, String::class.java, List::class.java) + ) } fun toOutgoingGossipingRequest(): OutgoingGossipingRequest {