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
23 changes: 20 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bitwarden-exporters = { path = "crates/bitwarden-exporters", version = "=1.0.0"
bitwarden-fido = { path = "crates/bitwarden-fido", version = "=1.0.0" }
bitwarden-generators = { path = "crates/bitwarden-generators", version = "=1.0.0" }
bitwarden-ipc = { path = "crates/bitwarden-ipc", version = "=1.0.0" }
bitwarden-pm = { path = "crates/bitwarden-pm", version = "=1.0.0" }
bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
bitwarden-sm = { path = "bitwarden_license/bitwarden-sm", version = "=1.0.0" }
bitwarden-ssh = { path = "crates/bitwarden-ssh", version = "=1.0.0" }
Expand Down
58 changes: 58 additions & 0 deletions crates/bitwarden-pm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[package]
name = "bitwarden-pm"
description = """
Internal crate for the bitwarden crate. Do not use.
"""

version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
license-file.workspace = true
keywords.workspace = true

[features]
no-memory-hardening = [
"bitwarden-core/no-memory-hardening"
] # Disable memory hardening features
uniffi = [
"bitwarden-auth/uniffi",
"bitwarden-core/uniffi",
"bitwarden-exporters/uniffi",
"bitwarden-fido/uniffi",
"bitwarden-generators/uniffi",
"bitwarden-send/uniffi",
"bitwarden-vault/uniffi",
"dep:uniffi"
] # Uniffi bindings
wasm = [
"bitwarden-auth/wasm",
"bitwarden-core/wasm",
"bitwarden-exporters/wasm",
"bitwarden-generators/wasm",
"bitwarden-vault/wasm",
"dep:wasm-bindgen",
"dep:wasm-bindgen-futures",
"dep:tsify"
] # WASM support

[dependencies]
bitwarden-auth = { workspace = true }
bitwarden-core = { workspace = true, features = ["internal"] }
bitwarden-exporters = { workspace = true }
bitwarden-fido = { workspace = true }
bitwarden-generators = { workspace = true }
bitwarden-send = { workspace = true }
bitwarden-vault = { workspace = true }

thiserror = { workspace = true }
tsify = { workspace = true, optional = true }
uniffi = { workspace = true, optional = true, features = ["tokio"] }
wasm-bindgen = { workspace = true, optional = true }
wasm-bindgen-futures = { workspace = true, optional = true }

[lints]
workspace = true
1 change: 1 addition & 0 deletions crates/bitwarden-pm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Bitwarden Password Manager
73 changes: 73 additions & 0 deletions crates/bitwarden-pm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#![doc = include_str!("../README.md")]

use std::sync::Arc;

use bitwarden_auth::AuthClientExt as _;
use bitwarden_core::client::internal::ClientManagedTokens;
use bitwarden_exporters::ExporterClientExt as _;
use bitwarden_generators::GeneratorClientsExt as _;
use bitwarden_send::SendClientExt as _;
use bitwarden_vault::VaultClientExt as _;

#[cfg(feature = "uniffi")]
uniffi::setup_scaffolding!();

/// Re-export subclients for easier access
pub mod clients {
pub use bitwarden_auth::AuthClient;
pub use bitwarden_core::key_management::CryptoClient;
pub use bitwarden_exporters::ExporterClient;
pub use bitwarden_generators::GeneratorClient;
pub use bitwarden_send::SendClient;
pub use bitwarden_vault::VaultClient;
}

/// The main entry point for the Bitwarden Password Manager SDK
pub struct PasswordManagerClient(pub bitwarden_core::Client);

impl PasswordManagerClient {
/// Initialize a new instance of the SDK client
pub fn new(settings: Option<bitwarden_core::ClientSettings>) -> Self {
Self(bitwarden_core::Client::new(settings))
}

/// Initialize a new instance of the SDK client with client-managed tokens
pub fn new_with_client_tokens(
settings: Option<bitwarden_core::ClientSettings>,
tokens: Arc<dyn ClientManagedTokens>,
) -> Self {
Self(bitwarden_core::Client::new_with_client_tokens(
settings, tokens,
))
}

/// Auth operations
pub fn auth(&self) -> bitwarden_auth::AuthClient {
self.0.auth_new()
}

/// Crypto operations
pub fn crypto(&self) -> bitwarden_core::key_management::CryptoClient {
self.0.crypto()
}

/// Vault item operations
pub fn vault(&self) -> bitwarden_vault::VaultClient {
self.0.vault()
}

/// Exporter operations
pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {
self.0.exporters()
}

/// Generator operations
pub fn generator(&self) -> bitwarden_generators::GeneratorClient {
self.0.generator()
}

/// Send operations
pub fn sends(&self) -> bitwarden_send::SendClient {
self.0.sends()
}
}
9 changes: 9 additions & 0 deletions crates/bitwarden-pm/uniffi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[bindings.kotlin]
package_name = "com.bitwarden.pm"
generate_immutable_records = true
android = true

[bindings.swift]
ffi_module_name = "BitwardenPMFFI"
module_name = "BitwardenPM"
generate_immutable_records = true
1 change: 1 addition & 0 deletions crates/bitwarden-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bitwarden-encoding = { workspace = true, features = ["uniffi"] }
bitwarden-exporters = { workspace = true, features = ["uniffi"] }
bitwarden-fido = { workspace = true, features = ["uniffi"] }
bitwarden-generators = { workspace = true, features = ["uniffi"] }
bitwarden-pm = { workspace = true, features = ["uniffi"] }
bitwarden-send = { workspace = true, features = ["uniffi"] }
bitwarden-ssh = { workspace = true, features = ["uniffi"] }
bitwarden-state = { workspace = true, features = ["uniffi"] }
Expand Down
14 changes: 5 additions & 9 deletions crates/bitwarden-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ pub mod vault;
#[cfg(target_os = "android")]
mod android_support;

use bitwarden_exporters::ExporterClientExt;
use bitwarden_generators::GeneratorClientsExt;
use bitwarden_send::SendClientExt;
use bitwarden_vault::VaultClientExt;
use crypto::CryptoClient;
use error::{Error, Result};
use platform::PlatformClient;
Expand All @@ -33,7 +29,7 @@ use vault::VaultClient;

#[allow(missing_docs)]
#[derive(uniffi::Object)]
pub struct Client(pub(crate) bitwarden_core::Client);
pub struct Client(pub(crate) bitwarden_pm::PasswordManagerClient);

#[uniffi::export(async_runtime = "tokio")]
impl Client {
Expand All @@ -46,7 +42,7 @@ impl Client {
#[cfg(target_os = "android")]
android_support::init();

Self(bitwarden_core::Client::new(settings))
Self(bitwarden_pm::PasswordManagerClient::new(settings))
}

/// Crypto operations
Expand All @@ -61,7 +57,7 @@ impl Client {

#[allow(missing_docs)]
pub fn platform(&self) -> PlatformClient {
PlatformClient(self.0.clone())
PlatformClient(self.0 .0.clone())
}

/// Generator operations
Expand All @@ -86,7 +82,7 @@ impl Client {

/// Auth operations
pub fn auth(&self) -> AuthClient {
AuthClient(self.0.clone())
AuthClient(self.0 .0.clone())
}

/// Test method, echoes back the input
Expand All @@ -96,7 +92,7 @@ impl Client {

/// Test method, calls http endpoint
pub async fn http_get(&self, url: String) -> Result<String> {
let client = self.0.internal.get_http_client();
let client = self.0 .0.internal.get_http_client();
let res = client
.get(&url)
.send()
Expand Down
4 changes: 1 addition & 3 deletions crates/bitwarden-wasm-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ crate-type = ["cdylib"]

[dependencies]
async-trait = { workspace = true }
bitwarden-auth = { workspace = true, features = ["wasm"] }
bitwarden-core = { workspace = true, features = ["wasm", "internal"] }
bitwarden-crypto = { workspace = true, features = ["wasm"] }
bitwarden-error = { workspace = true }
bitwarden-exporters = { workspace = true, features = ["wasm"] }
bitwarden-generators = { workspace = true, features = ["wasm"] }
bitwarden-ipc = { workspace = true, features = ["wasm"] }
bitwarden-pm = { workspace = true, features = ["wasm"] }
bitwarden-ssh = { workspace = true, features = ["wasm"] }
bitwarden-state = { workspace = true, features = ["wasm"] }
bitwarden-state-migrations = { workspace = true, features = ["wasm"] }
Expand Down
39 changes: 19 additions & 20 deletions crates/bitwarden-wasm-internal/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
extern crate console_error_panic_hook;
use std::{fmt::Display, sync::Arc};

use bitwarden_auth::{AuthClient, AuthClientExt};
use bitwarden_core::{key_management::CryptoClient, Client, ClientSettings};
use bitwarden_core::ClientSettings;
use bitwarden_error::bitwarden_error;
use bitwarden_exporters::ExporterClientExt;
use bitwarden_generators::GeneratorClientsExt;
use bitwarden_vault::{VaultClient, VaultClientExt};
use bitwarden_pm::{clients::*, PasswordManagerClient};
use wasm_bindgen::prelude::*;

use crate::platform::{
token_provider::{JsTokenProvider, WasmClientManagedTokens},
PlatformClient,
};

#[allow(missing_docs)]
/// The main entry point for the Bitwarden SDK in WebAssembly environments
#[wasm_bindgen]
pub struct BitwardenClient(pub(crate) Client);
pub struct BitwardenClient(pub(crate) PasswordManagerClient);

#[wasm_bindgen]
impl BitwardenClient {
#[allow(missing_docs)]
/// Initialize a new instance of the SDK client
#[wasm_bindgen(constructor)]
pub fn new(token_provider: JsTokenProvider, settings: Option<ClientSettings>) -> Self {
let tokens = Arc::new(WasmClientManagedTokens::new(token_provider));
Self(Client::new_with_client_tokens(settings, tokens))
Self(PasswordManagerClient::new_with_client_tokens(
settings, tokens,
))
}

/// Test method, echoes back the input
pub fn echo(&self, msg: String) -> String {
msg
}

#[allow(missing_docs)]
/// Returns the current SDK version
pub fn version(&self) -> String {
env!("SDK_VERSION").to_owned()
}

#[allow(missing_docs)]
/// Test method, always throws an error
pub fn throw(&self, msg: String) -> Result<(), TestError> {
Err(TestError(msg))
}

/// Test method, calls http endpoint
pub async fn http_get(&self, url: String) -> Result<String, String> {
let client = self.0.internal.get_http_client();
let client = self.0 .0.internal.get_http_client();
let res = client.get(&url).send().await.map_err(|e| e.to_string())?;

res.text().await.map_err(|e| e.to_string())
}

/// Auth related operations.
pub fn auth(&self) -> AuthClient {
self.0.auth_new()
self.0.auth()
}

#[allow(missing_docs)]
/// Crypto related operations.
pub fn crypto(&self) -> CryptoClient {
self.0.crypto()
self.0 .0.crypto()
}

#[allow(missing_docs)]
/// Vault item related operations.
pub fn vault(&self) -> VaultClient {
self.0.vault()
}

/// Constructs a specific client for platform-specific functionality
pub fn platform(&self) -> PlatformClient {
PlatformClient::new(self.0.clone())
PlatformClient::new(self.0 .0.clone())
}

/// Constructs a specific client for generating passwords and passphrases
pub fn generator(&self) -> bitwarden_generators::GeneratorClient {
pub fn generator(&self) -> GeneratorClient {
self.0.generator()
}

#[allow(missing_docs)]
pub fn exporters(&self) -> bitwarden_exporters::ExporterClient {
/// Exporter related operations.
pub fn exporters(&self) -> ExporterClient {
self.0.exporters()
}
}
Expand Down
Loading