refactor(crypto): Reduce the size of MaybeEncryptedRoomKey.

This patch reduces the size of `MaybeEncryptedRoomKey` from 336 bytes
to 32 bytes.
This commit is contained in:
Ivan Enderlin
2025-05-16 10:12:13 +02:00
parent 87066a127e
commit 293d4ee08c
2 changed files with 9 additions and 7 deletions

View File

@@ -60,8 +60,10 @@ use crate::{
pub enum MaybeEncryptedRoomKey {
Encrypted {
used_session: Session,
share_info: ShareInfo,
// `Box` the session to reduce the size of `Encrypted`.
used_session: Box<Session>,
// `Box` the session to reduce the size of `Encrypted`.
share_info: Box<ShareInfo>,
message: Raw<AnyToDeviceEventContent>,
},
/// We could not encrypt a message to this device because there is no active
@@ -832,12 +834,12 @@ impl DeviceData {
match self.encrypt(store, &event_type, content).await {
Ok((session, encrypted)) => Ok(MaybeEncryptedRoomKey::Encrypted {
share_info: ShareInfo::new_shared(
share_info: Box::new(ShareInfo::new_shared(
session.sender_key().to_owned(),
message_index,
self.olm_wedging_index,
),
used_session: session,
)),
used_session: Box::new(session),
message: encrypted.cast(),
}),

View File

@@ -310,14 +310,14 @@ impl GroupSessionManager {
match result.maybe_encrypted_room_key {
MaybeEncryptedRoomKey::Encrypted { used_session, share_info, message } => {
result_builder.on_successful_encryption(&result.device, used_session, message);
result_builder.on_successful_encryption(&result.device, *used_session, message);
let user_id = result.device.user_id().to_owned();
let device_id = result.device.device_id().to_owned();
share_infos
.entry(user_id)
.or_insert_with(BTreeMap::new)
.insert(device_id, share_info);
.insert(device_id, *share_info);
}
MaybeEncryptedRoomKey::MissingSession => {
result_builder.on_missing_session(result.device);