@@ -732,6 +732,19 @@ async fn test_megolm_encryption() {
732
732
}
733
733
}
734
734
735
+ /// Helper function to set up end-to-end Megolm encryption between two devices.
736
+ ///
737
+ /// Creates two devices, Alice and Bob, and has Alice create an outgoing Megolm
738
+ /// session in the given room, whose decryption key is shared with Bob via a
739
+ /// to-device message.
740
+ ///
741
+ /// # Arguments
742
+ ///
743
+ /// * `room_id` - The RoomId for which to set up Megolm encryption.
744
+ ///
745
+ /// # Returns
746
+ ///
747
+ /// A tuple containing the alice and bob OlmMachine instances.
735
748
#[ cfg( feature = "experimental-encrypted-state-events" ) ]
736
749
async fn megolm_encryption_setup_helper ( room_id : & RoomId ) -> ( OlmMachine , OlmMachine ) {
737
750
let ( alice, bob) =
@@ -773,6 +786,9 @@ async fn megolm_encryption_setup_helper(room_id: &RoomId) -> (OlmMachine, OlmMac
773
786
( alice, bob)
774
787
}
775
788
789
+ /// Verifies that Megolm-encrypted state events can be encrypted and decrypted
790
+ /// correctly, and that the decrypted event matches the expected type and
791
+ /// content.
776
792
#[ cfg( feature = "experimental-encrypted-state-events" ) ]
777
793
#[ async_test]
778
794
async fn test_megolm_state_encryption ( ) {
@@ -818,6 +834,9 @@ async fn test_megolm_state_encryption() {
818
834
}
819
835
}
820
836
837
+ /// Verifies that decryption fails with StateKeyVerificationFailed
838
+ /// when unpacking the state_key of the decrypted event yields an event type
839
+ /// that does not exist or does not match the type in the decrypted ciphertext.
821
840
#[ cfg( feature = "experimental-encrypted-state-events" ) ]
822
841
#[ async_test]
823
842
async fn test_megolm_state_encryption_bad_type ( ) {
@@ -831,7 +850,6 @@ async fn test_megolm_state_encryption_bad_type() {
831
850
let encrypted_content =
832
851
alice. encrypt_state_event ( room_id, content, EmptyStateKey ) . await . unwrap ( ) ;
833
852
834
- // Malformed events
835
853
let bad_type_event = json ! ( {
836
854
"event_id" : "$xxxxx:example.org" ,
837
855
"origin_server_ts" : MilliSecondsSinceUnixEpoch :: now( ) ,
@@ -858,6 +876,9 @@ async fn test_megolm_state_encryption_bad_type() {
858
876
) ;
859
877
}
860
878
879
+ /// Verifies that decryption fails with StateKeyVerificationFailed
880
+ /// when unpacking the state_key of the decrypted event yields a state_key
881
+ /// that does not match the state_key in the decrypted ciphertext.
861
882
#[ cfg( feature = "experimental-encrypted-state-events" ) ]
862
883
#[ async_test]
863
884
async fn test_megolm_state_encryption_bad_state_key ( ) {
@@ -890,7 +911,6 @@ async fn test_megolm_state_encryption_bad_state_key() {
890
911
. await
891
912
. unwrap ( ) ;
892
913
893
- // Require malformed events fail verification
894
914
assert_matches ! (
895
915
bad_state_key_decryption_result,
896
916
RoomEventDecryptionResult :: UnableToDecrypt ( UnableToDecryptInfo {
0 commit comments