openmls/test_utils/
storage_state.rs

1use crate::prelude::{hash_ref::ProposalRef, past_secrets::MessageSecretsStore, *};
2
3use crate::schedule::psk::store::ResumptionPskStore;
4use crate::schedule::GroupEpochSecrets;
5use crate::treesync::TreeSync;
6
7use openmls_traits::storage::{traits::GroupId, StorageProvider, CURRENT_VERSION};
8
9/// All state associated only with a GroupId
10#[derive(PartialEq)]
11pub struct NonProposalGroupStorageState {
12    own_leaf_nodes: Vec<LeafNode>,
13    group_config: Option<MlsGroupJoinConfig>,
14    tree: Option<TreeSync>,
15    confirmation_tag: Option<ConfirmationTag>,
16    group_state: Option<MlsGroupState>,
17    context: Option<GroupContext>,
18    interim_transcript_hash: Option<Vec<u8>>,
19    message_secrets: Option<MessageSecretsStore>,
20    resumption_psk_secrets: Option<ResumptionPskStore>,
21    own_leaf_index: Option<LeafNodeIndex>,
22    group_epoch_secrets: Option<GroupEpochSecrets>,
23}
24
25impl NonProposalGroupStorageState {
26    pub fn from_storage(
27        store: &impl StorageProvider<CURRENT_VERSION>,
28        group_id: &impl GroupId<CURRENT_VERSION>,
29    ) -> NonProposalGroupStorageState {
30        let own_leaf_nodes = store.own_leaf_nodes(group_id).unwrap();
31
32        let group_config = store.mls_group_join_config(group_id).unwrap();
33
34        let tree = store.tree(group_id).unwrap();
35        let confirmation_tag = store.confirmation_tag(group_id).unwrap();
36
37        let group_state = store.group_state(group_id).unwrap();
38
39        let context = store.group_context(group_id).unwrap();
40
41        let interim_transcript_hash = store
42            .interim_transcript_hash(group_id)
43            .unwrap()
44            .map(|hash: InterimTranscriptHash| hash.0);
45
46        let message_secrets = store.message_secrets(group_id).unwrap();
47
48        let resumption_psk_secrets = store.resumption_psk_store(group_id).unwrap();
49        let own_leaf_index = store.own_leaf_index(group_id).unwrap();
50
51        let group_epoch_secrets = store.group_epoch_secrets(group_id).unwrap();
52
53        Self {
54            own_leaf_nodes,
55            group_config,
56            tree,
57            confirmation_tag,
58            group_state,
59            context,
60            interim_transcript_hash,
61            message_secrets,
62            resumption_psk_secrets,
63            own_leaf_index,
64            group_epoch_secrets,
65        }
66    }
67}
68
69/// All state associated only with a GroupId
70#[derive(PartialEq)]
71pub struct GroupStorageState {
72    queued_proposals: Vec<(ProposalRef, QueuedProposal)>,
73    non_proposal_state: NonProposalGroupStorageState,
74}
75
76impl GroupStorageState {
77    pub fn non_proposal_state(&self) -> &NonProposalGroupStorageState {
78        &self.non_proposal_state
79    }
80    pub fn from_storage(
81        store: &impl StorageProvider<CURRENT_VERSION>,
82        group_id: &impl GroupId<CURRENT_VERSION>,
83    ) -> GroupStorageState {
84        let queued_proposals = store.queued_proposals(group_id).unwrap();
85        let non_proposal_state = NonProposalGroupStorageState::from_storage(store, group_id);
86
87        GroupStorageState {
88            queued_proposals,
89            non_proposal_state,
90        }
91    }
92}