Skip to content

Commit d0262d3

Browse files
authored
Cleanup dependencies (#466)
Removes some unnecessary dependencies from `bitwarden-auth`. - `serde_json` only used in tests. - `serde_qs` never used. - `serde_urlencoded` replaced manual form handling with the `.form` method from `reqwest`. Changed `bitwarden-uniffi-error` to be optional and removed `uniffi` as a dependency from it.
1 parent 92bb5c3 commit d0262d3

File tree

9 files changed

+25
-36
lines changed

9 files changed

+25
-36
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bitwarden-auth/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ wasm = [
2323
"dep:wasm-bindgen-futures"
2424
] # WASM support
2525

26-
# Note: dependencies must be alphabetized to pass the cargo sort check in the CI pipeline..
26+
# Note: dependencies must be alphabetized to pass the cargo sort check in the CI pipeline.
2727
[dependencies]
2828
bitwarden-core = { workspace = true, features = ["internal"] }
2929
bitwarden-error = { workspace = true }
3030
chrono = { workspace = true }
3131
reqwest = { workspace = true }
3232
serde = { workspace = true }
33-
serde_json = { workspace = true }
34-
serde_qs = { workspace = true }
35-
serde_urlencoded = ">=0.7.1, <0.8"
3633
thiserror = { workspace = true }
3734
tsify = { workspace = true, optional = true }
3835
uniffi = { workspace = true, optional = true }
@@ -41,6 +38,7 @@ wasm-bindgen-futures = { workspace = true, optional = true }
4138

4239
[dev-dependencies]
4340
bitwarden-test = { workspace = true }
41+
serde_json = { workspace = true }
4442
tokio = { workspace = true, features = ["rt"] }
4543
wiremock = "0.6.0"
4644

crates/bitwarden-auth/src/send_access/client.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,9 @@ impl SendAccessClient {
4949
.identity
5050
.client
5151
.post(&url)
52-
.header(
53-
reqwest::header::CONTENT_TYPE,
54-
"application/x-www-form-urlencoded; charset=utf-8",
55-
)
5652
.header(reqwest::header::ACCEPT, "application/json")
5753
.header(reqwest::header::CACHE_CONTROL, "no-store")
58-
// We can use `serde_urlencoded` to serialize the payload into a URL-encoded string
59-
// because we don't have complex nested structures in the payload.
60-
// If we had nested structures, we have to use serde_qs::to_string instead.
61-
.body(serde_urlencoded::to_string(&payload).expect("Serialize should be infallible"));
54+
.form(&payload);
6255

6356
// Because of the ? operator, any errors from sending the request are automatically
6457
// wrapped in SendAccessTokenError::Unexpected as an UnexpectedIdentityError::Reqwest
@@ -164,7 +157,7 @@ mod tests {
164157
// expect the headers we set in the client
165158
.and(matchers::header(
166159
reqwest::header::CONTENT_TYPE.as_str(),
167-
"application/x-www-form-urlencoded; charset=utf-8",
160+
"application/x-www-form-urlencoded",
168161
))
169162
.and(matchers::header(
170163
reqwest::header::ACCEPT.as_str(),
@@ -234,7 +227,7 @@ mod tests {
234227
// expect the headers we set in the client
235228
.and(matchers::header(
236229
reqwest::header::CONTENT_TYPE.as_str(),
237-
"application/x-www-form-urlencoded; charset=utf-8",
230+
"application/x-www-form-urlencoded",
238231
))
239232
.and(matchers::header(
240233
reqwest::header::ACCEPT.as_str(),
@@ -298,8 +291,6 @@ mod tests {
298291
otp: otp.into(),
299292
};
300293

301-
let email_param = serde_urlencoded::to_string([("email", email)]).unwrap(); // "email=valid%40email.com"
302-
303294
let req = SendAccessTokenRequest {
304295
send_id: "valid-send-id".into(),
305296
send_access_credentials: Some(SendAccessCredentials::EmailOtp(
@@ -312,7 +303,7 @@ mod tests {
312303
// expect the headers we set in the client
313304
.and(matchers::header(
314305
reqwest::header::CONTENT_TYPE.as_str(),
315-
"application/x-www-form-urlencoded; charset=utf-8",
306+
"application/x-www-form-urlencoded",
316307
))
317308
.and(matchers::header(
318309
reqwest::header::ACCEPT.as_str(),
@@ -330,7 +321,7 @@ mod tests {
330321
)))
331322
.and(body_string_contains(format!("scope={}", scope_str)))
332323
.and(body_string_contains(format!("send_id={}", req.send_id)))
333-
.and(body_string_contains(email_param))
324+
.and(body_string_contains("email=valid%40email.com"))
334325
.and(body_string_contains(format!("otp={}", otp)))
335326
// respond with the mock success response
336327
.respond_with(ResponseTemplate::new(200).set_body_json(raw_success));

crates/bitwarden-core/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ uniffi = [
2424
"internal",
2525
"bitwarden-crypto/uniffi",
2626
"bitwarden-encoding/uniffi",
27+
"dep:bitwarden-uniffi-error",
2728
"dep:uniffi"
2829
] # Uniffi bindings
2930
wasm = [
31+
"bitwarden-crypto/wasm",
3032
"bitwarden-encoding/wasm",
3133
"bitwarden-error/wasm",
3234
"dep:wasm-bindgen",
@@ -42,7 +44,7 @@ bitwarden-crypto = { workspace = true }
4244
bitwarden-encoding = { workspace = true }
4345
bitwarden-error = { workspace = true }
4446
bitwarden-state = { workspace = true }
45-
bitwarden-uniffi-error = { workspace = true }
47+
bitwarden-uniffi-error = { workspace = true, optional = true }
4648
bitwarden-uuid = { workspace = true }
4749
chrono = { workspace = true, features = ["std"] }
4850
# We don't use this directly (it's used by rand), but we need it here to enable WASM support

crates/bitwarden-crypto/Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ keywords.workspace = true
1616

1717
[features]
1818
default = []
19-
no-memory-hardening = [] # Disable memory hardening features
20-
uniffi = ["bitwarden-encoding/uniffi", "dep:uniffi"] # Uniffi bindings
21-
wasm = ["dep:tsify", "dep:wasm-bindgen"] # WASM support
19+
no-memory-hardening = [] # Disable memory hardening features
20+
uniffi = [
21+
"bitwarden-encoding/uniffi",
22+
"dep:bitwarden-uniffi-error",
23+
"dep:uniffi"
24+
] # Uniffi bindings
25+
wasm = ["dep:tsify", "dep:wasm-bindgen"] # WASM support
2226

2327
[dependencies]
2428
aes = { version = ">=0.8.2, <0.9", features = ["zeroize"] }
@@ -28,7 +32,7 @@ argon2 = { version = ">=0.5.0, <0.6", features = [
2832
], default-features = false }
2933
bitwarden-encoding = { workspace = true }
3034
bitwarden-error = { workspace = true }
31-
bitwarden-uniffi-error = { workspace = true }
35+
bitwarden-uniffi-error = { workspace = true, optional = true }
3236
cbc = { version = ">=0.1.2, <0.2", features = ["alloc", "zeroize"] }
3337
chacha20poly1305 = { version = "0.10.1" }
3438
ciborium = { version = ">=0.2.2, <0.3" }

crates/bitwarden-encoding/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ license-file.workspace = true
1515
keywords.workspace = true
1616

1717
[features]
18-
uniffi = ["dep:uniffi"]
18+
uniffi = ["dep:bitwarden-uniffi-error", "dep:uniffi"]
1919
wasm = ["dep:tsify", "dep:wasm-bindgen"]
2020

2121
[dependencies]
22-
bitwarden-uniffi-error = { workspace = true }
22+
bitwarden-uniffi-error = { workspace = true, optional = true }
2323
data-encoding = { workspace = true }
2424
data-encoding-macro = "0.1.18"
2525
serde = { workspace = true }

crates/bitwarden-uniffi-error/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ repository.workspace = true
1414
license-file.workspace = true
1515
keywords.workspace = true
1616

17-
[features]
18-
uniffi = ["dep:uniffi"]
19-
2017
[dependencies]
2118
anyhow = { version = ">=1.0, <2.0" }
22-
uniffi = { workspace = true, optional = true }
2319

2420
[lints]
2521
workspace = true

crates/bitwarden-uniffi-error/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ static ERROR_TO_UNIFFI_ERROR: OnceLock<
99

1010
pub use anyhow::Error;
1111

12-
/// Configure an error converter to convert errors in calls to [`uniffi::custom_type!`] into the
12+
/// Configure an error converter to convert errors in calls to
13+
/// [`uniffi::custom_type!`](https://docs.rs/uniffi/latest/uniffi/macro.custom_type.html) into the
1314
/// main error of the application (`bitwarden_uniffi::error::BitwardenError). This is needed because
1415
/// if the errors don't match, Uniffi will panic instead of returning an error. This needs to be
1516
/// called by the `bitwarden_uniffi` crate before any other Uniffi code is run.
@@ -29,8 +30,8 @@ fn convert_error<E: std::error::Error + Send + Sync + 'static>(error: E) -> anyh
2930
}
3031

3132
/// Convert a `Result` into one that will not cause a panic when called inside
32-
/// [`uniffi::custom_type!`]. It is required that all the results created inside a `custom_type!`
33-
/// are converted using this function.
33+
/// [`uniffi::custom_type!`](https://docs.rs/uniffi/latest/uniffi/macro.custom_type.html). It is
34+
/// required that all the results created inside a `custom_type!` are converted using this function.
3435
pub fn convert_result<T, E: std::error::Error + Send + Sync + 'static>(
3536
result: Result<T, E>,
3637
) -> Result<T, anyhow::Error> {

crates/bitwarden-uniffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bitwarden-send = { workspace = true, features = ["uniffi"] }
3232
bitwarden-ssh = { workspace = true, features = ["uniffi"] }
3333
bitwarden-state = { workspace = true, features = ["uniffi"] }
3434
bitwarden-state-migrations = { workspace = true, features = ["uniffi"] }
35-
bitwarden-uniffi-error = { workspace = true, features = ["uniffi"] }
35+
bitwarden-uniffi-error = { workspace = true }
3636
bitwarden-vault = { workspace = true, features = ["uniffi"] }
3737
chrono = { workspace = true, features = ["std"] }
3838
env_logger = "0.11.1"

0 commit comments

Comments
 (0)