@@ -51,6 +51,7 @@ use crate::{
5151 } ,
5252 olm_v1:: DecryptedForwardedRoomKeyEvent ,
5353 room:: encrypted:: { EncryptedEvent , RoomEventEncryptionScheme } ,
54+ room_key,
5455 } ,
5556 serialize_curve_key, EventEncryptionAlgorithm , SigningKeys ,
5657 } ,
@@ -210,6 +211,36 @@ impl InboundGroupSession {
210211 } )
211212 }
212213
214+ /// Create a new [`InboundGroupSession`] from a `m.room_key` event with an
215+ /// `m.megolm.v1.aes-sha2` content.
216+ ///
217+ /// The `m.room_key` event **must** have been encrypted using the
218+ /// `m.olm.v1.curve25519-aes-sha2` algorithm and the `sender_key` **must**
219+ /// be the long-term [`Curve25519PublicKey`] that was used to establish
220+ /// the 1-to-1 Olm session.
221+ ///
222+ /// The `signing_key` **must** be the [`Ed25519PublicKey`] contained in the
223+ /// `keys` field of the [decrypted payload].
224+ ///
225+ /// [decrypted payload]: https://spec.matrix.org/unstable/client-server-api/#molmv1curve25519-aes-sha2
226+ pub fn from_room_key_content (
227+ sender_key : Curve25519PublicKey ,
228+ signing_key : Ed25519PublicKey ,
229+ content : & room_key:: MegolmV1AesSha2Content ,
230+ ) -> Result < Self , SessionCreationError > {
231+ let room_key:: MegolmV1AesSha2Content { room_id, session_id : _, session_key, .. } = content;
232+
233+ Self :: new (
234+ sender_key,
235+ signing_key,
236+ room_id,
237+ session_key,
238+ SenderData :: unknown ( ) ,
239+ EventEncryptionAlgorithm :: MegolmV1AesSha2 ,
240+ None ,
241+ )
242+ }
243+
213244 /// Create a new [`InboundGroupSession`] from an exported version of the
214245 /// group session.
215246 ///
0 commit comments