Skip to content

Commit 8f42673

Browse files
committed
test: Allow to create encrypted events in the event factory
1 parent 950c427 commit 8f42673

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

testing/matrix-sdk-test/src/event_factory.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use matrix_sdk_common::deserialized_responses::{
2525
TimelineEvent, UnableToDecryptInfo, UnableToDecryptReason,
2626
};
2727
use ruma::{
28-
EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId,
29-
OwnedRoomId, OwnedTransactionId, OwnedUserId, OwnedVoipId, RoomId, RoomVersionId,
30-
TransactionId, UInt, UserId, VoipVersionId,
28+
EventId, Int, MilliSecondsSinceUnixEpoch, MxcUri, OwnedDeviceId, OwnedEventId, OwnedMxcUri,
29+
OwnedRoomAliasId, OwnedRoomId, OwnedTransactionId, OwnedUserId, OwnedVoipId, RoomId,
30+
RoomVersionId, TransactionId, UInt, UserId, VoipVersionId,
3131
events::{
3232
AnyGlobalAccountDataEvent, AnyMessageLikeEvent, AnyStateEvent, AnyStrippedStateEvent,
3333
AnySyncEphemeralRoomEvent, AnySyncMessageLikeEvent, AnySyncStateEvent,
@@ -60,7 +60,9 @@ use ruma::{
6060
avatar::{self, RoomAvatarEventContent},
6161
canonical_alias::RoomCanonicalAliasEventContent,
6262
create::{PreviousRoom, RoomCreateEventContent},
63-
encrypted::{EncryptedEventScheme, RoomEncryptedEventContent},
63+
encrypted::{
64+
EncryptedEventScheme, MegolmV1AesSha2ContentInit, RoomEncryptedEventContent,
65+
},
6466
member::{MembershipState, RoomMemberEventContent},
6567
message::{
6668
FormattedBody, GalleryItemType, GalleryMessageEventContent,
@@ -871,6 +873,29 @@ impl EventFactory {
871873
self.event(RoomMessageEventContent::emote_plain(content.into()))
872874
}
873875

876+
/// Create a new `m.room.encrypted` event using the `m.megolm.v1.aes-sha2`
877+
/// algorithm.
878+
pub fn encrypted(
879+
&self,
880+
ciphertext: impl Into<String>,
881+
sender_key: impl Into<String>,
882+
device_id: impl Into<OwnedDeviceId>,
883+
session_id: impl Into<String>,
884+
) -> EventBuilder<RoomEncryptedEventContent> {
885+
self.event(RoomEncryptedEventContent::new(
886+
EncryptedEventScheme::MegolmV1AesSha2(
887+
MegolmV1AesSha2ContentInit {
888+
ciphertext: ciphertext.into(),
889+
sender_key: sender_key.into(),
890+
device_id: device_id.into(),
891+
session_id: session_id.into(),
892+
}
893+
.into(),
894+
),
895+
None,
896+
))
897+
}
898+
874899
/// Create a new `m.room.member` event for the given member.
875900
///
876901
/// The given member will be used as the `sender` as well as the `state_key`

0 commit comments

Comments
 (0)