Skip to content

Commit

Permalink
crypto: refactoring move user loop inside of sharing strategy code
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Aug 7, 2024
1 parent 2e7bb79 commit bd7711e
Showing 1 changed file with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,47 +127,67 @@ pub(crate) async fn collect_session_recipients(

let own_identity = store.get_user_identity(store.user_id()).await?.and_then(|i| i.into_own());

for user_id in users {
let user_devices = store.get_device_data_for_user_filtered(user_id).await?;
match settings.sharing_strategy {
CollectStrategy::DeviceBasedStrategy { only_allow_trusted_devices } => {
for user_id in users {
let user_devices = store.get_device_data_for_user_filtered(user_id).await?;

let recipient_devices = match settings.sharing_strategy {
CollectStrategy::DeviceBasedStrategy { only_allow_trusted_devices } => {
// We only need the user identity if only_allow_trusted_devices is set.
let device_owner_identity = if only_allow_trusted_devices {
store.get_user_identity(user_id).await?
} else {
None
};
split_recipients_withhelds_for_user(
let recipient_devices = split_recipients_withhelds_for_user(
user_devices,
&own_identity,
&device_owner_identity,
only_allow_trusted_devices,
)
);
let recipients = recipient_devices.allowed_devices;
let withheld_recipients = recipient_devices.denied_devices_with_code;

// If we haven't already concluded that the session should be
// rotated for other reasons, we also need to check whether any
// of the devices in the session got deleted or blacklisted in the
// meantime. If so, we should also rotate the session.
if !should_rotate {
should_rotate = is_session_overshared_for_user(outbound, user_id, &recipients)
}

devices.entry(user_id.to_owned()).or_default().extend(recipients);
withheld_devices.extend(withheld_recipients);
}
CollectStrategy::IdentityBasedStrategy => {
}
CollectStrategy::IdentityBasedStrategy => {
for user_id in users {
let user_devices = store.get_device_data_for_user_filtered(user_id).await?;

let device_owner_identity = store.get_user_identity(user_id).await?;
split_recipients_withhelds_for_user_based_on_identity(
let recipient_devices = split_recipients_withhelds_for_user_based_on_identity(
user_devices,
&device_owner_identity,
)
}
};
);

let recipients = recipient_devices.allowed_devices;
let withheld_recipients = recipient_devices.denied_devices_with_code;
let recipients = recipient_devices.allowed_devices;
let withheld_recipients = recipient_devices.denied_devices_with_code;

// If we haven't already concluded that the session should be
// rotated for other reasons, we also need to check whether any
// of the devices in the session got deleted or blacklisted in the
// meantime. If so, we should also rotate the session.
if !should_rotate {
should_rotate = is_session_overshared_for_user(outbound, user_id, &recipients)
// If we haven't already concluded that the session should be
// rotated for other reasons, we also need to check whether any
// of the devices in the session got deleted or blacklisted in the
// meantime. If so, we should also rotate the session.
if !should_rotate {
should_rotate = is_session_overshared_for_user(outbound, user_id, &recipients)
}

devices.entry(user_id.to_owned()).or_default().extend(recipients);
withheld_devices.extend(withheld_recipients);
}
}
};

devices.entry(user_id.to_owned()).or_default().extend(recipients);
withheld_devices.extend(withheld_recipients);
}
// }
// end of for each

if should_rotate {
debug!(
Expand All @@ -183,8 +203,8 @@ pub(crate) async fn collect_session_recipients(
Ok(CollectRecipientsResult { should_rotate, devices, withheld_devices })
}

// Checks if the session has been shared with a device that is not anymore in the
// pool of devices that should participate in the discussion.
// Checks if the session has been shared with a device that is not anymore in
// the pool of devices that should participate in the discussion.
fn is_session_overshared_for_user(
outbound: &OutboundGroupSession,
user_id: &UserId,
Expand Down

0 comments on commit bd7711e

Please sign in to comment.