From 7a6a78b99d9bed1eeebc2a15a60e463afdb20075 Mon Sep 17 00:00:00 2001 From: tangowithfoxtrot <5676771+tangowithfoxtrot@users.noreply.github.com> Date: Fri, 3 Jan 2025 08:53:16 -0800 Subject: [PATCH 1/2] add minimal docs --- crates/bitwarden-vault/src/collection.rs | 4 ++ crates/bitwarden-vault/src/sync.rs | 2 + crates/bitwarden-vault/src/vault_client.rs | 58 ++++++++++++++++++++++ 3 files changed, 64 insertions(+) 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..402cce95 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>; } From df097262674615b7dabc644728cd6773b941da51 Mon Sep 17 00:00:00 2001 From: tangowithfoxtrot <5676771+tangowithfoxtrot@users.noreply.github.com> Date: Fri, 3 Jan 2025 08:59:55 -0800 Subject: [PATCH 2/2] fix: typo --- crates/bitwarden-vault/src/sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bitwarden-vault/src/sync.rs b/crates/bitwarden-vault/src/sync.rs index 402cce95..e623f8df 100644 --- a/crates/bitwarden-vault/src/sync.rs +++ b/crates/bitwarden-vault/src/sync.rs @@ -54,7 +54,7 @@ pub(crate) async fn sync(client: &Client, input: &SyncRequest) -> Result