pub struct ClientStorage {
pub identity_log: Arc<RwLock<FolderEventLog>>,
pub account_log: Arc<RwLock<AccountEventLog>>,
pub cache: HashMap<VaultId, DiscFolder>,
pub device_log: Arc<RwLock<DeviceEventLog>>,
pub devices: IndexSet<TrustedDevice>,
/* private fields */
}Expand description
Client storage for folders loaded into memory and mirrored to disc.
Fields§
§identity_log: Arc<RwLock<FolderEventLog>>Identity folder event log.
This is a clone of the main identity folder event log and is defined here so we can get the commit state for synchronization.
account_log: Arc<RwLock<AccountEventLog>>Account event log.
cache: HashMap<VaultId, DiscFolder>Folder event logs.
device_log: Arc<RwLock<DeviceEventLog>>Device event log.
devices: IndexSet<TrustedDevice>Reduced collection of devices.
Implementations§
Source§impl ClientStorage
impl ClientStorage
Sourcepub async fn new_unauthenticated(
address: Address,
paths: Arc<Paths>,
) -> Result<Self>
pub async fn new_unauthenticated( address: Address, paths: Arc<Paths>, ) -> Result<Self>
Create unauthenticated folder storage for client-side access.
Sourcepub async fn new_authenticated(
address: Address,
data_dir: Option<PathBuf>,
identity_log: Arc<RwLock<FolderEventLog>>,
device: TrustedDevice,
) -> Result<Self>
pub async fn new_authenticated( address: Address, data_dir: Option<PathBuf>, identity_log: Arc<RwLock<FolderEventLog>>, device: TrustedDevice, ) -> Result<Self>
Create folder storage for client-side access.
Sourcepub fn devices(&self) -> &IndexSet<TrustedDevice>
pub fn devices(&self) -> &IndexSet<TrustedDevice>
Collection of trusted devices.
Sourcepub fn cache(&self) -> &HashMap<VaultId, DiscFolder>
pub fn cache(&self) -> &HashMap<VaultId, DiscFolder>
Cache of in-memory event logs.
Sourcepub fn cache_mut(&mut self) -> &mut HashMap<VaultId, DiscFolder>
pub fn cache_mut(&mut self) -> &mut HashMap<VaultId, DiscFolder>
Mutable in-memory event logs.
Sourcepub fn find_folder(&self, vault: &FolderRef) -> Option<&Summary>
pub fn find_folder(&self, vault: &FolderRef) -> Option<&Summary>
Find a summary in this storage.
Sourcepub async fn open_folder(&mut self, summary: &Summary) -> Result<ReadEvent>
pub async fn open_folder(&mut self, summary: &Summary) -> Result<ReadEvent>
Mark a folder as the currently open folder.
Sourcepub fn close_folder(&mut self)
pub fn close_folder(&mut self)
Close the current open folder.
Sourcepub async fn create_account(
&mut self,
account: &AccountPack,
) -> Result<Vec<Event>>
pub async fn create_account( &mut self, account: &AccountPack, ) -> Result<Vec<Event>>
Create the data for a new account.
Sourcepub async fn import_folder_patches(
&mut self,
patches: HashMap<VaultId, FolderPatch>,
) -> Result<()>
pub async fn import_folder_patches( &mut self, patches: HashMap<VaultId, FolderPatch>, ) -> Result<()>
Create folders from a collection of folder patches.
If the folders already exist they will be overwritten.
Sourcepub async fn restore_folder(
&mut self,
folder_id: &VaultId,
records: Vec<EventRecord>,
key: &AccessKey,
) -> Result<Summary>
pub async fn restore_folder( &mut self, folder_id: &VaultId, records: Vec<EventRecord>, key: &AccessKey, ) -> Result<Summary>
Restore a folder from an event log.
Sourcepub fn list_folders(&self) -> &[Summary]
pub fn list_folders(&self) -> &[Summary]
List the folder summaries for this storage.
Sourcepub fn current_folder(&self) -> Option<Summary>
pub fn current_folder(&self) -> Option<Summary>
Reference to the currently open folder.
Sourcepub async fn read_vault(&self, id: &VaultId) -> Result<Vault>
pub async fn read_vault(&self, id: &VaultId) -> Result<Vault>
Read a vault from the file on disc.
Sourcepub async fn unlock(&mut self, keys: &FolderKeys) -> Result<()>
pub async fn unlock(&mut self, keys: &FolderKeys) -> Result<()>
Unlock all folders.
Sourcepub async fn unlock_folder(
&mut self,
id: &VaultId,
key: &AccessKey,
) -> Result<()>
pub async fn unlock_folder( &mut self, id: &VaultId, key: &AccessKey, ) -> Result<()>
Unlock a folder.
Sourcepub async fn lock_folder(&mut self, id: &VaultId) -> Result<()>
pub async fn lock_folder(&mut self, id: &VaultId) -> Result<()>
Lock a folder.
Sourcepub async fn import_folder(
&mut self,
buffer: impl AsRef<[u8]>,
key: Option<&AccessKey>,
apply_event: bool,
creation_time: Option<&UtcDateTime>,
) -> Result<(Event, Summary)>
pub async fn import_folder( &mut self, buffer: impl AsRef<[u8]>, key: Option<&AccessKey>, apply_event: bool, creation_time: Option<&UtcDateTime>, ) -> Result<(Event, Summary)>
Import a folder into an existing account.
If a folder with the same identifier already exists it is overwritten.
Buffer is the encoded representation of the vault.
Sourcepub async fn create_folder(
&mut self,
name: String,
options: NewFolderOptions,
) -> Result<(Vec<u8>, AccessKey, Summary, AccountEvent)>
pub async fn create_folder( &mut self, name: String, options: NewFolderOptions, ) -> Result<(Vec<u8>, AccessKey, Summary, AccountEvent)>
Create a new folder.
Sourcepub async fn compact_folder(
&mut self,
summary: &Summary,
key: &AccessKey,
) -> Result<(AccountEvent, u64, u64)>
pub async fn compact_folder( &mut self, summary: &Summary, key: &AccessKey, ) -> Result<(AccountEvent, u64, u64)>
Compact an event log file.
Sourcepub async fn load_folders(&mut self) -> Result<&[Summary]>
pub async fn load_folders(&mut self) -> Result<&[Summary]>
Read folders from the local disc and create the in-memory event logs for each folder on disc.
Sourcepub async fn delete_folder(
&mut self,
summary: &Summary,
apply_event: bool,
) -> Result<Vec<Event>>
pub async fn delete_folder( &mut self, summary: &Summary, apply_event: bool, ) -> Result<Vec<Event>>
Delete a folder.
Sourcepub async fn remove_folder(&mut self, folder_id: &VaultId) -> Result<bool>
pub async fn remove_folder(&mut self, folder_id: &VaultId) -> Result<bool>
Remove a folder from the cache.
Sourcepub fn set_folder_name(
&mut self,
summary: &Summary,
name: impl AsRef<str>,
) -> Result<()>
pub fn set_folder_name( &mut self, summary: &Summary, name: impl AsRef<str>, ) -> Result<()>
Update the in-memory name for a folder.
Sourcepub fn set_folder_flags(
&mut self,
summary: &Summary,
flags: VaultFlags,
) -> Result<()>
pub fn set_folder_flags( &mut self, summary: &Summary, flags: VaultFlags, ) -> Result<()>
Update the in-memory name for a folder.
Sourcepub async fn rename_folder(
&mut self,
summary: &Summary,
name: impl AsRef<str>,
) -> Result<Event>
pub async fn rename_folder( &mut self, summary: &Summary, name: impl AsRef<str>, ) -> Result<Event>
Set the name of a vault.
Sourcepub async fn update_folder_flags(
&mut self,
summary: &Summary,
flags: VaultFlags,
) -> Result<Event>
pub async fn update_folder_flags( &mut self, summary: &Summary, flags: VaultFlags, ) -> Result<Event>
Update the flags for a vault.
Sourcepub async fn description(&self) -> Result<String>
pub async fn description(&self) -> Result<String>
Get the description of the currently open folder.
Sourcepub async fn set_description(
&mut self,
description: impl AsRef<str>,
) -> Result<WriteEvent>
pub async fn set_description( &mut self, description: impl AsRef<str>, ) -> Result<WriteEvent>
Set the description of the currently open folder.
Sourcepub async fn change_password(
&mut self,
vault: &Vault,
current_key: AccessKey,
new_key: AccessKey,
) -> Result<AccessKey>
pub async fn change_password( &mut self, vault: &Vault, current_key: AccessKey, new_key: AccessKey, ) -> Result<AccessKey>
Change the password for a vault.
If the target vault is the currently selected vault the currently selected vault is unlocked with the new passphrase on success.
Sourcepub async fn history(
&self,
summary: &Summary,
) -> Result<Vec<(CommitHash, UtcDateTime, WriteEvent)>>
pub async fn history( &self, summary: &Summary, ) -> Result<Vec<(CommitHash, UtcDateTime, WriteEvent)>>
Get the history of events for a vault.
Sourcepub async fn identity_state(&self) -> Result<CommitState>
pub async fn identity_state(&self) -> Result<CommitState>
Commit state of the identity folder.
Sourcepub async fn commit_state(&self, summary: &Summary) -> Result<CommitState>
pub async fn commit_state(&self, summary: &Summary) -> Result<CommitState>
Get the commit state for a folder.
The folder must have at least one commit.
Source§impl ClientStorage
impl ClientStorage
Sourcepub async fn create_secret(
&mut self,
secret_data: SecretRow,
options: AccessOptions,
) -> Result<StorageChangeEvent>
pub async fn create_secret( &mut self, secret_data: SecretRow, options: AccessOptions, ) -> Result<StorageChangeEvent>
Create a secret in the currently open vault.
Sourcepub async fn raw_secret(
&self,
folder_id: &VaultId,
secret_id: &SecretId,
) -> Result<(Option<Cow<'_, VaultCommit>>, ReadEvent)>
pub async fn raw_secret( &self, folder_id: &VaultId, secret_id: &SecretId, ) -> Result<(Option<Cow<'_, VaultCommit>>, ReadEvent)>
Read the encrypted contents of a secret.
Sourcepub async fn read_secret(
&self,
id: &SecretId,
) -> Result<(SecretMeta, Secret, ReadEvent)>
pub async fn read_secret( &self, id: &SecretId, ) -> Result<(SecretMeta, Secret, ReadEvent)>
Read a secret in the currently open folder.
Sourcepub async fn update_secret(
&mut self,
secret_id: &SecretId,
meta: SecretMeta,
secret: Option<Secret>,
options: AccessOptions,
) -> Result<StorageChangeEvent>
pub async fn update_secret( &mut self, secret_id: &SecretId, meta: SecretMeta, secret: Option<Secret>, options: AccessOptions, ) -> Result<StorageChangeEvent>
Update a secret in the currently open folder.
Sourcepub async fn write_secret(
&mut self,
id: &SecretId,
secret_data: SecretRow,
is_update: bool,
) -> Result<WriteEvent>
pub async fn write_secret( &mut self, id: &SecretId, secret_data: SecretRow, is_update: bool, ) -> Result<WriteEvent>
Write a secret in the current open folder.
Unlike update_secret() this function does not support moving
between folders or managing external files which allows us
to avoid recursion when handling embedded file secrets which
require rewriting the secret once the files have been encrypted.
Sourcepub async fn delete_secret(
&mut self,
secret_id: &SecretId,
options: AccessOptions,
) -> Result<StorageChangeEvent>
pub async fn delete_secret( &mut self, secret_id: &SecretId, options: AccessOptions, ) -> Result<StorageChangeEvent>
Delete a secret in the currently open vault.
Sourcepub async fn remove_secret(&mut self, id: &SecretId) -> Result<WriteEvent>
pub async fn remove_secret(&mut self, id: &SecretId) -> Result<WriteEvent>
Remove a secret.
Any external files for the secret are left intact.
Source§impl ClientStorage
impl ClientStorage
Sourcepub fn list_trusted_devices(&self) -> Vec<&TrustedDevice>
pub fn list_trusted_devices(&self) -> Vec<&TrustedDevice>
List trusted devices.
Sourcepub async fn patch_devices_unchecked(
&mut self,
events: Vec<DeviceEvent>,
) -> Result<()>
pub async fn patch_devices_unchecked( &mut self, events: Vec<DeviceEvent>, ) -> Result<()>
Patch the devices event log.
Sourcepub async fn revoke_device(
&mut self,
public_key: &DevicePublicKey,
) -> Result<()>
pub async fn revoke_device( &mut self, public_key: &DevicePublicKey, ) -> Result<()>
Revoke trust in a device.
Auto Trait Implementations§
impl Freeze for ClientStorage
impl !RefUnwindSafe for ClientStorage
impl Send for ClientStorage
impl Sync for ClientStorage
impl Unpin for ClientStorage
impl !UnwindSafe for ClientStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more