From bc68e356882739ba1b5b754c86ece3c5cfab10f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Mon, 4 Sep 2023 17:46:56 +0200 Subject: [PATCH 1/2] Add Sends api in bitwarden-uniffi --- crates/bitwarden-uniffi/src/vault/mod.rs | 8 +- crates/bitwarden-uniffi/src/vault/sends.rs | 104 +++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 crates/bitwarden-uniffi/src/vault/sends.rs diff --git a/crates/bitwarden-uniffi/src/vault/mod.rs b/crates/bitwarden-uniffi/src/vault/mod.rs index 53567c063..2692632ab 100644 --- a/crates/bitwarden-uniffi/src/vault/mod.rs +++ b/crates/bitwarden-uniffi/src/vault/mod.rs @@ -6,6 +6,7 @@ pub mod ciphers; pub mod collections; pub mod folders; pub mod password_history; +pub mod sends; #[derive(uniffi::Object)] pub struct ClientVault(pub(crate) Arc); @@ -27,8 +28,13 @@ impl ClientVault { Arc::new(ciphers::ClientCiphers(self.0.clone())) } - /// Ciphers operations + /// Password history operations pub fn password_history(self: Arc) -> Arc { Arc::new(password_history::ClientPasswordHistory(self.0.clone())) } + + /// Sends operations + pub fn sends(self: Arc) -> Arc { + Arc::new(sends::ClientSends(self.0.clone())) + } } diff --git a/crates/bitwarden-uniffi/src/vault/sends.rs b/crates/bitwarden-uniffi/src/vault/sends.rs new file mode 100644 index 000000000..6e2f1b879 --- /dev/null +++ b/crates/bitwarden-uniffi/src/vault/sends.rs @@ -0,0 +1,104 @@ +use std::{path::Path, sync::Arc}; + +use bitwarden::vault::{Send, SendListView, SendView}; + +use crate::{Client, Result}; + +#[derive(uniffi::Object)] +pub struct ClientSends(pub Arc); + +#[uniffi::export] +impl ClientSends { + /// Encrypt send + pub async fn encrypt(&self, send: SendView) -> Result { + Ok(self.0 .0.read().await.vault().sends().encrypt(send).await?) + } + + /// Encrypt a send file in memory + pub async fn encrypt_buffer(&self, send: Send, buffer: Vec) -> Result> { + Ok(self + .0 + .0 + .read() + .await + .vault() + .sends() + .encrypt_buffer(send, &buffer) + .await?) + } + + /// Encrypt a send file located in the file system + pub async fn encrypt_file( + &self, + send: Send, + decrypted_file_path: String, + encrypted_file_path: String, + ) -> Result<()> { + Ok(self + .0 + .0 + .read() + .await + .vault() + .sends() + .encrypt_file( + send, + Path::new(&decrypted_file_path), + Path::new(&encrypted_file_path), + ) + .await?) + } + + /// Decrypt send + pub async fn decrypt(&self, send: Send) -> Result { + Ok(self.0 .0.read().await.vault().sends().decrypt(send).await?) + } + + /// Decrypt send list + pub async fn decrypt_list(&self, sends: Vec) -> Result> { + Ok(self + .0 + .0 + .read() + .await + .vault() + .sends() + .decrypt_list(sends) + .await?) + } + + /// Decrypt a send file in memory + pub async fn decrypt_buffer(&self, send: Send, buffer: Vec) -> Result> { + Ok(self + .0 + .0 + .read() + .await + .vault() + .sends() + .decrypt_buffer(send, &buffer) + .await?) + } + + /// Decrypt a send file located in the file system + pub async fn decrypt_file( + &self, + send: Send, + encrypted_file_path: String, + decrypted_file_path: String, + ) -> Result<()> { + Ok(self + .0 + .0 + .read() + .await + .vault() + .sends() + .decrypt_file( + send, + Path::new(&encrypted_file_path), + Path::new(&decrypted_file_path), + ) + .await?) + } +} From 78bdf2fa179e636b9d01136d88c7e5244dec64c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Mon, 4 Sep 2023 18:19:51 +0200 Subject: [PATCH 2/2] Update doc.md --- .prettierignore | 5 +- crates/bitwarden-uniffi/src/docs.rs | 5 +- languages/kotlin/doc.md | 97 ++++++++++++++++++++++++++++- support/docs/docs.ts | 1 + 4 files changed, 105 insertions(+), 3 deletions(-) diff --git a/.prettierignore b/.prettierignore index ba98edfb6..d5ffe5a0e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,8 @@ target -languages +languages/* +!/languages/kotlin +languages/kotlin/* +!/languages/kotlin/doc.md schemas /crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts about.hbs diff --git a/crates/bitwarden-uniffi/src/docs.rs b/crates/bitwarden-uniffi/src/docs.rs index af9b9a8d5..94a40a0e9 100644 --- a/crates/bitwarden-uniffi/src/docs.rs +++ b/crates/bitwarden-uniffi/src/docs.rs @@ -3,7 +3,7 @@ use bitwarden::{ client::auth_settings::Kdf, mobile::crypto::InitCryptoRequest, tool::{ExportFormat, PassphraseGeneratorRequest, PasswordGeneratorRequest}, - vault::{Cipher, CipherView, Collection, Folder, FolderView}, + vault::{Cipher, CipherView, Collection, Folder, FolderView, Send, SendListView, SendView}, }; use schemars::JsonSchema; @@ -16,6 +16,9 @@ pub enum DocRef { Collection(Collection), Folder(Folder), FolderView(FolderView), + Send(Send), + SendView(SendView), + SendListView(SendListView), // Crypto InitCryptoRequest(InitCryptoRequest), diff --git a/languages/kotlin/doc.md b/languages/kotlin/doc.md index 6d0ed6b12..55e5124e2 100644 --- a/languages/kotlin/doc.md +++ b/languages/kotlin/doc.md @@ -291,6 +291,91 @@ Decrypt password history **Output**: std::result::Result +## ClientSends + +### `encrypt` + +Encrypt send + +**Arguments**: + +- self: +- send: SendView + +**Output**: std::result::Result + +### `encrypt_buffer` + +Encrypt a send file in memory + +**Arguments**: + +- self: +- send: Send +- buffer: Vec<> + +**Output**: std::result::Result + +### `encrypt_file` + +Encrypt a send file located in the file system + +**Arguments**: + +- self: +- send: Send +- decrypted_file_path: String +- encrypted_file_path: String + +**Output**: std::result::Result<,BitwardenError> + +### `decrypt` + +Decrypt send + +**Arguments**: + +- self: +- send: Send + +**Output**: std::result::Result + +### `decrypt_list` + +Decrypt send list + +**Arguments**: + +- self: +- sends: Vec + +**Output**: std::result::Result + +### `decrypt_buffer` + +Decrypt a send file in memory + +**Arguments**: + +- self: +- send: Send +- buffer: Vec<> + +**Output**: std::result::Result + +### `decrypt_file` + +Decrypt a send file located in the file system + +**Arguments**: + +- self: +- send: Send +- encrypted_file_path: String +- decrypted_file_path: String + +**Output**: std::result::Result<,BitwardenError> + ## ClientVault ### `folders` @@ -325,7 +410,7 @@ Ciphers operations ### `password_history` -Ciphers operations +Password history operations **Arguments**: @@ -333,6 +418,16 @@ Ciphers operations **Output**: Arc +### `sends` + +Sends operations + +**Arguments**: + +- self: Arc + +**Output**: Arc + # References References are generated from the JSON schemas and should mostly match the kotlin and swift diff --git a/support/docs/docs.ts b/support/docs/docs.ts index ed79c4c2c..14603dd57 100644 --- a/support/docs/docs.ts +++ b/support/docs/docs.ts @@ -28,6 +28,7 @@ const rootElements = [ "ClientFolders", "ClientGenerators", "ClientPasswordHistory", + "ClientSends", "ClientVault", ];