mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
refactor(crypto): Add a constructor to create an InboundGroupSession from a m.room_key event
This commit is contained in:
@@ -877,15 +877,8 @@ impl OlmMachine {
|
||||
event: &DecryptedRoomKeyEvent,
|
||||
content: &MegolmV1AesSha2Content,
|
||||
) -> OlmResult<Option<InboundGroupSession>> {
|
||||
let session = InboundGroupSession::new(
|
||||
sender_key,
|
||||
event.keys.ed25519,
|
||||
&content.room_id,
|
||||
&content.session_key,
|
||||
SenderData::unknown(),
|
||||
event.content.algorithm(),
|
||||
None,
|
||||
);
|
||||
let session =
|
||||
InboundGroupSession::from_room_key_content(sender_key, event.keys.ed25519, content);
|
||||
|
||||
match session {
|
||||
Ok(mut session) => {
|
||||
|
||||
@@ -51,6 +51,7 @@ use crate::{
|
||||
},
|
||||
olm_v1::DecryptedForwardedRoomKeyEvent,
|
||||
room::encrypted::{EncryptedEvent, RoomEventEncryptionScheme},
|
||||
room_key,
|
||||
},
|
||||
serialize_curve_key, EventEncryptionAlgorithm, SigningKeys,
|
||||
},
|
||||
@@ -210,6 +211,36 @@ impl InboundGroupSession {
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a new [`InboundGroupSession`] from a `m.room_key` event with an
|
||||
/// `m.megolm.v1.aes-sha2` content.
|
||||
///
|
||||
/// The `m.room_key` event **must** have been encrypted using the
|
||||
/// `m.olm.v1.curve25519-aes-sha2` algorithm and the `sender_key` **must**
|
||||
/// be the long-term [`Curve25519PublicKey`] that was used to establish
|
||||
/// the 1-to-1 Olm session.
|
||||
///
|
||||
/// The `signing_key` **must** be the [`Ed25519PublicKey`] contained in the
|
||||
/// `keys` field of the [decrypted payload].
|
||||
///
|
||||
/// [decrypted payload]: https://spec.matrix.org/unstable/client-server-api/#molmv1curve25519-aes-sha2
|
||||
pub fn from_room_key_content(
|
||||
sender_key: Curve25519PublicKey,
|
||||
signing_key: Ed25519PublicKey,
|
||||
content: &room_key::MegolmV1AesSha2Content,
|
||||
) -> Result<Self, SessionCreationError> {
|
||||
let room_key::MegolmV1AesSha2Content { room_id, session_id: _, session_key, .. } = content;
|
||||
|
||||
Self::new(
|
||||
sender_key,
|
||||
signing_key,
|
||||
room_id,
|
||||
session_key,
|
||||
SenderData::unknown(),
|
||||
EventEncryptionAlgorithm::MegolmV1AesSha2,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a new [`InboundGroupSession`] from an exported version of the
|
||||
/// group session.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user