sos_database::storage

Struct ClientStorage

Source
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

Source

pub async fn new_unauthenticated( address: Address, paths: Arc<Paths>, ) -> Result<Self>

Create unauthenticated folder storage for client-side access.

Source

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.

Source

pub fn address(&self) -> &Address

Address of the account owner.

Source

pub fn devices(&self) -> &IndexSet<TrustedDevice>

Collection of trusted devices.

Source

pub fn cache(&self) -> &HashMap<VaultId, DiscFolder>

Cache of in-memory event logs.

Source

pub fn cache_mut(&mut self) -> &mut HashMap<VaultId, DiscFolder>

Mutable in-memory event logs.

Source

pub fn find_folder(&self, vault: &FolderRef) -> Option<&Summary>

Find a summary in this storage.

Source

pub fn find<F>(&self, predicate: F) -> Option<&Summary>
where F: FnMut(&&Summary) -> bool,

Find a summary in this storage.

Source

pub fn paths(&self) -> Arc<Paths>

Computed storage paths.

Source

pub async fn open_folder(&mut self, summary: &Summary) -> Result<ReadEvent>

Mark a folder as the currently open folder.

Source

pub fn close_folder(&mut self)

Close the current open folder.

Source

pub async fn create_account( &mut self, account: &AccountPack, ) -> Result<Vec<Event>>

Create the data for a new account.

Source

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.

Source

pub async fn restore_folder( &mut self, folder_id: &VaultId, records: Vec<EventRecord>, key: &AccessKey, ) -> Result<Summary>

Restore a folder from an event log.

Source

pub fn list_folders(&self) -> &[Summary]

List the folder summaries for this storage.

Source

pub fn current_folder(&self) -> Option<Summary>

Reference to the currently open folder.

Source

pub async fn read_vault(&self, id: &VaultId) -> Result<Vault>

Read a vault from the file on disc.

Source

pub async fn unlock(&mut self, keys: &FolderKeys) -> Result<()>

Unlock all folders.

Source

pub async fn lock(&mut self)

Lock all folders.

Source

pub async fn unlock_folder( &mut self, id: &VaultId, key: &AccessKey, ) -> Result<()>

Unlock a folder.

Source

pub async fn lock_folder(&mut self, id: &VaultId) -> Result<()>

Lock a folder.

Source

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.

Source

pub async fn create_folder( &mut self, name: String, options: NewFolderOptions, ) -> Result<(Vec<u8>, AccessKey, Summary, AccountEvent)>

Create a new folder.

Source

pub async fn compact_folder( &mut self, summary: &Summary, key: &AccessKey, ) -> Result<(AccountEvent, u64, u64)>

Compact an event log file.

Source

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.

Source

pub async fn delete_folder( &mut self, summary: &Summary, apply_event: bool, ) -> Result<Vec<Event>>

Delete a folder.

Source

pub async fn remove_folder(&mut self, folder_id: &VaultId) -> Result<bool>

Remove a folder from the cache.

Source

pub fn set_folder_name( &mut self, summary: &Summary, name: impl AsRef<str>, ) -> Result<()>

Update the in-memory name for a folder.

Source

pub fn set_folder_flags( &mut self, summary: &Summary, flags: VaultFlags, ) -> Result<()>

Update the in-memory name for a folder.

Source

pub async fn rename_folder( &mut self, summary: &Summary, name: impl AsRef<str>, ) -> Result<Event>

Set the name of a vault.

Source

pub async fn update_folder_flags( &mut self, summary: &Summary, flags: VaultFlags, ) -> Result<Event>

Update the flags for a vault.

Source

pub async fn description(&self) -> Result<String>

Get the description of the currently open folder.

Source

pub async fn set_description( &mut self, description: impl AsRef<str>, ) -> Result<WriteEvent>

Set the description of the currently open folder.

Source

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.

Source

pub async fn history( &self, summary: &Summary, ) -> Result<Vec<(CommitHash, UtcDateTime, WriteEvent)>>

Get the history of events for a vault.

Source

pub async fn identity_state(&self) -> Result<CommitState>

Commit state of the identity folder.

Source

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

Source

pub async fn create_secret( &mut self, secret_data: SecretRow, options: AccessOptions, ) -> Result<StorageChangeEvent>

Create a secret in the currently open vault.

Source

pub async fn raw_secret( &self, folder_id: &VaultId, secret_id: &SecretId, ) -> Result<(Option<Cow<'_, VaultCommit>>, ReadEvent)>

Read the encrypted contents of a secret.

Source

pub async fn read_secret( &self, id: &SecretId, ) -> Result<(SecretMeta, Secret, ReadEvent)>

Read a secret in the currently open folder.

Source

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.

Source

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.

Source

pub async fn delete_secret( &mut self, secret_id: &SecretId, options: AccessOptions, ) -> Result<StorageChangeEvent>

Delete a secret in the currently open vault.

Source

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

Source

pub fn list_trusted_devices(&self) -> Vec<&TrustedDevice>

List trusted devices.

Source

pub async fn patch_devices_unchecked( &mut self, events: Vec<DeviceEvent>, ) -> Result<()>

Patch the devices event log.

Source

pub async fn revoke_device( &mut self, public_key: &DevicePublicKey, ) -> Result<()>

Revoke trust in a device.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T