Skip to content

Commit f989eed

Browse files
committed
Use @throws(MXCryptoError::class)
1 parent 4d296dd commit f989eed

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ internal class DefaultCryptoService @Inject constructor(
661661
* @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack.
662662
* @return the MXEventDecryptionResult data, or null in case of error
663663
*/
664+
@Throws(MXCryptoError::class)
664665
private fun internalDecryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
665666
val eventContent = event.content
666667
if (eventContent == null) {

matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/MXOlmDevice.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ internal class MXOlmDevice @Inject constructor(
625625
* @param senderKey the base64-encoded curve25519 key of the sender.
626626
* @return the decrypting result. Nil if the sessionId is unknown.
627627
*/
628+
@Throws(MXCryptoError::class)
628629
fun decryptGroupMessage(body: String,
629630
roomId: String,
630631
timeline: String?,
@@ -662,8 +663,7 @@ internal class MXOlmDevice @Inject constructor(
662663
adapter.fromJson(payloadString)
663664
} catch (e: Exception) {
664665
Timber.e("## decryptGroupMessage() : fails to parse the payload")
665-
throw
666-
MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON)
666+
throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON)
667667
}
668668

669669
return OlmDecryptionResult(

matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/IMXDecrypting.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package im.vector.matrix.android.internal.crypto.algorithms
1919

20+
import im.vector.matrix.android.api.session.crypto.MXCryptoError
2021
import im.vector.matrix.android.api.session.events.model.Event
2122
import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequest
2223
import im.vector.matrix.android.internal.crypto.IncomingSecretShareRequest
@@ -35,6 +36,7 @@ internal interface IMXDecrypting {
3536
* @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack.
3637
* @return the decryption information, or an error
3738
*/
39+
@Throws(MXCryptoError::class)
3840
fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult
3941

4042
/**

matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/megolm/MXMegolmDecryption.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ internal class MXMegolmDecryption(private val userId: String,
6363
*/
6464
private var pendingEvents: MutableMap<String /* senderKey|sessionId */, MutableMap<String /* timelineId */, MutableList<Event>>> = HashMap()
6565

66+
@Throws(MXCryptoError::class)
6667
override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
6768
// If cross signing is enabled, we don't send request until the keys are trusted
6869
// There could be a race effect here when xsigning is enabled, we should ensure that keys was downloaded once
6970
val requestOnFail = cryptoStore.getMyCrossSigningInfo()?.isTrusted() == true
7071
return decryptEvent(event, timeline, requestOnFail)
7172
}
7273

74+
@Throws(MXCryptoError::class)
7375
private fun decryptEvent(event: Event, timeline: String, requestKeysOnFail: Boolean): MXEventDecryptionResult {
7476
if (event.roomId.isNullOrBlank()) {
7577
throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)

matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/algorithms/olm/MXOlmDecryption.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ internal class MXOlmDecryption(
3838
private val userId: String)
3939
: IMXDecrypting {
4040

41+
@Throws(MXCryptoError::class)
4142
override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
4243
val olmEventContent = event.content.toModel<OlmEventContent>() ?: run {
4344
Timber.e("## decryptEvent() : bad event format")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2020 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package im.vector.matrix.android.internal.crypto.model.rest
17+
18+
/**
19+
* Class representing the dummy content
20+
* Ref: https://matrix.org/docs/spec/client_server/latest#id82
21+
*/
22+
typealias DummyContent = Unit

0 commit comments

Comments
 (0)