diff --git a/Cargo.lock b/Cargo.lock index e4296da6d..e63e77b6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -354,8 +354,6 @@ dependencies = [ "reqwest", "serde", "serde_json", - "serde_qs", - "serde_urlencoded", "thiserror 2.0.12", "tokio", "tsify", @@ -760,7 +758,6 @@ name = "bitwarden-uniffi-error" version = "1.0.0" dependencies = [ "anyhow", - "uniffi", ] [[package]] diff --git a/crates/bitwarden-auth/Cargo.toml b/crates/bitwarden-auth/Cargo.toml index 88285b58d..a287bbeb3 100644 --- a/crates/bitwarden-auth/Cargo.toml +++ b/crates/bitwarden-auth/Cargo.toml @@ -23,16 +23,13 @@ wasm = [ "dep:wasm-bindgen-futures" ] # WASM support -# Note: dependencies must be alphabetized to pass the cargo sort check in the CI pipeline.. +# Note: dependencies must be alphabetized to pass the cargo sort check in the CI pipeline. [dependencies] bitwarden-core = { workspace = true, features = ["internal"] } bitwarden-error = { workspace = true } chrono = { workspace = true } reqwest = { workspace = true } serde = { workspace = true } -serde_json = { workspace = true } -serde_qs = { workspace = true } -serde_urlencoded = ">=0.7.1, <0.8" thiserror = { workspace = true } tsify = { workspace = true, optional = true } uniffi = { workspace = true, optional = true } @@ -41,6 +38,7 @@ wasm-bindgen-futures = { workspace = true, optional = true } [dev-dependencies] bitwarden-test = { workspace = true } +serde_json = { workspace = true } tokio = { workspace = true, features = ["rt"] } wiremock = "0.6.0" diff --git a/crates/bitwarden-auth/src/send_access/client.rs b/crates/bitwarden-auth/src/send_access/client.rs index 692564d45..3b295e0f7 100644 --- a/crates/bitwarden-auth/src/send_access/client.rs +++ b/crates/bitwarden-auth/src/send_access/client.rs @@ -49,16 +49,9 @@ impl SendAccessClient { .identity .client .post(&url) - .header( - reqwest::header::CONTENT_TYPE, - "application/x-www-form-urlencoded; charset=utf-8", - ) .header(reqwest::header::ACCEPT, "application/json") .header(reqwest::header::CACHE_CONTROL, "no-store") - // We can use `serde_urlencoded` to serialize the payload into a URL-encoded string - // because we don't have complex nested structures in the payload. - // If we had nested structures, we have to use serde_qs::to_string instead. - .body(serde_urlencoded::to_string(&payload).expect("Serialize should be infallible")); + .form(&payload); // Because of the ? operator, any errors from sending the request are automatically // wrapped in SendAccessTokenError::Unexpected as an UnexpectedIdentityError::Reqwest @@ -164,7 +157,7 @@ mod tests { // expect the headers we set in the client .and(matchers::header( reqwest::header::CONTENT_TYPE.as_str(), - "application/x-www-form-urlencoded; charset=utf-8", + "application/x-www-form-urlencoded", )) .and(matchers::header( reqwest::header::ACCEPT.as_str(), @@ -234,7 +227,7 @@ mod tests { // expect the headers we set in the client .and(matchers::header( reqwest::header::CONTENT_TYPE.as_str(), - "application/x-www-form-urlencoded; charset=utf-8", + "application/x-www-form-urlencoded", )) .and(matchers::header( reqwest::header::ACCEPT.as_str(), @@ -298,8 +291,6 @@ mod tests { otp: otp.into(), }; - let email_param = serde_urlencoded::to_string([("email", email)]).unwrap(); // "email=valid%40email.com" - let req = SendAccessTokenRequest { send_id: "valid-send-id".into(), send_access_credentials: Some(SendAccessCredentials::EmailOtp( @@ -312,7 +303,7 @@ mod tests { // expect the headers we set in the client .and(matchers::header( reqwest::header::CONTENT_TYPE.as_str(), - "application/x-www-form-urlencoded; charset=utf-8", + "application/x-www-form-urlencoded", )) .and(matchers::header( reqwest::header::ACCEPT.as_str(), @@ -330,7 +321,7 @@ mod tests { ))) .and(body_string_contains(format!("scope={}", scope_str))) .and(body_string_contains(format!("send_id={}", req.send_id))) - .and(body_string_contains(email_param)) + .and(body_string_contains("email=valid%40email.com")) .and(body_string_contains(format!("otp={}", otp))) // respond with the mock success response .respond_with(ResponseTemplate::new(200).set_body_json(raw_success)); diff --git a/crates/bitwarden-core/Cargo.toml b/crates/bitwarden-core/Cargo.toml index 2b498f26a..b6093d487 100644 --- a/crates/bitwarden-core/Cargo.toml +++ b/crates/bitwarden-core/Cargo.toml @@ -24,9 +24,11 @@ uniffi = [ "internal", "bitwarden-crypto/uniffi", "bitwarden-encoding/uniffi", + "dep:bitwarden-uniffi-error", "dep:uniffi" ] # Uniffi bindings wasm = [ + "bitwarden-crypto/wasm", "bitwarden-encoding/wasm", "bitwarden-error/wasm", "dep:wasm-bindgen", @@ -42,7 +44,7 @@ bitwarden-crypto = { workspace = true } bitwarden-encoding = { workspace = true } bitwarden-error = { workspace = true } bitwarden-state = { workspace = true } -bitwarden-uniffi-error = { workspace = true } +bitwarden-uniffi-error = { workspace = true, optional = 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 diff --git a/crates/bitwarden-crypto/Cargo.toml b/crates/bitwarden-crypto/Cargo.toml index ea692171d..0da4085fc 100644 --- a/crates/bitwarden-crypto/Cargo.toml +++ b/crates/bitwarden-crypto/Cargo.toml @@ -16,9 +16,13 @@ keywords.workspace = true [features] default = [] -no-memory-hardening = [] # Disable memory hardening features -uniffi = ["bitwarden-encoding/uniffi", "dep:uniffi"] # Uniffi bindings -wasm = ["dep:tsify", "dep:wasm-bindgen"] # WASM support +no-memory-hardening = [] # Disable memory hardening features +uniffi = [ + "bitwarden-encoding/uniffi", + "dep:bitwarden-uniffi-error", + "dep:uniffi" +] # Uniffi bindings +wasm = ["dep:tsify", "dep:wasm-bindgen"] # WASM support [dependencies] aes = { version = ">=0.8.2, <0.9", features = ["zeroize"] } @@ -28,7 +32,7 @@ argon2 = { version = ">=0.5.0, <0.6", features = [ ], default-features = false } bitwarden-encoding = { workspace = true } bitwarden-error = { workspace = true } -bitwarden-uniffi-error = { workspace = true } +bitwarden-uniffi-error = { workspace = true, optional = true } cbc = { version = ">=0.1.2, <0.2", features = ["alloc", "zeroize"] } chacha20poly1305 = { version = "0.10.1" } ciborium = { version = ">=0.2.2, <0.3" } diff --git a/crates/bitwarden-encoding/Cargo.toml b/crates/bitwarden-encoding/Cargo.toml index 6a4bb1856..3a11caaf4 100644 --- a/crates/bitwarden-encoding/Cargo.toml +++ b/crates/bitwarden-encoding/Cargo.toml @@ -15,11 +15,11 @@ license-file.workspace = true keywords.workspace = true [features] -uniffi = ["dep:uniffi"] +uniffi = ["dep:bitwarden-uniffi-error", "dep:uniffi"] wasm = ["dep:tsify", "dep:wasm-bindgen"] [dependencies] -bitwarden-uniffi-error = { workspace = true } +bitwarden-uniffi-error = { workspace = true, optional = true } data-encoding = { workspace = true } data-encoding-macro = "0.1.18" serde = { workspace = true } diff --git a/crates/bitwarden-uniffi-error/Cargo.toml b/crates/bitwarden-uniffi-error/Cargo.toml index a33ff25ac..4daa0b272 100644 --- a/crates/bitwarden-uniffi-error/Cargo.toml +++ b/crates/bitwarden-uniffi-error/Cargo.toml @@ -14,12 +14,8 @@ repository.workspace = true license-file.workspace = true keywords.workspace = true -[features] -uniffi = ["dep:uniffi"] - [dependencies] anyhow = { version = ">=1.0, <2.0" } -uniffi = { workspace = true, optional = true } [lints] workspace = true diff --git a/crates/bitwarden-uniffi-error/src/lib.rs b/crates/bitwarden-uniffi-error/src/lib.rs index 3b2102bf7..df24fef87 100644 --- a/crates/bitwarden-uniffi-error/src/lib.rs +++ b/crates/bitwarden-uniffi-error/src/lib.rs @@ -9,7 +9,8 @@ static ERROR_TO_UNIFFI_ERROR: OnceLock< pub use anyhow::Error; -/// Configure an error converter to convert errors in calls to [`uniffi::custom_type!`] into the +/// Configure an error converter to convert errors in calls to +/// [`uniffi::custom_type!`](https://docs.rs/uniffi/latest/uniffi/macro.custom_type.html) into the /// main error of the application (`bitwarden_uniffi::error::BitwardenError). This is needed because /// if the errors don't match, Uniffi will panic instead of returning an error. This needs to be /// called by the `bitwarden_uniffi` crate before any other Uniffi code is run. @@ -29,8 +30,8 @@ fn convert_error(error: E) -> anyh } /// Convert a `Result` into one that will not cause a panic when called inside -/// [`uniffi::custom_type!`]. It is required that all the results created inside a `custom_type!` -/// are converted using this function. +/// [`uniffi::custom_type!`](https://docs.rs/uniffi/latest/uniffi/macro.custom_type.html). It is +/// required that all the results created inside a `custom_type!` are converted using this function. pub fn convert_result( result: Result, ) -> Result { diff --git a/crates/bitwarden-uniffi/Cargo.toml b/crates/bitwarden-uniffi/Cargo.toml index bd9ffdbd7..f99b9764e 100644 --- a/crates/bitwarden-uniffi/Cargo.toml +++ b/crates/bitwarden-uniffi/Cargo.toml @@ -31,7 +31,7 @@ bitwarden-send = { workspace = true, features = ["uniffi"] } bitwarden-ssh = { workspace = true, features = ["uniffi"] } bitwarden-state = { workspace = true, features = ["uniffi"] } bitwarden-state-migrations = { workspace = true, features = ["uniffi"] } -bitwarden-uniffi-error = { workspace = true, features = ["uniffi"] } +bitwarden-uniffi-error = { workspace = true } bitwarden-vault = { workspace = true, features = ["uniffi"] } chrono = { workspace = true, features = ["std"] } env_logger = "0.11.1"