1use std::{fmt::Debug, future::Future};
4
5use anyhow::Result;
6use futures::Stream;
7
8use crate::{
9 types::{ExactLink, NamespaceId, NamespaceSecretKey, SubspaceId, SubspaceSecretKey},
10 Digest,
11};
12
13#[cfg(feature = "backend_iroh")]
14pub mod iroh;
15
16pub trait KeyResolverImpl<KeyId> {
17 fn id(&self) -> KeyId;
19 fn resolve(&self, data: &[u8]) -> KeyId;
21}
22
23pub trait EncryptionAlgorithmImpl<Digest> {
24 fn id(&self) -> Digest;
26 fn encrypt(&self, key_id: [u8; 32], data: &[u8]) -> Vec<u8>;
28 fn decrypt(&self, key_id: [u8; 32], data: &[u8]) -> Vec<u8>;
30}
31
32pub trait LeafStore: Debug {
47 fn key_resolvers(&self) -> Box<dyn Iterator<Item = &dyn KeyResolverImpl<Digest>> + '_>;
50 fn encryption_algorithms(
52 &self,
53 ) -> Box<dyn Iterator<Item = &dyn EncryptionAlgorithmImpl<Digest>> + '_>;
54
55 fn create_subspace(&self) -> impl Future<Output = Result<SubspaceId>>;
56 fn get_subspace_secret(
57 &self,
58 subspace: SubspaceId,
59 ) -> impl Future<Output = Result<Option<SubspaceSecretKey>>>;
60 fn list_subspaces(
61 &self,
62 ) -> impl Future<Output = Result<impl Stream<Item = anyhow::Result<SubspaceId>>>>;
63 fn import_subspace_secret(
64 &self,
65 subspace_secret: SubspaceSecretKey,
66 ) -> impl Future<Output = Result<SubspaceId>>;
67
68 fn create_namespace(&self) -> impl Future<Output = Result<NamespaceId>>;
69 fn list_namespaces(
70 &self,
71 ) -> impl Future<Output = Result<impl Stream<Item = anyhow::Result<NamespaceId>>>>;
72 fn get_namespace_secret(
73 &self,
74 namespace: NamespaceId,
75 ) -> impl Future<Output = Result<Option<NamespaceSecretKey>>>;
76 fn import_namespace_secret(
77 &self,
78 secret: [u8; 32],
79 ) -> impl Future<Output = Result<NamespaceId>>;
80
81 fn store_blob(
89 &self,
90 data: &[u8],
91 link: &ExactLink,
92 entity_snapshot_id: Digest,
93 ) -> impl Future<Output = Result<Digest>>;
94 fn del_blobs(
99 &self,
100 link: &ExactLink,
101 entity_snapshot_id: Digest,
102 ) -> impl Future<Output = Result<usize>>;
103 fn get_blob(&self, digest: Digest) -> impl Future<Output = Result<Vec<u8>>>;
105
106 fn store_entity(&self, link: &ExactLink, data: Vec<u8>)
107 -> impl Future<Output = Result<Digest>>;
108 fn del_entity(&self, link: &ExactLink) -> impl Future<Output = Result<()>>;
109 fn get_entity(&self, link: &ExactLink) -> impl Future<Output = Result<Option<Digest>>>;
110
111 fn list(
112 &self,
113 link: ExactLink,
114 limit: Option<u64>,
115 offset: Option<u64>,
116 ) -> impl Future<Output = Result<impl Stream<Item = anyhow::Result<ExactLink>>>>;
117}