Skip to main content

aven_core/sync/client/
host.rs

1//! What engine operations need from their host besides HTTP.
2use std::path::PathBuf;
3use std::sync::Arc;
4
5use anyhow::Result;
6
7use super::keys::{ProtectedLocalKeyStore, ProtectedStorage, StoreResult};
8use crate::db::Database;
9
10pub trait ClientHost: Send + Sync {
11    /// Refuses sync while the host's policy disables it.
12    fn ensure_sync_allowed(&self) -> Result<()>;
13
14    /// Storage for protected keys. Called only when an operation opens the
15    /// key store, so databases that don't take part in sync never need it.
16    fn protected_storage(&self) -> StoreResult<Arc<dyn ProtectedStorage>>;
17
18    /// The local image blob root of `database`.
19    fn blob_dir(&self, database: &Database) -> Result<PathBuf>;
20
21    /// Lifecycle limits for images installed from encrypted sync.
22    fn attachment_lifecycle_policy(&self) -> crate::attachments::LifecyclePolicy;
23
24    /// A name other devices show for this one, such as the computer name.
25    /// Asked for only while this device has no published label; control
26    /// characters are dropped and the length is bounded.
27    fn device_label(&self) -> Option<String>;
28}
29
30pub(crate) async fn key_store(
31    host: &dyn ClientHost,
32    database: &Database,
33) -> Result<ProtectedLocalKeyStore> {
34    Ok(ProtectedLocalKeyStore::open(database, host.protected_storage()?).await?)
35}