2
2
3
3
use std:: sync:: Arc ;
4
4
5
- use anyhow:: anyhow;
6
5
use js_sys:: { Array , JsString } ;
7
6
pub ( crate ) use matrix_sdk_common:: ruma:: api:: client:: {
8
7
backup:: add_backup_keys:: v3:: Response as KeysBackupResponse ,
@@ -19,6 +18,7 @@ use matrix_sdk_common::{
19
18
ruma:: { self , api:: IncomingResponse as RumaIncomingResponse } ,
20
19
} ;
21
20
use matrix_sdk_crypto:: types:: requests:: AnyIncomingResponse ;
21
+ use thiserror:: Error ;
22
22
use wasm_bindgen:: prelude:: * ;
23
23
24
24
use crate :: { encryption, identifiers, requests:: RequestType } ;
@@ -216,7 +216,7 @@ impl DecryptedRoomEvent {
216
216
}
217
217
218
218
impl TryFrom < matrix_sdk_common:: deserialized_responses:: TimelineEvent > for DecryptedRoomEvent {
219
- type Error = anyhow :: Error ;
219
+ type Error = UnsupportedAlgorithmError ;
220
220
221
221
fn try_from (
222
222
value : matrix_sdk_common:: deserialized_responses:: TimelineEvent ,
@@ -288,7 +288,7 @@ impl EncryptionInfo {
288
288
}
289
289
290
290
impl TryFrom < Arc < matrix_sdk_common:: deserialized_responses:: EncryptionInfo > > for EncryptionInfo {
291
- type Error = anyhow :: Error ;
291
+ type Error = UnsupportedAlgorithmError ;
292
292
293
293
fn try_from (
294
294
value : Arc < matrix_sdk_common:: deserialized_responses:: EncryptionInfo > ,
@@ -306,8 +306,8 @@ impl TryFrom<Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>> for
306
306
verification_state : value. verification_state . clone ( ) ,
307
307
} )
308
308
}
309
- AlgorithmInfo :: OlmV1Curve25519AesSha2 { .. } => Err ( anyhow ! (
310
- "AlgorithmInfo::OlmV1Curve25519AesSha2 is not applicable for room event EncryptionInfo" ,
309
+ AlgorithmInfo :: OlmV1Curve25519AesSha2 { .. } => Err ( UnsupportedAlgorithmError (
310
+ "AlgorithmInfo::OlmV1Curve25519AesSha2 is not applicable for room event EncryptionInfo" . to_owned ( )
311
311
) ) ,
312
312
}
313
313
}
@@ -344,14 +344,15 @@ pub struct ToDeviceEncryptionInfo {
344
344
}
345
345
346
346
impl TryFrom < matrix_sdk_common:: deserialized_responses:: EncryptionInfo > for ToDeviceEncryptionInfo {
347
- type Error = anyhow :: Error ;
347
+ type Error = UnsupportedAlgorithmError ;
348
348
349
349
fn try_from (
350
350
value : matrix_sdk_common:: deserialized_responses:: EncryptionInfo ,
351
351
) -> Result < Self , Self :: Error > {
352
352
match & value. algorithm_info {
353
- AlgorithmInfo :: MegolmV1AesSha2 { .. } => Err ( anyhow ! (
354
- "AlgorithmInfo::MegolmV1AesSha2 is not applicable for ToDeviceEncryptionInfo" ,
353
+ AlgorithmInfo :: MegolmV1AesSha2 { .. } => Err ( UnsupportedAlgorithmError (
354
+ "AlgorithmInfo::MegolmV1AesSha2 is not applicable for ToDeviceEncryptionInfo"
355
+ . to_owned ( ) ,
355
356
) ) ,
356
357
AlgorithmInfo :: OlmV1Curve25519AesSha2 { curve25519_public_key_base64 } => Ok ( Self {
357
358
sender_curve25519_key_base64 : curve25519_public_key_base64. clone ( ) ,
@@ -375,3 +376,11 @@ impl ToDeviceEncryptionInfo {
375
376
)
376
377
}
377
378
}
379
+
380
+ /// Error type returned when converting
381
+ /// [`matrix_sdk_common::deserialized_responses::EncryptionInfo`] to one of our
382
+ /// own types: the `algorithm_info` on the `EncryptionInfo` was of an unexpected
383
+ /// type.
384
+ #[ derive( Error , Debug ) ]
385
+ #[ error( "{0}" ) ]
386
+ pub struct UnsupportedAlgorithmError ( String ) ;
0 commit comments