sos_client_storage/
lib.rs

1#![deny(missing_docs)]
2#![forbid(unsafe_code)]
3#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
4//! Client storage for a backend target.
5use sos_core::{
6    crypto::{AccessKey, Cipher, KeyDerivation},
7    events::WriteEvent,
8    AccountId, VaultFlags, VaultId,
9};
10use sos_vault::Vault;
11
12mod database;
13mod error;
14#[cfg(feature = "files")]
15pub mod files;
16mod filesystem;
17pub(crate) mod folder_sync;
18mod secret_storage;
19mod storage;
20mod sync;
21mod traits;
22
23pub use error::Error;
24pub use storage::ClientStorage;
25pub use traits::{
26    ClientAccountStorage, ClientBaseStorage, ClientDeviceStorage,
27    ClientFolderStorage, ClientSecretStorage,
28};
29pub(crate) use traits::{ClientEventLogStorage, ClientVaultStorage};
30
31/// Result type for the client module.
32pub(crate) type Result<T> = std::result::Result<T, Error>;
33
34#[cfg(feature = "files")]
35use sos_external_files::FileMutationEvent;
36
37/// Options used when creating a new folder.
38#[derive(Debug, Default)]
39pub struct NewFolderOptions {
40    /// Folder name.
41    pub name: String,
42    /// Flags for the new folder.
43    pub flags: Option<VaultFlags>,
44    /// Access key.
45    pub key: Option<AccessKey>,
46    /// Encryption cipher.
47    pub cipher: Option<Cipher>,
48    /// Key derivation function.
49    pub kdf: Option<KeyDerivation>,
50}
51
52impl NewFolderOptions {
53    /// Create new folder options.
54    pub fn new(name: String) -> Self {
55        Self {
56            name,
57            flags: None,
58            key: None,
59            cipher: None,
60            kdf: None,
61        }
62    }
63}
64
65/// Collection of vaults for an account.
66#[derive(Default)]
67pub struct AccountPack {
68    /// Address of the account.
69    pub account_id: AccountId,
70    /// Identity vault.
71    pub identity_vault: Vault,
72    /// Addtional folders to be imported
73    /// into the new account.
74    pub folders: Vec<Vault>,
75}
76
77/// Options used when accessing account data.
78#[derive(Default, Clone)]
79pub struct AccessOptions {
80    /// Source folder for the operation.
81    ///
82    /// If no target folder is given the current open folder
83    /// will be used; it is an error if there is neither a
84    /// target folder or a currently open folder.
85    pub folder: Option<VaultId>,
86
87    /// Destination folder for the operation.
88    ///
89    /// Use during update operations to allow secrets
90    /// to be moved to a different folder.
91    pub destination: Option<VaultId>,
92
93    /// Channel for file progress operations.
94    #[cfg(feature = "files")]
95    pub file_progress:
96        Option<tokio::sync::mpsc::Sender<sos_external_files::FileProgress>>,
97}
98
99impl From<&VaultId> for AccessOptions {
100    fn from(value: &VaultId) -> Self {
101        Self {
102            folder: Some(*value),
103            ..Default::default()
104        }
105    }
106}
107
108impl From<Option<&VaultId>> for AccessOptions {
109    fn from(value: Option<&VaultId>) -> Self {
110        Self {
111            folder: value.copied(),
112            ..Default::default()
113        }
114    }
115}
116
117/// Storage change event with an optional
118/// collection of file mutation events.
119#[doc(hidden)]
120pub struct StorageChangeEvent {
121    /// Write event.
122    pub event: WriteEvent,
123    /// Collection of file mutation events.
124    #[cfg(feature = "files")]
125    pub file_events: Vec<FileMutationEvent>,
126}