pub struct CommitBuilder<'a, T> { /* private fields */ }
Expand description
The CommitBuilder
is used to easily and dynamically build commit messages.
It operates in a series of stages:
The Initial
stage is used to populate the builder with proposals and other data using
method calls on the builder that let the builder stay in the same stage.
The next stage is LoadedPsks
, and it signifies the stage after the builder loaded the the
pre-shared keys for the PreSharedKey proposals in this commit.
Then comes the Complete
stage, which denotes that all data has been validated. From this
stage, the commit can be staged in the group, and the outgoing messages returned.
For example, to create a commit to a new Add proposal with a KeyPackage key_package_to_add
that does not commit to the proposals in the proposal store, one could build the commit as
follows:
let message_bundle: CommitMessageBundle = mls_group
.commit_builder()
.consume_proposal_store(false)
.add_proposal(key_package_to_add)
.load_psks(provider.storage())?
.build(provider.rand(), provider.crypto(), signer, app_policy_proposals)?
.stage_commit(provider)?;
let commit = message_bundle.commit();
let welcome = message_bundle.welcome().expect("expected a welcome since there was an add");
let group_info = message_bundle.welcome().expect("expected a group info since there was an add");
In this example signer
is a reference to a [Signer
] and app_policy_proposals
is the
application-defined policy for which proposals to accept, implemented by an
FnMut(&QueuedProposal) -> bool
.
See the book for another example.
Implementations§
Source§impl<'a> CommitBuilder<'a, Initial>
impl<'a> CommitBuilder<'a, Initial>
Sourcepub fn new(group: &'a mut MlsGroup) -> Self
pub fn new(group: &'a mut MlsGroup) -> Self
returns a new CommitBuilder
for the given MlsGroup
.
Sourcepub fn consume_proposal_store(self, consume_proposal_store: bool) -> Self
pub fn consume_proposal_store(self, consume_proposal_store: bool) -> Self
Sets whether or not the proposals in the proposal store of the group should be included in
the commit. Defaults to true
.
Sourcepub fn create_group_info(self, create_group_info: bool) -> Self
pub fn create_group_info(self, create_group_info: bool) -> Self
Sets whether or not a GroupInfo
should be created when the commit is staged. Defaults to
the value of the MlsGroup
s MlsGroupJoinConfig
.
Sourcepub fn force_self_update(self, force_self_update: bool) -> Self
pub fn force_self_update(self, force_self_update: bool) -> Self
Sets whether or not the commit should force a self-update. Defaults to false
.
Sourcepub fn add_proposal(self, proposal: Proposal) -> Self
pub fn add_proposal(self, proposal: Proposal) -> Self
Adds a proposal to the proposals to be committed.
Sourcepub fn add_proposals(
self,
proposals: impl IntoIterator<Item = Proposal>,
) -> Self
pub fn add_proposals( self, proposals: impl IntoIterator<Item = Proposal>, ) -> Self
Adds the proposals in the iterator to the proposals to be committed.
Sourcepub fn leaf_node_parameters(
self,
leaf_node_parameters: LeafNodeParameters,
) -> Self
pub fn leaf_node_parameters( self, leaf_node_parameters: LeafNodeParameters, ) -> Self
Sets the leaf node parameters for the new leaf node in a self-update. Implies that a self-update takes place.
Sourcepub fn propose_adds(
self,
key_packages: impl IntoIterator<Item = KeyPackage>,
) -> Self
pub fn propose_adds( self, key_packages: impl IntoIterator<Item = KeyPackage>, ) -> Self
Adds an Add proposal to the provided KeyPackage
to the list of proposals to be
committed.
Sourcepub fn propose_removals(
self,
removed: impl IntoIterator<Item = LeafNodeIndex>,
) -> Self
pub fn propose_removals( self, removed: impl IntoIterator<Item = LeafNodeIndex>, ) -> Self
Adds a Remove proposal for the provided LeafNodeIndex
es to the list of proposals to be
committed.
Sourcepub fn propose_group_context_extensions(self, extensions: Extensions) -> Self
pub fn propose_group_context_extensions(self, extensions: Extensions) -> Self
Adds a GroupContextExtensions proposal for the provided Extensions
to the list of
proposals to be committed.
Sourcepub fn load_psks<Storage: StorageProvider>(
self,
storage: &'a Storage,
) -> Result<CommitBuilder<'a, LoadedPsks>, CreateCommitError>
pub fn load_psks<Storage: StorageProvider>( self, storage: &'a Storage, ) -> Result<CommitBuilder<'a, LoadedPsks>, CreateCommitError>
Loads the PSKs for the PskProposals marked for inclusion and moves on to the next phase.
Source§impl<'a> CommitBuilder<'a, LoadedPsks>
impl<'a> CommitBuilder<'a, LoadedPsks>
Sourcepub fn build<S: Signer>(
self,
rand: &impl OpenMlsRand,
crypto: &impl OpenMlsCrypto,
signer: &S,
f: impl FnMut(&QueuedProposal) -> bool,
) -> Result<CommitBuilder<'a, Complete>, CreateCommitError>
pub fn build<S: Signer>( self, rand: &impl OpenMlsRand, crypto: &impl OpenMlsCrypto, signer: &S, f: impl FnMut(&QueuedProposal) -> bool, ) -> Result<CommitBuilder<'a, Complete>, CreateCommitError>
Validates the inputs and builds the commit. The last argument f
is a function that lets
the caller filter the proposals that are considered for inclusion. This provides a way for
the application to enforce custom policies in the creation of commits.
Sourcepub fn build_with_new_signer<S: Signer>(
self,
rand: &impl OpenMlsRand,
crypto: &impl OpenMlsCrypto,
old_signer: &impl Signer,
new_signer: NewSignerBundle<'_, S>,
f: impl FnMut(&QueuedProposal) -> bool,
) -> Result<CommitBuilder<'a, Complete>, CreateCommitError>
pub fn build_with_new_signer<S: Signer>( self, rand: &impl OpenMlsRand, crypto: &impl OpenMlsCrypto, old_signer: &impl Signer, new_signer: NewSignerBundle<'_, S>, f: impl FnMut(&QueuedProposal) -> bool, ) -> Result<CommitBuilder<'a, Complete>, CreateCommitError>
Just like build
, this function validates the inputs and builds the
commit. The last argument f
is a function that lets the caller filter
the proposals that are considered for inclusion. This provides a way for
the application to enforce custom policies in the creation of commits.
In contrast to build
, this function can be used to create commits that
rotate the own leaf node’s signature key.
Source§impl CommitBuilder<'_, Complete>
impl CommitBuilder<'_, Complete>
Sourcepub fn stage_commit<Provider: OpenMlsProvider>(
self,
provider: &Provider,
) -> Result<CommitMessageBundle, CommitBuilderStageError<Provider::StorageError>>
pub fn stage_commit<Provider: OpenMlsProvider>( self, provider: &Provider, ) -> Result<CommitMessageBundle, CommitBuilderStageError<Provider::StorageError>>
Stages the commit and returns the protocol messages.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for CommitBuilder<'a, T>where
T: Freeze,
impl<'a, T> RefUnwindSafe for CommitBuilder<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for CommitBuilder<'a, T>where
T: Send,
impl<'a, T> Sync for CommitBuilder<'a, T>where
T: Sync,
impl<'a, T> Unpin for CommitBuilder<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for CommitBuilder<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more