Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/bitwarden-core/src/client/flags.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#[derive(Debug, Default, Clone, serde::Deserialize)]
/// Feature flags for the Bitwarden SDK client.
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
#[cfg_attr(
feature = "wasm",
derive(tsify::Tsify),
tsify(into_wasm_abi, from_wasm_abi)
)]
pub struct Flags {
/// Enable cipher key encryption within the `CipherClient`
#[serde(default, rename = "enableCipherKeyEncryption")]
pub enable_cipher_key_encryption: bool,
}

impl Flags {
/// Create a new `Flags` instance from a map of flag names and values.
pub fn load_from_map(map: std::collections::HashMap<String, bool>) -> Self {
let map = map
.into_iter()
Expand Down
6 changes: 6 additions & 0 deletions crates/bitwarden-core/src/client/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ impl InternalClient {
*self.flags.write().expect("RwLock is not poisoned") = Flags::load_from_map(flags);
}

#[allow(missing_docs)]
#[cfg(feature = "internal")]
pub fn set_flags(&self, flags: &Flags) {
*self.flags.write().expect("RwLock is not poisoned") = flags.clone();
}
Comment on lines +119 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have load_flags above, and #[allow(missing_docs)] is not allowed on new functions.


#[allow(missing_docs)]
#[cfg(feature = "internal")]
pub fn get_flags(&self) -> Flags {
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mod flags;

pub use client::Client;
pub use client_settings::{ClientSettings, DeviceType};
#[cfg(feature = "internal")]
pub use flags::Flags;

#[allow(missing_docs)]
#[cfg(feature = "internal")]
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub mod secrets_manager;
mod util;

pub use bitwarden_crypto::ZeroizingAllocator;
#[cfg(feature = "internal")]
pub use client::Flags;
pub use client::{Client, ClientSettings, DeviceType};

mod ids;
Expand Down
10 changes: 8 additions & 2 deletions crates/bitwarden-wasm-internal/src/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bitwarden_core::Client;
use bitwarden_core::{Client, Flags};
use bitwarden_vault::{Cipher, Folder};
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::prelude::*;

mod repository;
pub mod token_provider;
Expand All @@ -19,6 +19,12 @@ impl PlatformClient {
pub fn state(&self) -> StateClient {
StateClient::new(self.0.clone())
}

/// Load feature flags into the client
pub fn load_flags(&self, flags: Flags) -> Result<(), JsValue> {
self.0.internal.set_flags(&flags);
Ok(())
}
}

#[wasm_bindgen]
Expand Down
Loading