Skip to content

Commit

Permalink
feat: add support for decrypting folders
Browse files Browse the repository at this point in the history
  • Loading branch information
coroiu committed Oct 9, 2024
1 parent 1571dc5 commit 42bb86d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/bitwarden-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ uniffi = [
"bitwarden-crypto/uniffi",
"dep:uniffi",
] # Uniffi bindings
wasm = ["dep:tsify-next", "dep:wasm-bindgen"] # WASM support

[dependencies]
base64 = ">=0.22.1, <0.23"
Expand All @@ -38,6 +39,8 @@ sha2 = ">=0.10.6, <0.11"
thiserror = { workspace = true }
uniffi = { version = "=0.28.1", optional = true }
uuid = { workspace = true }
tsify-next = { workspace = true, optional = true }
wasm-bindgen = { workspace = true, optional = true }

[dev-dependencies]
tokio = { workspace = true, features = ["rt"] }
Expand Down
5 changes: 5 additions & 0 deletions crates/bitwarden-vault/src/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ use uuid::Uuid;

use crate::VaultParseError;

#[cfg(feature = "wasm")]
use {tsify_next::Tsify, wasm_bindgen::prelude::*};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]

Check warning on line 19 in crates/bitwarden-vault/src/folder.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-vault/src/folder.rs#L19

Added line #L19 was not covered by tests
pub struct Folder {
id: Option<Uuid>,
name: EncString,
Expand All @@ -22,6 +26,7 @@ pub struct Folder {
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]

Check warning on line 29 in crates/bitwarden-vault/src/folder.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-vault/src/folder.rs#L29

Added line #L29 was not covered by tests
pub struct FolderView {
pub id: Option<Uuid>,
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-wasm-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ crate-type = ["cdylib"]
bitwarden = { workspace = true, features = ["internal", "wasm"] }
bitwarden-core = { workspace = true, features = ["wasm"] }
bitwarden-crypto = { workspace = true, features = ["wasm"] }
bitwarden-vault = { workspace = true, features = ["wasm"] }
console_error_panic_hook = "0.1.7"
console_log = { version = "1.0.0", features = ["color"] }
js-sys = "0.3.68"
Expand Down
6 changes: 5 additions & 1 deletion crates/bitwarden-wasm-internal/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bitwarden::{Client, ClientSettings};
use log::{set_max_level, Level};
use wasm_bindgen::prelude::*;

use crate::ClientCrypto;
use crate::{vault::ClientVault, ClientCrypto};

#[wasm_bindgen]
pub enum LogLevel {
Expand Down Expand Up @@ -60,4 +60,8 @@ impl BitwardenClient {
pub fn crypto(&self) -> ClientCrypto {
ClientCrypto(self.0.clone())
}

Check warning on line 62 in crates/bitwarden-wasm-internal/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L60-L62

Added lines #L60 - L62 were not covered by tests

pub fn vault(&self) -> ClientVault {
ClientVault(self.0.clone())
}

Check warning on line 66 in crates/bitwarden-wasm-internal/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/client.rs#L64-L66

Added lines #L64 - L66 were not covered by tests
}
4 changes: 4 additions & 0 deletions crates/bitwarden-wasm-internal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
mod client;
mod crypto;
mod custom_types;
mod error;
mod vault;

pub use client::BitwardenClient;
pub use crypto::ClientCrypto;
pub use vault::folders::ClientFolders;
pub use vault::ClientVault;
20 changes: 20 additions & 0 deletions crates/bitwarden-wasm-internal/src/vault/folders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::rc::Rc;

use bitwarden::{
vault::{ClientVaultExt, Folder, FolderView},
Client,
};
use wasm_bindgen::prelude::*;

use crate::error::Result;

#[wasm_bindgen]

Check warning on line 11 in crates/bitwarden-wasm-internal/src/vault/folders.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/vault/folders.rs#L11

Added line #L11 was not covered by tests
pub struct ClientFolders(pub(crate) Rc<Client>);

#[wasm_bindgen]

Check warning on line 14 in crates/bitwarden-wasm-internal/src/vault/folders.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/vault/folders.rs#L14

Added line #L14 was not covered by tests
impl ClientFolders {
/// Decrypt folder
pub fn decrypt(&self, folder: Folder) -> Result<FolderView> {
Ok(self.0.vault().folders().decrypt(folder)?)
}

Check warning on line 19 in crates/bitwarden-wasm-internal/src/vault/folders.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/vault/folders.rs#L17-L19

Added lines #L17 - L19 were not covered by tests
}
18 changes: 18 additions & 0 deletions crates/bitwarden-wasm-internal/src/vault/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub mod folders;

use std::rc::Rc;

use bitwarden::Client;
use wasm_bindgen::prelude::*;

use crate::ClientFolders;

#[wasm_bindgen]

Check warning on line 10 in crates/bitwarden-wasm-internal/src/vault/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/vault/mod.rs#L10

Added line #L10 was not covered by tests
pub struct ClientVault(pub(crate) Rc<Client>);

#[wasm_bindgen]

Check warning on line 13 in crates/bitwarden-wasm-internal/src/vault/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/vault/mod.rs#L13

Added line #L13 was not covered by tests
impl ClientVault {
pub fn folders(&self) -> ClientFolders {
ClientFolders(self.0.clone())
}

Check warning on line 17 in crates/bitwarden-wasm-internal/src/vault/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm-internal/src/vault/mod.rs#L15-L17

Added lines #L15 - L17 were not covered by tests
}

0 comments on commit 42bb86d

Please sign in to comment.