Skip to content

Commit ae223fa

Browse files
committed
Bump SDK to 0f73ffde
This includes matrix-org/matrix-rust-sdk#5074, which adds an `OlmV1Curve25519AesSha2` variant to `AlgorithmInfo`, meaning some conversions are now fallible.
1 parent 02c61cd commit ae223fa

File tree

6 files changed

+72
-43
lines changed

6 files changed

+72
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# UNRELEASED
22

3-
- Update matrix-rusk-sdk to `022068996`, which includes:
3+
- Update matrix-rusk-sdk to `0f73ffde6`, which includes:
44

55
- Send stable identifier `sender_device_keys` for MSC4147 (Including device
66
keys with Olm-encrypted events).

Cargo.lock

Lines changed: 23 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ futures-util = "0.3.27"
6565
getrandom = { version = "0.3.0", features = ["wasm_js"] }
6666
http = "1.1.0"
6767
js-sys = "0.3.49"
68-
matrix-sdk-common = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "022068996", features = ["js"] }
69-
matrix-sdk-indexeddb = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "022068996", default-features = false, features = ["e2e-encryption"] }
70-
matrix-sdk-qrcode = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "022068996", optional = true }
68+
matrix-sdk-common = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0f73ffde6", features = ["js"] }
69+
matrix-sdk-indexeddb = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0f73ffde6", default-features = false, features = ["e2e-encryption"] }
70+
matrix-sdk-qrcode = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "0f73ffde6", optional = true }
7171
serde = "1.0.91"
7272
serde_json = "1.0.91"
7373
serde-wasm-bindgen = "0.6.5"
@@ -84,7 +84,7 @@ vergen-gitcl = { version = "1.0.0", features = ["build"] }
8484

8585
[dependencies.matrix-sdk-crypto]
8686
git = "https://github.com/matrix-org/matrix-rust-sdk"
87-
rev = "022068996"
87+
rev = "0f73ffde6"
8888
default-features = false
8989
features = ["js", "automatic-room-key-forwarding"]
9090

src/machine.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,14 @@ impl OlmMachine {
512512
.await
513513
.map_err(MegolmDecryptionError::from)?
514514
.into();
515-
Ok(responses::DecryptedRoomEvent::from(room_event))
515+
516+
responses::DecryptedRoomEvent::try_from(room_event).map_err(|e: anyhow::Error| {
517+
// This happens if we somehow encounter a room event whose encryption info we
518+
// don't understand (e.g., it is encrypted with Olm rather than
519+
// Megolm). That seems pretty unlikely. If it happens, let's
520+
// just treat it as a generic UTD.
521+
MegolmDecryptionError::unable_to_decrypt(format!("{e:#}"))
522+
})
516523
}))
517524
}
518525

@@ -545,7 +552,7 @@ impl OlmMachine {
545552
Ok(future_to_promise(async move {
546553
let encryption_info =
547554
me.get_room_event_encryption_info(&event, room_id.as_ref()).await?;
548-
Ok(responses::EncryptionInfo::from(encryption_info))
555+
Ok(responses::EncryptionInfo::try_from(encryption_info)?)
549556
}))
550557
}
551558

src/responses.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::sync::Arc;
44

5+
use anyhow::anyhow;
56
use js_sys::{Array, JsString};
67
pub(crate) use matrix_sdk_common::ruma::api::client::{
78
backup::add_backup_keys::v3::Response as KeysBackupResponse,
@@ -214,12 +215,18 @@ impl DecryptedRoomEvent {
214215
}
215216
}
216217

217-
impl From<matrix_sdk_common::deserialized_responses::TimelineEvent> for DecryptedRoomEvent {
218-
fn from(value: matrix_sdk_common::deserialized_responses::TimelineEvent) -> Self {
219-
Self {
220-
event: value.raw().json().get().to_owned().into(),
221-
encryption_info: value.encryption_info().map(|e| e.clone().into()),
222-
}
218+
impl TryFrom<matrix_sdk_common::deserialized_responses::TimelineEvent> for DecryptedRoomEvent {
219+
type Error = anyhow::Error;
220+
221+
fn try_from(
222+
value: matrix_sdk_common::deserialized_responses::TimelineEvent,
223+
) -> Result<Self, Self::Error> {
224+
let encryption_info = match value.encryption_info() {
225+
None => None,
226+
Some(encryption_info) => Some(encryption_info.clone().try_into()?),
227+
};
228+
229+
Ok(Self { event: value.raw().json().get().to_owned().into(), encryption_info })
223230
}
224231
}
225232

@@ -280,19 +287,28 @@ impl EncryptionInfo {
280287
}
281288
}
282289

283-
impl From<Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>> for EncryptionInfo {
284-
fn from(value: Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>) -> Self {
290+
impl TryFrom<Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>> for EncryptionInfo {
291+
type Error = anyhow::Error;
292+
293+
fn try_from(
294+
value: Arc<matrix_sdk_common::deserialized_responses::EncryptionInfo>,
295+
) -> Result<Self, Self::Error> {
285296
match &value.algorithm_info {
286-
AlgorithmInfo::MegolmV1AesSha2 { curve25519_key, sender_claimed_keys, .. } => Self {
287-
sender: value.sender.clone().into(),
288-
sender_device: value.sender_device.clone().map(Into::into),
289-
sender_curve25519_key_base64: curve25519_key.clone(),
290-
sender_claimed_ed25519_key: sender_claimed_keys
291-
.get(&ruma::DeviceKeyAlgorithm::Ed25519)
292-
.cloned()
293-
.into(),
294-
verification_state: value.verification_state.clone(),
295-
},
297+
AlgorithmInfo::MegolmV1AesSha2 { curve25519_key, sender_claimed_keys, .. } => {
298+
Ok(Self {
299+
sender: value.sender.clone().into(),
300+
sender_device: value.sender_device.clone().map(Into::into),
301+
sender_curve25519_key_base64: curve25519_key.clone(),
302+
sender_claimed_ed25519_key: sender_claimed_keys
303+
.get(&ruma::DeviceKeyAlgorithm::Ed25519)
304+
.cloned()
305+
.into(),
306+
verification_state: value.verification_state.clone(),
307+
})
308+
}
309+
AlgorithmInfo::OlmV1Curve25519AesSha2 { .. } => Err(anyhow!(
310+
"AlgorithmInfo::OlmV1Curve25519AesSha2 is not applicable for room event EncryptionInfo",
311+
)),
296312
}
297313
}
298314
}

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ pub fn processed_to_device_event_to_js_value(
480480
processed_to_device_event: matrix_sdk_crypto::types::ProcessedToDeviceEvent,
481481
) -> JsValue {
482482
match processed_to_device_event {
483-
matrix_sdk_crypto::types::ProcessedToDeviceEvent::Decrypted(raw) => {
483+
matrix_sdk_crypto::types::ProcessedToDeviceEvent::Decrypted { raw, .. } => {
484484
DecryptedToDeviceEvent { decrypted_raw_event: raw.json().get().into() }.into()
485485
}
486486
matrix_sdk_crypto::types::ProcessedToDeviceEvent::UnableToDecrypt(utd) => {

0 commit comments

Comments
 (0)