coven_replication/sync/store/authorization/
history_construction.rs1use coven_protocol::store_commit::StoreRootRef;
2use coven_storage::CloudSyncObjectStorage;
3
4use super::pull::StorePullError;
5use crate::sync::store::commit_verification::commit::StoreCommitVerifier;
6use crate::sync::store::commit_verification::merge_history::MergeHistoryVerifier;
7use crate::sync::store::protocol_root::VerifiedStoreRoot;
8
9#[derive(Clone, Copy)]
10pub struct HistoryConstructionAuthority(());
11
12impl HistoryConstructionAuthority {
13 pub(super) fn store() -> Self {
14 Self(())
15 }
16
17 pub fn admission() -> Self {
18 Self(())
19 }
20
21 pub(crate) fn founder() -> Self {
22 Self(())
23 }
24
25 pub(crate) fn for_pending_device_join() -> Self {
26 Self(())
27 }
28
29 pub fn for_snapshot() -> Self {
30 Self(())
31 }
32
33 pub async fn open_pinned<'storage>(
34 self,
35 storage: &'storage dyn CloudSyncObjectStorage,
36 root: &StoreRootRef,
37 ) -> Result<MergeHistoryVerifier<'storage>, StorePullError> {
38 let object =
39 crate::sync::store::protocol_root::load_pinned_store_protocol_root(storage, root)
40 .await
41 .map_err(StorePullError::ProtocolRoot)?;
42 let verified_root = VerifiedStoreRoot::from_verified_object(root.clone(), object)
43 .map_err(StorePullError::Protocol)?;
44 self.bind_verified(storage, verified_root).await
45 }
46
47 pub(super) async fn bind_verified<'storage>(
48 self,
49 storage: &'storage dyn CloudSyncObjectStorage,
50 root: VerifiedStoreRoot,
51 ) -> Result<MergeHistoryVerifier<'storage>, StorePullError> {
52 let commit_verifier = StoreCommitVerifier::from_verified_root(self, storage, root.clone());
53 MergeHistoryVerifier::from_commit_verifier(self, root, commit_verifier).await
54 }
55}