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

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

6 changes: 2 additions & 4 deletions crates/bitwarden-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"

Expand Down
19 changes: 5 additions & 14 deletions crates/bitwarden-auth/src/send_access/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(
Expand All @@ -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(),
Expand All @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions crates/bitwarden-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden-encoding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 0 additions & 4 deletions crates/bitwarden-uniffi-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions crates/bitwarden-uniffi-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,8 +30,8 @@ fn convert_error<E: std::error::Error + Send + Sync + 'static>(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<T, E: std::error::Error + Send + Sync + 'static>(
result: Result<T, E>,
) -> Result<T, anyhow::Error> {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading