diff --git a/crates/bitwarden-vault/src/collection.rs b/crates/bitwarden-vault/src/collection.rs index ce798d92..3ec5ece2 100644 --- a/crates/bitwarden-vault/src/collection.rs +++ b/crates/bitwarden-vault/src/collection.rs @@ -9,6 +9,7 @@ use uuid::Uuid; use crate::VaultParseError; +/// Encrypted Collection state #[derive(Serialize, Deserialize, Debug, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] @@ -24,6 +25,7 @@ pub struct Collection { pub manage: bool, } +/// Decrypted Collection state #[derive(Serialize, Deserialize, Debug, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] @@ -40,6 +42,7 @@ pub struct CollectionView { } impl LocateKey for Collection { + /// Returns a [SymmetricCryptoKey] on success, [CryptoError] on failure fn locate_key<'a>( &self, enc: &'a dyn KeyContainer, @@ -48,6 +51,7 @@ impl LocateKey for Collection { enc.get_key(&Some(self.organization_id)) } } + impl KeyDecryptable for Collection { fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result { Ok(CollectionView { diff --git a/crates/bitwarden-vault/src/sync.rs b/crates/bitwarden-vault/src/sync.rs index be4c3b16..e623f8df 100644 --- a/crates/bitwarden-vault/src/sync.rs +++ b/crates/bitwarden-vault/src/sync.rs @@ -54,6 +54,7 @@ pub(crate) async fn sync(client: &Client, input: &SyncRequest) -> Result { + /// A vault client. pub(crate) client: &'a Client, } impl<'a> VaultClient<'a> { + /// Constructs a new [VaultClient] with the given [Client] + /// + /// # Examples + /// + /// ```rust + /// # use bitwarden_core::{Client,ClientSettings,DeviceType}; + /// # use bitwarden_vault::VaultClient; + /// # let client = Client::new(Some(ClientSettings { + /// # identity_url: "https://identity.bitwarden.com".to_owned(), + /// # api_url: "https://api.bitwarden.com".to_owned(), + /// # user_agent: "Bitwarden Rust-SDK".to_owned(), + /// # device_type: DeviceType::ChromeBrowser, + /// # })); + /// let vault = VaultClient::new(&client); + /// let ciphers = vault.ciphers(); + /// // ... + /// ``` pub fn new(client: &'a Client) -> Self { Self { client } } + /// Syncs the [VaultClient] with the server. + /// + /// # Examples + /// + /// ```rust + /// # use bitwarden_core::{Client,ClientSettings,DeviceType}; + /// # use bitwarden_vault::{VaultClient,SyncRequest, SyncResponse}; + /// async fn sync_vault(client: &Client) { + /// let vault = VaultClient::new(client); + /// let request = SyncRequest { + /// exclude_subdomains: Some(false), + /// }; + /// + /// let result = vault.sync(&request).await; + /// match result { + /// Ok(response) => println!("Response: {:?}", response), + /// Err(error) => { + /// eprintln!("Sync failed: {:?}", error); + /// }, + /// } + /// } + /// ``` pub async fn sync(&self, input: &SyncRequest) -> Result { sync(self.client, input).await } } +/// An extension trait for the [VaultClient] struct to provide vault functionality. pub trait VaultClientExt<'a> { fn vault(&'a self) -> VaultClient<'a>; }