From 9649e07f76cde5dd0adbe8c4335fd54d35fbcaf6 Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Mon, 13 Jan 2025 19:17:38 +0100 Subject: [PATCH 1/2] Fix new `clippy` warnings --- talpid-core/src/split_tunnel/macos/process.rs | 2 +- talpid-dbus/src/systemd_resolved.rs | 3 +-- talpid-types/src/net/proxy.rs | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/talpid-core/src/split_tunnel/macos/process.rs b/talpid-core/src/split_tunnel/macos/process.rs index 05f83b249731..7b3d644cd526 100644 --- a/talpid-core/src/split_tunnel/macos/process.rs +++ b/talpid-core/src/split_tunnel/macos/process.rs @@ -567,7 +567,7 @@ mod test { msg.contains('\n'), "Message does not contain a newline!! Make sure to add a newline to '{msg}'" ); - let (stdout_read, mut stdout_write) = simplex(msg.as_bytes().len()); + let (stdout_read, mut stdout_write) = simplex(msg.len()); // "print" to "stdout" after `duration`. tokio::spawn(async move { tokio::time::sleep(lag).await; diff --git a/talpid-dbus/src/systemd_resolved.rs b/talpid-dbus/src/systemd_resolved.rs index b678d5bf20a6..7dad235ac7f3 100644 --- a/talpid-dbus/src/systemd_resolved.rs +++ b/talpid-dbus/src/systemd_resolved.rs @@ -208,8 +208,7 @@ impl SystemdResolved { let parts = contents.trim().split(' '); parts .map(str::parse::) - .map(|maybe_ip| maybe_ip.map(|addr| addr.is_loopback()).unwrap_or(false)) - .any(|is_loopback| is_loopback) + .any(|maybe_ip| maybe_ip.map(|addr| addr.is_loopback()).unwrap_or(false)) }) .unwrap_or(false); diff --git a/talpid-types/src/net/proxy.rs b/talpid-types/src/net/proxy.rs index d60b2df436f6..c73db5a3553b 100644 --- a/talpid-types/src/net/proxy.rs +++ b/talpid-types/src/net/proxy.rs @@ -159,12 +159,12 @@ impl SocksAuth { /// assert!(too_long_username.is_err()); /// ``` pub fn new(username: String, password: String) -> Result { - if !(1..=255).contains(&password.as_bytes().len()) { + if !(1..=255).contains(&password.len()) { return Err(Error::InvalidSocksAuthValues( "Password length should between 1 and 255 bytes", )); } - if !(1..=255).contains(&username.as_bytes().len()) { + if !(1..=255).contains(&username.len()) { return Err(Error::InvalidSocksAuthValues( "Username length should between 1 and 255 bytes", )); From 406405f4523264f0ba0bebb29acecc4a57265f7c Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Mon, 13 Jan 2025 19:52:15 +0100 Subject: [PATCH 2/2] Replace `objc` with `objc2` to fix `clippy` warnings --- Cargo.lock | 33 +++-------------------- mullvad-daemon/Cargo.toml | 2 +- mullvad-daemon/src/macos_launch_daemon.rs | 28 +++++++++++-------- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66b17974d13b..13e2e0d7e681 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2273,15 +2273,6 @@ version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9106e1d747ffd48e6be5bb2d97fa706ed25b144fbee4d5c02eae110cd8d6badd" -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] - [[package]] name = "match_cfg" version = "0.1.0" @@ -2544,7 +2535,7 @@ dependencies = [ "mullvad-types", "mullvad-version", "nix 0.23.2", - "objc", + "objc2", "regex", "serde", "serde_json", @@ -2986,21 +2977,14 @@ dependencies = [ "libm", ] -[[package]] -name = "objc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -dependencies = [ - "malloc_buf", - "objc_exception", -] - [[package]] name = "objc-sys" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" +dependencies = [ + "cc", +] [[package]] name = "objc2" @@ -3095,15 +3079,6 @@ dependencies = [ "objc2-metal", ] -[[package]] -name = "objc_exception" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" -dependencies = [ - "cc", -] - [[package]] name = "object" version = "0.32.2" diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index d8b1a2b1c605..4c9fce37ec99 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -62,7 +62,7 @@ simple-signal = "1.1" talpid-dbus = { path = "../talpid-dbus" } [target.'cfg(target_os="macos")'.dependencies] -objc = { version = "0.2.7", features = ["exception", "verify_message"] } +objc2 = { version = "0.5.2", features = ["exception"] } [target.'cfg(windows)'.dependencies] ctrlc = "3.0" diff --git a/mullvad-daemon/src/macos_launch_daemon.rs b/mullvad-daemon/src/macos_launch_daemon.rs index 945e61828bb7..0c9c89080cb7 100644 --- a/mullvad-daemon/src/macos_launch_daemon.rs +++ b/mullvad-daemon/src/macos_launch_daemon.rs @@ -5,10 +5,11 @@ //! must be checked so that the user can be directed to approve the launch //! daemon in the system settings. -use objc::{class, msg_send, sel, sel_impl}; +use libc::c_longlong; +use objc2::{class, msg_send, runtime::AnyObject, Encode, Encoding, RefEncode}; use std::ffi::CStr; -type Id = *mut objc::runtime::Object; +type Id = *mut AnyObject; // Framework that contains `SMAppService`. #[link(name = "ServiceManagement", kind = "framework")] @@ -18,18 +19,23 @@ extern "C" {} #[repr(C)] #[derive(Debug)] struct NSOperatingSystemVersion { - major_version: libc::c_longlong, - minor_version: libc::c_longlong, - patch_version: libc::c_longlong, + major_version: c_longlong, + minor_version: c_longlong, + patch_version: c_longlong, } -/// Implement Objective-C type encoding for the struct. Allows the `objc` crate +/// Implement Objective-C type encoding for the struct. Allows the `objc2` crate /// to perform function signature matching before performing calls into the Objective-C -/// runtime. This is needed to be able to enable the `verify_message` feature on `objc`. -unsafe impl objc::Encode for NSOperatingSystemVersion { - fn encode() -> objc::Encoding { - unsafe { objc::Encoding::from_str("{?=qqq}") } - } +/// runtime. +unsafe impl Encode for NSOperatingSystemVersion { + const ENCODING: Encoding = Encoding::Struct( + "NSOperatingSystemVersion", + &[Encoding::LongLong, Encoding::LongLong, Encoding::LongLong], + ); +} + +unsafe impl RefEncode for NSOperatingSystemVersion { + const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING); } /// Authorization status of the Mullvad daemon.