openmls/test_utils/
storage_state.rs1use 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#[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 #[openmls_traits::maybe_async]
27 pub async fn from_storage(
28 store: &impl StorageProvider<CURRENT_VERSION>,
29 group_id: &impl GroupId<CURRENT_VERSION>,
30 ) -> NonProposalGroupStorageState {
31 let own_leaf_nodes = store.own_leaf_nodes(group_id).await.unwrap();
32
33 let group_config = store.mls_group_join_config(group_id).await.unwrap();
34
35 let tree = store.tree(group_id).await.unwrap();
36 let confirmation_tag = store.confirmation_tag(group_id).await.unwrap();
37
38 let group_state = store.group_state(group_id).await.unwrap();
39
40 let context = store.group_context(group_id).await.unwrap();
41
42 let interim_transcript_hash = store
43 .interim_transcript_hash(group_id)
44 .await
45 .unwrap()
46 .map(|hash: InterimTranscriptHash| hash.0);
47
48 let message_secrets = store.message_secrets(group_id).await.unwrap();
49
50 let resumption_psk_secrets = store.resumption_psk_store(group_id).await.unwrap();
51 let own_leaf_index = store.own_leaf_index(group_id).await.unwrap();
52
53 let group_epoch_secrets = store.group_epoch_secrets(group_id).await.unwrap();
54
55 Self {
56 own_leaf_nodes,
57 group_config,
58 tree,
59 confirmation_tag,
60 group_state,
61 context,
62 interim_transcript_hash,
63 message_secrets,
64 resumption_psk_secrets,
65 own_leaf_index,
66 group_epoch_secrets,
67 }
68 }
69}
70
71#[derive(PartialEq)]
73pub struct GroupStorageState {
74 queued_proposals: Vec<(ProposalRef, QueuedProposal)>,
75 non_proposal_state: NonProposalGroupStorageState,
76}
77
78impl GroupStorageState {
79 pub fn non_proposal_state(&self) -> &NonProposalGroupStorageState {
80 &self.non_proposal_state
81 }
82 #[openmls_traits::maybe_async]
83 pub async fn from_storage(
84 store: &impl StorageProvider<CURRENT_VERSION>,
85 group_id: &impl GroupId<CURRENT_VERSION>,
86 ) -> GroupStorageState {
87 let queued_proposals = store.queued_proposals(group_id).await.unwrap();
88 let non_proposal_state = NonProposalGroupStorageState::from_storage(store, group_id).await;
89
90 GroupStorageState {
91 queued_proposals,
92 non_proposal_state,
93 }
94 }
95}