Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marta Mularczyk committed Nov 18, 2024
1 parent 9320806 commit 431ba42
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 24 deletions.
2 changes: 2 additions & 0 deletions mls-rs-core/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// Copyright by contributors to this project.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

mod context;
mod group_state;
mod proposal_type;
mod roster;

pub use context::*;
pub use group_state::*;
pub use proposal_type::*;
pub use roster::*;
21 changes: 20 additions & 1 deletion mls-rs-core/src/context.rs → mls-rs-core/src/group/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

use crate::{crypto::CipherSuite, extension::ExtensionList, protocol_version::ProtocolVersion};
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};
use core::{
fmt::{self, Debug},
ops::Deref,
Expand Down Expand Up @@ -78,6 +78,25 @@ impl Debug for GroupContext {

#[cfg_attr(all(feature = "ffi", not(test)), ::safer_ffi_gen::safer_ffi_gen)]
impl GroupContext {
/// Create a group context for a new MLS group.
pub fn new(
protocol_version: ProtocolVersion,
cipher_suite: CipherSuite,
group_id: Vec<u8>,
tree_hash: Vec<u8>,
extensions: ExtensionList,
) -> GroupContext {
GroupContext {
protocol_version,
cipher_suite,
group_id,
epoch: 0,
tree_hash,
confirmed_transcript_hash: vec![].into(),
extensions,
}
}

/// Get the current protocol version in use by the group.
pub fn version(&self) -> ProtocolVersion {
self.protocol_version
Expand Down
2 changes: 1 addition & 1 deletion mls-rs-core/src/identity/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright by contributors to this project.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

use crate::{context::GroupContext, error::IntoAnyError, extension::ExtensionList, time::MlsTime};
use crate::{error::IntoAnyError, extension::ExtensionList, group::GroupContext, time::MlsTime};
#[cfg(mls_build_async)]
use alloc::boxed::Box;
use alloc::vec::Vec;
Expand Down
1 change: 0 additions & 1 deletion mls-rs-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern crate alloc;
#[cfg(all(test, target_arch = "wasm32"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

pub mod context;
pub mod crypto;
pub mod debug;
pub mod error;
Expand Down
12 changes: 5 additions & 7 deletions mls-rs/src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ pub use group_info::GroupInfo;

pub use self::framing::{ContentType, Sender};
pub use commit::*;
pub use mls_rs_core::context::GroupContext;
pub use mls_rs_core::group::GroupContext;
pub use roster::*;

pub(crate) use mls_rs_core::context::ConfirmedTranscriptHash;
pub(crate) use mls_rs_core::group::ConfirmedTranscriptHash;
pub(crate) use util::*;

#[cfg(all(feature = "by_ref_proposal", feature = "external_client"))]
Expand Down Expand Up @@ -325,15 +325,13 @@ where
.map_err(|e| MlsError::CryptoProviderError(e.into_any_error()))
})?;

let context = GroupContext {
let context = GroupContext::new(
protocol_version,
cipher_suite,
group_id,
epoch: 0,
tree_hash,
confirmed_transcript_hash: vec![].into(),
extensions: group_context_extensions,
};
group_context_extensions,
);

let identity_provider = config.identity_provider();

Expand Down
12 changes: 6 additions & 6 deletions mls-rs/src/group/proposal_filter/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,19 @@ where
&self,
strategy: FilterStrategy,
proposals: ProposalBundle,
group_extensions_in_use: &ExtensionList,
new_extensions: &ExtensionList,
commit_time: Option<MlsTime>,
) -> Result<ApplyProposalsOutput, MlsError> {
let mut applied_proposals = self
.validate_new_nodes(strategy, proposals, group_extensions_in_use, commit_time)
.validate_new_nodes(strategy, proposals, new_extensions, commit_time)
.await?;

let mut new_tree = self.original_tree.clone();

let added = new_tree
.batch_edit(
&mut applied_proposals,
group_extensions_in_use,
new_extensions,
self.identity_provider,
self.cipher_suite_provider,
strategy.is_ignore(),
Expand All @@ -176,12 +176,12 @@ where
&self,
strategy: FilterStrategy,
mut proposals: ProposalBundle,
group_extensions_in_use: &ExtensionList,
new_extensions: &ExtensionList,
commit_time: Option<MlsTime>,
) -> Result<ProposalBundle, MlsError> {
let member_validation_context = MemberValidationContext::ForCommit {
current_context: self.original_context,
new_extensions: group_extensions_in_use,
new_extensions,
};

let leaf_node_validator = &LeafNodeValidator::new(
Expand Down Expand Up @@ -218,7 +218,7 @@ where
.valid_successor(
&old_leaf.signing_identity,
&leaf.signing_identity,
group_extensions_in_use,
new_extensions,
)
.await
.map_err(|e| MlsError::IdentityProviderError(e.into_any_error()))
Expand Down
10 changes: 5 additions & 5 deletions mls-rs/src/group/proposal_filter/filtering_lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ where
pub(super) async fn apply_tree_changes(
&self,
proposals: &ProposalBundle,
group_extensions_in_use: &ExtensionList,
new_extensions: &ExtensionList,
commit_time: Option<MlsTime>,
) -> Result<ApplyProposalsOutput, MlsError> {
self.validate_new_nodes(proposals, group_extensions_in_use, commit_time)
self.validate_new_nodes(proposals, new_extensions, commit_time)
.await?;

let mut new_tree = self.original_tree.clone();

let added = new_tree
.batch_edit_lite(
proposals,
group_extensions_in_use,
new_extensions,
self.identity_provider,
self.cipher_suite_provider,
)
Expand All @@ -124,12 +124,12 @@ where
async fn validate_new_nodes(
&self,
proposals: &ProposalBundle,
group_extensions_in_use: &ExtensionList,
new_extensions: &ExtensionList,
commit_time: Option<MlsTime>,
) -> Result<(), MlsError> {
let member_validation_context = MemberValidationContext::ForCommit {
current_context: self.original_context,
new_extensions: group_extensions_in_use,
new_extensions,
};

let leaf_node_validator = &LeafNodeValidator::new(
Expand Down
2 changes: 1 addition & 1 deletion mls-rs/src/group/transcript_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::{

use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use mls_rs_core::{
context::ConfirmedTranscriptHash, crypto::CipherSuiteProvider, error::IntoAnyError,
crypto::CipherSuiteProvider, error::IntoAnyError, group::ConfirmedTranscriptHash,
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion mls-rs/src/tree_kem/leaf_node_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ mod tests {
use assert_matches::assert_matches;
#[cfg(feature = "std")]
use core::time::Duration;
use mls_rs_core::context::GroupContext;
use mls_rs_core::crypto::CipherSuite;
use mls_rs_core::group::GroupContext;
use mls_rs_core::group::ProposalType;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion mls-rs/src/tree_kem/update_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use alloc::{vec, vec::Vec};
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
use mls_rs_core::{
context::GroupContext,
error::IntoAnyError,
group::GroupContext,
identity::{IdentityProvider, MemberValidationContext},
};

Expand Down

0 comments on commit 431ba42

Please sign in to comment.