Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RemoveProposal to the Removed case of CommitEffect #176

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mls-rs-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl From<mls_rs::group::CommitEffect> for CommitEffect {
.map(|p| Arc::new(p.proposal.into()))
.collect(),
},
group::CommitEffect::Removed => CommitEffect::Removed,
group::CommitEffect::Removed(_) => CommitEffect::Removed,
group::CommitEffect::ReInit(_) => CommitEffect::ReInit,
}
}
Expand Down
2 changes: 1 addition & 1 deletion mls-rs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ mod tests {
assert_matches!(
message,
ReceivedMessage::Commit(CommitMessageDescription {
effect: CommitEffect::Removed,
effect: CommitEffect::Removed(_),
..
})
);
Expand Down
11 changes: 8 additions & 3 deletions mls-rs/src/external_client/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::{
ApplicationMessageDescription, CommitMessageDescription, EventOrContent,
MessageProcessor, ProposalMessageDescription, ProvisionalState,
},
proposal::RemoveProposal,
proposal_filter::ProposalInfo,
snapshot::RawGroupState,
state::GroupState,
transcript_hash::InterimTranscriptHash,
Expand Down Expand Up @@ -56,7 +58,7 @@ use mls_rs_core::{crypto::CipherSuiteProvider, psk::ExternalPskId};
#[cfg(feature = "by_ref_proposal")]
use crate::{
extension::ExternalSendersExt,
group::proposal::{AddProposal, ReInitProposal, RemoveProposal},
group::proposal::{AddProposal, ReInitProposal},
};

#[cfg(all(feature = "by_ref_proposal", feature = "psk"))]
Expand Down Expand Up @@ -638,8 +640,11 @@ where
&mut self.state
}

fn can_continue_processing(&self, _provisional_state: &ProvisionalState) -> bool {
true
fn removal_proposal(
&self,
_provisional_state: &ProvisionalState,
) -> Option<ProposalInfo<RemoveProposal>> {
None
}

#[cfg(feature = "private_message")]
Expand Down
14 changes: 9 additions & 5 deletions mls-rs/src/group/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{
state::GroupState,
transcript_hash::InterimTranscriptHash,
transcript_hashes, validate_group_info_member, GroupContext, GroupInfo, ReInitProposal,
Welcome,
RemoveProposal, Welcome,
};
use crate::{
client::MlsError,
Expand Down Expand Up @@ -121,7 +121,7 @@ impl NewEpoch {
#[derive(Clone, Debug, PartialEq)]
pub enum CommitEffect {
NewEpoch(Box<NewEpoch>),
Removed,
Removed(ProposalInfo<RemoveProposal>),
ReInit(ProposalInfo<ReInitProposal>),
}

Expand Down Expand Up @@ -636,12 +636,12 @@ pub(crate) trait MessageProcessor: Send + Sync {
return Err(MlsError::CommitMissingPath);
}

if !self.can_continue_processing(&provisional_state) {
if let Some(removal) = self.removal_proposal(&provisional_state) {
return Ok(CommitMessageDescription {
is_external: matches!(auth_content.content.sender, Sender::NewMemberCommit),
authenticated_data: auth_content.content.authenticated_data,
committer: *sender,
effect: CommitEffect::Removed,
effect: CommitEffect::Removed(removal),
});
}

Expand Down Expand Up @@ -727,7 +727,11 @@ pub(crate) trait MessageProcessor: Send + Sync {
fn identity_provider(&self) -> Self::IdentityProvider;
fn cipher_suite_provider(&self) -> &Self::CipherSuiteProvider;
fn psk_storage(&self) -> Self::PreSharedKeyStorage;
fn can_continue_processing(&self, provisional_state: &ProvisionalState) -> bool;

fn removal_proposal(
&self,
provisional_state: &ProvisionalState,
) -> Option<ProposalInfo<RemoveProposal>>;

#[cfg(feature = "private_message")]
fn min_epoch_available(&self) -> Option<u64>;
Expand Down
21 changes: 13 additions & 8 deletions mls-rs/src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub(crate) use self::commit::test_utils::CommitModifiers;
#[cfg(all(test, feature = "private_message"))]
pub use self::framing::PrivateMessage;

#[cfg(feature = "psk")]
use self::proposal_filter::ProposalInfo;

#[cfg(any(feature = "secret_tree_access", feature = "private_message"))]
Expand Down Expand Up @@ -1827,13 +1826,19 @@ where
&mut self.state
}

fn can_continue_processing(&self, provisional_state: &ProvisionalState) -> bool {
!(provisional_state
.applied_proposals
.removals
.iter()
.any(|p| p.proposal.to_remove == self.private_tree.self_index)
&& self.pending_commit.is_none())
fn removal_proposal(
&self,
provisional_state: &ProvisionalState,
) -> Option<ProposalInfo<RemoveProposal>> {
match self.pending_commit {
tomleavy marked this conversation as resolved.
Show resolved Hide resolved
Some(_) => None,
None => provisional_state
.applied_proposals
.removals
.iter()
.find(|p| p.proposal.to_remove == self.private_tree.self_index)
.cloned(),
}
}

#[cfg(feature = "private_message")]
Expand Down
7 changes: 5 additions & 2 deletions mls-rs/src/group/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,11 @@ impl MessageProcessor for GroupWithoutKeySchedule {
self.inner.psk_storage()
}

fn can_continue_processing(&self, provisional_state: &ProvisionalState) -> bool {
self.inner.can_continue_processing(provisional_state)
fn removal_proposal(
&self,
provisional_state: &ProvisionalState,
) -> Option<ProposalInfo<RemoveProposal>> {
self.inner.removal_proposal(provisional_state)
}

#[cfg(feature = "private_message")]
Expand Down
Loading