Skip to content

Commit

Permalink
undo a bunch of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed May 16, 2024
1 parent 4e4643b commit b5d91f9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
17 changes: 16 additions & 1 deletion openmls/src/group/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ pub(crate) enum CoreGroupParseMessageError {

/// Create group context ext proposal error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateGroupContextExtProposalError {
pub enum CreateGroupContextExtProposalError<StorageError> {
/// See [`LibraryError`] for more details.
#[error(transparent)]
LibraryError(#[from] LibraryError),
Expand All @@ -513,6 +513,12 @@ pub enum CreateGroupContextExtProposalError {
/// See [`LeafNodeValidationError`] for more details.
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
/// See [`MlsGroupStateError`] for more details.
#[error(transparent)]
MlsGroupStateError(#[from] MlsGroupStateError<StorageError>),
/// See [`CreateCommitError`] for more details.
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError<StorageError>),
}

/// Error merging a commit.
Expand All @@ -537,6 +543,15 @@ pub enum GroupContextExtensionsProposalValidationError {
#[error(transparent)]
LibraryError(#[from] LibraryError),

/// The new extension types in required capabilties contails extensions that are not supported by all group members.
#[error(
"The new required capabilties contain extension types that are not supported by all group members."
)]
ExtensionNotSupportedByAllMembers,
/// Proposal changes the immutable metadata extension, which is not allowed.
#[error("Proposal changes the immutable metadata extension, which is not allowed.")]
ChangedImmutableMetadata,

/// The new extension types in required capabilties contails extensions that are not supported by all group members.
#[error(
"The new required capabilties contain extension types that are not supported by all group members."
Expand Down
17 changes: 17 additions & 0 deletions openmls/src/group/mls_group/membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ impl MlsGroup {
.leaf(leaf_index)
.map(|leaf| leaf.credential())
}

/// Returns the [`Member`] corresponding to the given
/// leaf index. Returns `None` if the member can not be found in this group.
pub fn member_at(&self, leaf_index: LeafNodeIndex) -> Option<Member> {
self.group
.public_group()
// This will return an error if the member can't be found.
.leaf(leaf_index)
.map(|leaf_node| {
Member::new(
leaf_index,
leaf_node.encryption_key().as_slice().to_vec(),
leaf_node.signature_key().as_slice().to_vec(),
leaf_node.credential().clone(),
)
})
}
}

/// Helper `enum` that classifies the kind of remove operation. This can be used to
Expand Down
48 changes: 46 additions & 2 deletions openmls/src/group/mls_group/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use openmls_traits::{signatures::Signer, storage::StorageProvider, types::Ciphersuite};

use super::{
core_group::create_commit_params::CreateCommitParams,
errors::{ProposalError, ProposeAddMemberError, ProposeRemoveMemberError},
CustomProposal, MlsGroup,
CreateGroupContextExtProposalError, CustomProposal, GroupContextExtensionProposal, MlsGroup,
MlsGroupState, PendingCommitState, Proposal,
};
use crate::{
binary_tree::LeafNodeIndex,
Expand All @@ -12,7 +14,7 @@ use crate::{
framing::MlsMessageOut,
group::{errors::CreateAddProposalError, GroupId, QueuedProposal},
key_packages::KeyPackage,
messages::proposals::ProposalOrRefType,
messages::{group_info::GroupInfo, proposals::ProposalOrRefType},
prelude::LibraryError,
schedule::PreSharedKeyId,
storage::OpenMlsProvider,
Expand Down Expand Up @@ -384,4 +386,46 @@ impl MlsGroup {

Ok((mls_message, proposal_ref))
}

/// Updates group context extensions
///
/// Returns an error when the group does not support all the required capabilities
/// in the new `extensions`.
#[allow(clippy::type_complexity)]
pub fn update_group_context_extensions<Provider: OpenMlsProvider>(
&mut self,
provider: &Provider,
extensions: Extensions,
signer: &impl Signer,
) -> Result<
(MlsMessageOut, Option<MlsMessageOut>, Option<GroupInfo>),
CreateGroupContextExtProposalError<Provider::StorageError>,
> {
self.is_operational()?;

// Create group context extension proposals
let inline_proposals = vec![Proposal::GroupContextExtensions(
GroupContextExtensionProposal { extensions },
)];

let params = CreateCommitParams::builder()
.framing_parameters(self.framing_parameters())
.proposal_store(&self.proposal_store)
.inline_proposals(inline_proposals)
.build();
let create_commit_result = self.group.create_commit(params, provider, signer)?;

let mls_messages = self.content_to_mls_message(create_commit_result.commit, provider)?;
self.group_state = MlsGroupState::PendingCommit(Box::new(PendingCommitState::Member(
create_commit_result.staged_commit,
)));

Ok((
mls_messages,
create_commit_result
.welcome_option
.map(|w| MlsMessageOut::from_welcome(w, self.group.version())),
create_commit_result.group_info,
))
}
}
5 changes: 5 additions & 0 deletions openmls/src/key_packages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ impl KeyPackage {
pub fn last_resort(&self) -> bool {
self.payload.extensions.contains(ExtensionType::LastResort)
}

/// Get the lifetime of the KeyPackage
pub fn life_time(&self) -> &Lifetime {
self.payload.leaf_node.life_time().unwrap()
}
}

/// Crate visible `KeyPackage` functions.
Expand Down
4 changes: 2 additions & 2 deletions openmls/src/messages/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ pub struct AppAckProposal {
TlsSize,
)]
pub struct GroupContextExtensionProposal {
extensions: Extensions,
pub(crate) extensions: Extensions,
}

impl GroupContextExtensionProposal {
Expand All @@ -478,7 +478,7 @@ impl GroupContextExtensionProposal {
}

/// Get the extensions of the proposal
pub(crate) fn extensions(&self) -> &Extensions {
pub fn extensions(&self) -> &Extensions {
&self.extensions
}
}
Expand Down

0 comments on commit b5d91f9

Please sign in to comment.