Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
17 changes: 17 additions & 0 deletions Cargo.lock

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

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bitwarden-api-identity = { path = "crates/bitwarden-api-identity", version = "=1
bitwarden-cli = { path = "crates/bitwarden-cli", version = "=1.0.0" }
bitwarden-core = { path = "crates/bitwarden-core", version = "=1.0.0" }
bitwarden-crypto = { path = "crates/bitwarden-crypto", version = "=1.0.0" }
bitwarden-error = { path = "crates/bitwarden-error", version = "=1.0.0" }
bitwarden-error-macro = { path = "crates/bitwarden-error-macro", version = "=1.0.0" }
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" }
Expand All @@ -32,17 +34,20 @@ bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
bitwarden-threading = { path = "crates/bitwarden-threading", 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" }
bitwarden-uuid = { path = "crates/bitwarden-uuid", version = "=1.0.0" }
bitwarden-uuid-macro = { path = "crates/bitwarden-uuid-macro", version = "=1.0.0" }
bitwarden-vault = { path = "crates/bitwarden-vault", version = "=1.0.0" }
bitwarden-error = { path = "crates/bitwarden-error", version = "=1.0.0" }
bitwarden-error-macro = { path = "crates/bitwarden-error-macro", version = "=1.0.0" }

# External crates that are expected to maintain a consistent version across all crates
chrono = { version = ">=0.4.26, <0.5", features = [
"clock",
"serde",
"std",
], default-features = false }
js-sys = { version = ">=0.3.72, <0.4" }
log = ">=0.4.18, <0.5"
proc-macro2 = ">=1.0.89, <2"
quote = ">=1.0.37, <2"
reqwest = { version = ">=0.12.5, <0.13", features = [
"json",
"multipart",
Expand All @@ -53,6 +58,7 @@ serde = { version = ">=1.0, <2.0", features = ["derive"] }
serde_json = ">=1.0.96, <2.0"
serde_qs = ">=0.12.0, <0.16"
serde_repr = ">=0.1.12, <0.2"
syn = ">=2.0.87, <3"
thiserror = ">=1.0.40, <3"
tokio = { version = "1.36.0", features = ["macros"] }
tsify-next = { version = ">=0.5.4, <0.6", features = [
Expand All @@ -62,7 +68,6 @@ uniffi = "=0.28.3"
uuid = { version = ">=1.3.3, <2.0", features = ["serde", "v4", "js"] }
validator = { version = ">=0.18.1, <0.20", features = ["derive"] }
wasm-bindgen = { version = ">=0.2.91, <0.3", features = ["serde-serialize"] }
js-sys = { version = ">=0.3.72, <0.4" }
wasm-bindgen-futures = "0.4.41"
wasm-bindgen-test = "0.3.45"

Expand Down
5 changes: 3 additions & 2 deletions crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ keywords.workspace = true
[features]
internal = ["dep:zxcvbn"]
no-memory-hardening = [
"bitwarden-crypto/no-memory-hardening"
"bitwarden-crypto/no-memory-hardening",
] # Disable memory hardening features
secrets = [] # Secrets manager API
uniffi = ["bitwarden-crypto/uniffi", "dep:uniffi"] # Uniffi bindings
wasm = [
"bitwarden-error/wasm",
"dep:wasm-bindgen",
"dep:tsify-next"
"dep:tsify-next",
] # WASM support

[dependencies]
Expand All @@ -33,6 +33,7 @@ bitwarden-api-api = { workspace = true }
bitwarden-api-identity = { workspace = true }
bitwarden-crypto = { workspace = true }
bitwarden-error = { workspace = true }
bitwarden-uuid = { workspace = true }
chrono = { workspace = true, features = ["std"] }
# We don't use this directly (it's used by rand), but we need it here to enable WASM support
getrandom = { version = ">=0.2.9, <0.3", features = ["js"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/bitwarden-core/src/ids.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use bitwarden_uuid::uuid;

uuid!(pub OrganizationId);
3 changes: 3 additions & 0 deletions crates/bitwarden-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ mod util;

pub use bitwarden_crypto::ZeroizingAllocator;
pub use client::{Client, ClientSettings, DeviceType};

mod ids;
pub use ids::*;
6 changes: 3 additions & 3 deletions crates/bitwarden-error-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ wasm = []

[dependencies]
darling = "0.20.10"
proc-macro2 = "1.0.89"
quote = "1.0.37"
syn = "2.0.87"
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { workspace = true }

[lints]
workspace = true
Expand Down
5 changes: 4 additions & 1 deletion crates/bitwarden-uniffi/src/vault/ciphers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bitwarden_core::OrganizationId;

use bitwarden_vault::{Cipher, CipherListView, CipherView, EncryptionContext, Fido2CredentialView};

use uuid::Uuid;

use crate::{error::Error, Result};
Expand Down Expand Up @@ -41,7 +44,7 @@ impl CiphersClient {
) -> Result<CipherView> {
Ok(self
.0
.move_to_organization(cipher, organization_id)
.move_to_organization(cipher, OrganizationId::new(organization_id))
.map_err(Error::Cipher)?)
}
}
29 changes: 29 additions & 0 deletions crates/bitwarden-uuid-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "bitwarden-uuid-macro"
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]
wasm = []

[dependencies]
proc-macro2 = { workspace = true }
syn = { workspace = true }
quote = { workspace = true }

[lints]
workspace = true

[lib]
proc-macro = true
74 changes: 74 additions & 0 deletions crates/bitwarden-uuid-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{
parse::{Parse, ParseStream},
parse_macro_input, Ident, Visibility,
};

#[proc_macro]
pub fn uuid(input: TokenStream) -> TokenStream {
// Parse input as: vis ident
let input = parse_macro_input!(input as IdTypeInput);
let ident = input.ident;
let vis = input.vis;
let name_str = ident.to_string();

let tsify_type = format!("Tagged<Uuid, \"{}\">", name_str);

let expanded = quote! {
#[cfg(feature = "wasm")]
#[derive(serde::Serialize, serde::Deserialize, tsify_next::Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
#[repr(transparent)]
#vis struct #ident(
#[tsify(type = #tsify_type)]
uuid::Uuid
);

#[cfg(not(feature = "wasm"))]
#[derive(serde::Serialize, serde::Deserialize)]
#[repr(transparent)]
#vis struct #ident(
uuid::Uuid
);

#[cfg(feature = "uniffi")]
uniffi::custom_newtype!(#ident, uuid::Uuid);

impl #ident {
pub fn new(value: uuid::Uuid) -> Self {
Self(value)
}
}

impl std::str::FromStr for #ident {
type Err = uuid::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
uuid::Uuid::from_str(s).map(Self)
}
}

impl From<#ident> for uuid::Uuid {
fn from(value: #ident) -> Self {
value.0
}
}
};

TokenStream::from(expanded)
}

// Helper struct to parse "vis ident"
struct IdTypeInput {
vis: Visibility,
ident: Ident,
}

impl Parse for IdTypeInput {
fn parse(input: ParseStream) -> syn::Result<Self> {
let vis: Visibility = input.parse()?;
let ident: Ident = input.parse()?;
Ok(IdTypeInput { vis, ident })
}
}
31 changes: 31 additions & 0 deletions crates/bitwarden-uuid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "bitwarden-uuid"
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]
wasm = [
"bitwarden-uuid-macro/wasm",
#"dep:js-sys",
#"dep:tsify-next",
#"dep:wasm-bindgen",
]

[dependencies]
bitwarden-uuid-macro = { workspace = true }

[lints]
workspace = true

[dev-dependencies]
1 change: 1 addition & 0 deletions crates/bitwarden-uuid/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use bitwarden_uuid_macro::uuid;
2 changes: 1 addition & 1 deletion crates/bitwarden-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ keywords.workspace = true
uniffi = [
"bitwarden-core/uniffi",
"bitwarden-crypto/uniffi",
"dep:uniffi"
"dep:uniffi",
] # Uniffi bindings
wasm = ["dep:tsify-next", "dep:wasm-bindgen"] # WASM support

Expand Down
16 changes: 10 additions & 6 deletions crates/bitwarden-vault/src/cipher/cipher_client.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use bitwarden_core::Client;
use bitwarden_core::{Client, OrganizationId};
use bitwarden_crypto::IdentifyKey;
use uuid::Uuid;

#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;

use super::EncryptionContext;
use crate::{
Cipher, CipherError, CipherListView, CipherView, DecryptError, EncryptError, VaultClient,
};

#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct CiphersClient {
pub(crate) client: Client,
}

#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl CiphersClient {
pub fn encrypt(&self, mut cipher_view: CipherView) -> Result<EncryptionContext, EncryptError> {
let user_id = self
Expand Down Expand Up @@ -64,10 +68,10 @@ impl CiphersClient {
pub fn move_to_organization(
&self,
mut cipher_view: CipherView,
organization_id: Uuid,
organization_id: OrganizationId,
) -> Result<CipherView, CipherError> {
let key_store = self.client.internal.get_key_store();
cipher_view.move_to_organization(&mut key_store.context(), organization_id)?;
cipher_view.move_to_organization(&mut key_store.context(), organization_id.into())?;
Ok(cipher_view)
}

Expand Down Expand Up @@ -215,7 +219,7 @@ mod tests {
// Move cipher to organization
let res = client.vault().ciphers().move_to_organization(
view,
"1bc9ac1e-f5aa-45f2-94bf-b181009709b8".parse().unwrap(),
OrganizationId("1bc9ac1e-f5aa-45f2-94bf-b181009709b8".parse().unwrap()),
);

assert!(res.is_err());
Expand Down Expand Up @@ -320,7 +324,7 @@ mod tests {
.ciphers()
.move_to_organization(
view,
"1bc9ac1e-f5aa-45f2-94bf-b181009709b8".parse().unwrap(),
OrganizationId("1bc9ac1e-f5aa-45f2-94bf-b181009709b8".parse().unwrap()),
)
.unwrap();
let EncryptionContext {
Expand Down
4 changes: 4 additions & 0 deletions crates/bitwarden-vault/src/folder_client.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use bitwarden_core::Client;
#[cfg(feature = "wasm")]
use wasm_bindgen::prelude::*;

use crate::{
error::{DecryptError, EncryptError},
Folder, FolderView, VaultClient,
};

#[cfg_attr(feature = "wasm", wasm_bindgen)]
pub struct FoldersClient {
pub(crate) client: Client,
}

#[cfg_attr(feature = "wasm", wasm_bindgen)]
impl FoldersClient {
pub fn encrypt(&self, folder_view: FolderView) -> Result<Folder, EncryptError> {
let key_store = self.client.internal.get_key_store();
Expand Down
28 changes: 28 additions & 0 deletions crates/bitwarden-wasm-internal/npm/package-lock.json

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

Loading
Loading