Skip to content

Commit d4a0c28

Browse files
BillCarsonFrpoljar
authored andcommitted
review: Move ProcessedToDeviceEvent to crypto types mod
1 parent 031f4ec commit d4a0c28

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

crates/matrix-sdk-common/src/deserialized_responses.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::{collections::BTreeMap, fmt};
1717
#[cfg(doc)]
1818
use ruma::events::AnyTimelineEvent;
1919
use ruma::{
20-
events::{AnyMessageLikeEvent, AnySyncTimelineEvent, AnyToDeviceEvent},
20+
events::{AnyMessageLikeEvent, AnySyncTimelineEvent},
2121
push::Action,
2222
serde::{
2323
AsRefStr, AsStrAsRefStr, DebugAsRefStr, DeserializeFromCowStr, FromString, JsonObject, Raw,
@@ -615,38 +615,6 @@ impl fmt::Debug for DecryptedRoomEvent {
615615
}
616616
}
617617

618-
#[derive(Clone, Debug, Serialize, Deserialize)]
619-
pub enum ProcessedToDeviceEvent {
620-
/// A successfully-decrypted encrypted event.
621-
Decrypted {
622-
/// The decrypted to device event
623-
decrypted_event: Raw<AnyToDeviceEvent>,
624-
},
625-
626-
/// An encrypted event which could not be decrypted.
627-
UnableToDecrypt {
628-
/// The `m.room.encrypted` to device event.
629-
event: Raw<AnyToDeviceEvent>,
630-
},
631-
632-
/// An unencrypted event.
633-
PlainText(Raw<AnyToDeviceEvent>),
634-
635-
/// An invalid to device event that was ignored
636-
NotProcessed(Raw<AnyToDeviceEvent>),
637-
}
638-
639-
impl ProcessedToDeviceEvent {
640-
pub fn to_raw(&self) -> Raw<AnyToDeviceEvent> {
641-
match self {
642-
ProcessedToDeviceEvent::Decrypted { decrypted_event, .. } => decrypted_event.clone(),
643-
ProcessedToDeviceEvent::UnableToDecrypt { event } => event.clone(),
644-
ProcessedToDeviceEvent::PlainText(event) => event.clone(),
645-
ProcessedToDeviceEvent::NotProcessed(event) => event.clone(),
646-
}
647-
}
648-
}
649-
650618
/// The location of an event bundled in an `unsigned` object.
651619
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
652620
pub enum UnsignedEventLocation {

crates/matrix-sdk-crypto/src/machine/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use itertools::Itertools;
2222
use matrix_sdk_common::{
2323
deserialized_responses::{
2424
AlgorithmInfo, DecryptedRoomEvent, DeviceLinkProblem, EncryptionInfo,
25-
ProcessedToDeviceEvent, UnableToDecryptInfo, UnableToDecryptReason,
25+
UnableToDecryptInfo, UnableToDecryptReason,
2626
UnsignedDecryptionResult, UnsignedEventLocation, VerificationLevel, VerificationState,
2727
},
2828
locks::RwLock as StdRwLock,
@@ -102,6 +102,7 @@ use crate::{
102102
CollectStrategy, CrossSigningKeyExport, CryptoStoreError, DecryptionSettings, DeviceData,
103103
LocalTrust, RoomEventDecryptionResult, SignatureError, TrustRequirement,
104104
};
105+
use crate::types::ProcessedToDeviceEvent;
105106

106107
/// State machine implementation of the Olm/Megolm encryption protocol used for
107108
/// Matrix end to end encryption.

crates/matrix-sdk-crypto/src/machine/tests/megolm_sender_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::{fmt::Debug, iter, pin::Pin};
1717
use assert_matches::assert_matches;
1818
use futures_core::Stream;
1919
use futures_util::{FutureExt, StreamExt};
20-
use matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent;
20+
use crate::types::ProcessedToDeviceEvent;
2121
use matrix_sdk_test::async_test;
2222
use ruma::{room_id, user_id, RoomId, TransactionId, UserId};
2323
use serde::Serialize;

crates/matrix-sdk-crypto/src/machine/tests/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use assert_matches2::{assert_let, assert_matches};
1818
use futures_util::{pin_mut, FutureExt, StreamExt};
1919
use itertools::Itertools;
2020
use matrix_sdk_common::deserialized_responses::{
21-
AlgorithmInfo, ProcessedToDeviceEvent, UnableToDecryptInfo, UnableToDecryptReason,
21+
AlgorithmInfo, UnableToDecryptInfo, UnableToDecryptReason,
2222
UnsignedDecryptionResult, UnsignedEventLocation, VerificationLevel, VerificationState,
2323
WithheldCode,
2424
};
@@ -78,6 +78,7 @@ use crate::{
7878
Account, DecryptionSettings, DeviceData, EncryptionSettings, LocalTrust, MegolmError, OlmError,
7979
RoomEventDecryptionResult, TrustRequirement,
8080
};
81+
use crate::types::ProcessedToDeviceEvent;
8182

8283
mod decryption_verification_state;
8384
mod interactive_verification;

crates/matrix-sdk-crypto/src/machine/tests/olm_encryption.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{
1818
};
1919

2020
use assert_matches2::assert_let;
21-
use matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent;
21+
use crate::types::ProcessedToDeviceEvent;
2222
use matrix_sdk_test::async_test;
2323
use ruma::{
2424
device_id,

crates/matrix-sdk-crypto/src/machine/tests/send_encrypted_to_device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use assert_matches2::{assert_let, assert_matches};
16-
use matrix_sdk_common::deserialized_responses::ProcessedToDeviceEvent;
16+
use crate::types::ProcessedToDeviceEvent;
1717
use matrix_sdk_test::async_test;
1818
use ruma::{events::AnyToDeviceEvent, serde::Raw, to_device::DeviceIdOrAllDevices};
1919
use serde_json::{json, value::to_raw_value};

crates/matrix-sdk-crypto/src/session_manager/group_sessions/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ mod tests {
10311031
};
10321032

10331033
use assert_matches2::assert_let;
1034-
use matrix_sdk_common::deserialized_responses::{ProcessedToDeviceEvent, WithheldCode};
1034+
use matrix_sdk_common::deserialized_responses::WithheldCode;
10351035
use matrix_sdk_test::{async_test, ruma_response_from_json};
10361036
use ruma::{
10371037
api::client::{
@@ -1067,6 +1067,7 @@ mod tests {
10671067
},
10681068
EncryptionSettings, LocalTrust, OlmMachine,
10691069
};
1070+
use crate::types::ProcessedToDeviceEvent;
10701071

10711072
fn alice_id() -> &'static UserId {
10721073
user_id!("@alice:example.org")

crates/matrix-sdk-crypto/src/types/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ use ruma::{
4141
use serde::{Deserialize, Deserializer, Serialize, Serializer};
4242
use vodozemac::{Curve25519PublicKey, Ed25519PublicKey, Ed25519Signature, KeyError};
4343
use zeroize::{Zeroize, ZeroizeOnDrop};
44+
use ruma::serde::Raw;
45+
use ruma::events::AnyToDeviceEvent;
4446

4547
mod backup;
4648
mod cross_signing;
@@ -626,3 +628,37 @@ mod test {
626628
assert_json_snapshot!(secret_bundle);
627629
}
628630
}
631+
632+
/// Represents a to-device event after it has been processed by the olm machine.
633+
#[derive(Clone, Debug, Serialize, Deserialize)]
634+
pub enum ProcessedToDeviceEvent {
635+
/// A successfully-decrypted encrypted event.
636+
Decrypted {
637+
/// The decrypted to device event
638+
decrypted_event: Raw<AnyToDeviceEvent>,
639+
},
640+
641+
/// An encrypted event which could not be decrypted.
642+
UnableToDecrypt {
643+
/// The `m.room.encrypted` to device event.
644+
event: Raw<AnyToDeviceEvent>,
645+
},
646+
647+
/// An unencrypted event.
648+
PlainText(Raw<AnyToDeviceEvent>),
649+
650+
/// An invalid to device event that was ignored
651+
NotProcessed(Raw<AnyToDeviceEvent>),
652+
}
653+
654+
impl ProcessedToDeviceEvent {
655+
/// Converts a ProcessedToDeviceEvent to the Raw<AnyToDeviceEvent> it encapsulates
656+
pub fn to_raw(&self) -> Raw<AnyToDeviceEvent> {
657+
match self {
658+
ProcessedToDeviceEvent::Decrypted { decrypted_event, .. } => decrypted_event.clone(),
659+
ProcessedToDeviceEvent::UnableToDecrypt { event } => event.clone(),
660+
ProcessedToDeviceEvent::PlainText(event) => event.clone(),
661+
ProcessedToDeviceEvent::NotProcessed(event) => event.clone(),
662+
}
663+
}
664+
}

0 commit comments

Comments
 (0)