| 1 |
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
// Copyright by contributors to this project. |
| 3 |
// SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 4 |
|
| 5 |
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize}; |
| 6 |
use mls_rs_core::group::Member; |
| 7 |
|
| 8 |
use super::{ |
| 9 |
confirmation_tag::ConfirmationTag, member_from_leaf_node, proposal::ReInitProposal, |
| 10 |
transcript_hash::InterimTranscriptHash, |
| 11 |
}; |
| 12 |
use crate::{ |
| 13 |
group::{GroupContext, TreeKemPublic}, |
| 14 |
tree_kem::node::LeafIndex, |
| 15 |
}; |
| 16 |
|
| 17 |
#[cfg_attr( |
| 18 |
all(feature = "ffi", not(test)), |
| 19 |
safer_ffi_gen::ffi_type(clone, opaque) |
| 20 |
)] |
| 21 |
#[derive(Clone, Debug, PartialEq, MlsSize, MlsEncode, MlsDecode)] |
| 22 |
#[non_exhaustive] |
| 23 |
pub struct GroupState { |
| 24 |
#[cfg(feature = "by_ref_proposal")] |
| 25 |
pub(crate) proposals: crate::group::ProposalCache, |
| 26 |
pub context: GroupContext, |
| 27 |
pub(crate) public_tree: TreeKemPublic, |
| 28 |
pub(crate) interim_transcript_hash: InterimTranscriptHash, |
| 29 |
pub(crate) pending_reinit: Option<ReInitProposal>, |
| 30 |
pub(crate) confirmation_tag: ConfirmationTag, |
| 31 |
} |
| 32 |
|
| 33 |
#[cfg(all(feature = "ffi", not(test)))] |
| 34 |
impl GroupState { |
| 35 |
pub fn context(&self) -> &GroupContext { |
| 36 |
&self.context |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
#[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::safer_ffi_gen)] |
| 41 |
impl GroupState { |
| 42 |
pub fn member_at_index(&self, index: u32) -> Option<Member> { |
| 43 |
let leaf_index = LeafIndex(index); |
| 44 |
|
| 45 |
self.public_tree |
| 46 |
.get_leaf_node(leaf_index) |
| 47 |
.ok() |
| 48 |
.map(|ln| member_from_leaf_node(ln, leaf_index)) |
| 49 |
} |
| 50 |
|
| 51 |
pub(crate) fn new( |
| 52 |
context: GroupContext, |
| 53 |
current_tree: TreeKemPublic, |
| 54 |
interim_transcript_hash: InterimTranscriptHash, |
| 55 |
confirmation_tag: ConfirmationTag, |
| 56 |
) -> Self { |
| 57 |
Self { |
| 58 |
#[cfg(feature = "by_ref_proposal")] |
| 59 |
proposals: crate::group::ProposalCache::new( |
| 60 |
context.protocol_version, |
| 61 |
context.group_id.clone(), |
| 62 |
), |
| 63 |
context, |
| 64 |
public_tree: current_tree, |
| 65 |
interim_transcript_hash, |
| 66 |
pending_reinit: None, |
| 67 |
confirmation_tag, |
| 68 |
} |
| 69 |
} |
| 70 |
} |