From 5ee385c95c958175cc2bf4db862cd8ea26f89bf4 Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Tue, 12 Aug 2025 08:19:31 -0600 Subject: [PATCH] Fix cargo clippy warnings --- ffi/src/core_device/app_service.rs | 8 ++++---- ffi/src/process_control.rs | 8 ++++---- idevice/src/lib.rs | 4 ++-- idevice/src/services/afc/mod.rs | 8 ++++---- .../src/services/core_device/app_service.rs | 4 ++-- idevice/src/services/core_device/mod.rs | 4 ++-- idevice/src/services/dvt/remote_server.rs | 12 ++++++------ idevice/src/services/installation_proxy.rs | 18 +++++++++--------- idevice/src/services/mobile_image_mounter.rs | 7 +++---- idevice/src/tss.rs | 18 +++++++++--------- idevice/src/xpc/http2/mod.rs | 2 +- idevice/src/xpc/mod.rs | 15 +++++++-------- tools/Cargo.toml | 2 +- tools/src/common.rs | 8 +++++--- 14 files changed, 59 insertions(+), 59 deletions(-) diff --git a/ffi/src/core_device/app_service.rs b/ffi/src/core_device/app_service.rs index 5aac7a4..908bd26 100644 --- a/ffi/src/core_device/app_service.rs +++ b/ffi/src/core_device/app_service.rs @@ -329,10 +329,10 @@ pub unsafe extern "C" fn app_service_launch_app( if !argv.is_null() && argc > 0 { let argv_slice = unsafe { std::slice::from_raw_parts(argv, argc) }; for &arg in argv_slice { - if !arg.is_null() { - if let Ok(arg_str) = unsafe { CStr::from_ptr(arg) }.to_str() { - args.push(arg_str); - } + if !arg.is_null() + && let Ok(arg_str) = unsafe { CStr::from_ptr(arg) }.to_str() + { + args.push(arg_str); } } } diff --git a/ffi/src/process_control.rs b/ffi/src/process_control.rs index 2ed84b9..b771125 100644 --- a/ffi/src/process_control.rs +++ b/ffi/src/process_control.rs @@ -105,10 +105,10 @@ pub unsafe extern "C" fn process_control_launch_app( for &env_var in env_vars_slice { if !env_var.is_null() { let env_var = unsafe { CStr::from_ptr(env_var) }; - if let Ok(env_var) = env_var.to_str() { - if let Some((key, value)) = env_var.split_once('=') { - env_dict.insert(key.to_string(), Value::String(value.to_string())); - } + if let Ok(env_var) = env_var.to_str() + && let Some((key, value)) = env_var.split_once('=') + { + env_dict.insert(key.to_string(), Value::String(value.to_string())); } } } diff --git a/idevice/src/lib.rs b/idevice/src/lib.rs index b9fca66..3313de8 100644 --- a/idevice/src/lib.rs +++ b/idevice/src/lib.rs @@ -25,7 +25,7 @@ pub use services::*; #[cfg(feature = "xpc")] pub use xpc::RemoteXpcClient; -use log::{debug, error, trace, warn}; +use log::{debug, error, trace}; use provider::{IdeviceProvider, RsdProvider}; use rustls::{crypto::CryptoProvider, pki_types::ServerName}; use std::{ @@ -443,7 +443,7 @@ impl Idevice { // My sanity while debugging the workspace crates are more important. debug!("Using ring crypto backend, because both were passed"); - warn!("Both ring && aws-lc are selected as idevice crypto backends!"); + log::warn!("Both ring && aws-lc are selected as idevice crypto backends!"); rustls::crypto::ring::default_provider() } }; diff --git a/idevice/src/services/afc/mod.rs b/idevice/src/services/afc/mod.rs index 634e379..c6319be 100644 --- a/idevice/src/services/afc/mod.rs +++ b/idevice/src/services/afc/mod.rs @@ -11,7 +11,7 @@ use log::warn; use opcode::{AfcFopenMode, AfcOpcode}; use packet::{AfcPacket, AfcPacketHeader}; -use crate::{obf, Idevice, IdeviceError, IdeviceService}; +use crate::{Idevice, IdeviceError, IdeviceService, obf}; pub mod errors; pub mod file; @@ -376,11 +376,11 @@ impl AfcClient { /// /// # Returns /// A `FileDescriptor` struct for the opened file - pub async fn open( - &mut self, + pub async fn open<'f>( + &'f mut self, path: impl Into, mode: AfcFopenMode, - ) -> Result { + ) -> Result, IdeviceError> { let path = path.into(); let mut header_payload = (mode as u64).to_le_bytes().to_vec(); header_payload.extend(path.as_bytes()); diff --git a/idevice/src/services/core_device/app_service.rs b/idevice/src/services/core_device/app_service.rs index fc74960..d4a2952 100644 --- a/idevice/src/services/core_device/app_service.rs +++ b/idevice/src/services/core_device/app_service.rs @@ -3,7 +3,7 @@ use log::warn; use serde::Deserialize; -use crate::{obf, IdeviceError, ReadWrite, RsdService}; +use crate::{IdeviceError, ReadWrite, RsdService, obf}; use super::CoreDeviceServiceClient; @@ -128,7 +128,7 @@ pub struct IconUuid { pub classes: Vec, } -impl<'a, R: ReadWrite + 'a> AppServiceClient { +impl AppServiceClient { pub async fn new(stream: R) -> Result { Ok(Self { inner: CoreDeviceServiceClient::new(stream).await?, diff --git a/idevice/src/services/core_device/mod.rs b/idevice/src/services/core_device/mod.rs index e11fd76..6114a0e 100644 --- a/idevice/src/services/core_device/mod.rs +++ b/idevice/src/services/core_device/mod.rs @@ -4,8 +4,8 @@ use log::warn; use crate::{ - xpc::{self, XPCObject}, IdeviceError, ReadWrite, RemoteXpcClient, + xpc::{self, XPCObject}, }; mod app_service; @@ -17,7 +17,7 @@ pub struct CoreDeviceServiceClient { inner: RemoteXpcClient, } -impl<'a, R: ReadWrite + 'a> CoreDeviceServiceClient { +impl CoreDeviceServiceClient { pub async fn new(inner: R) -> Result { let mut client = RemoteXpcClient::new(inner).await?; client.do_handshake().await?; diff --git a/idevice/src/services/dvt/remote_server.rs b/idevice/src/services/dvt/remote_server.rs index 91e9684..c4111a8 100644 --- a/idevice/src/services/dvt/remote_server.rs +++ b/idevice/src/services/dvt/remote_server.rs @@ -55,8 +55,8 @@ use log::{debug, warn}; use tokio::io::AsyncWriteExt; use crate::{ - dvt::message::{Aux, AuxValue, Message, MessageHeader, PayloadHeader}, IdeviceError, ReadWrite, + dvt::message::{Aux, AuxValue, Message, MessageHeader, PayloadHeader}, }; /// Message type identifier for instruments protocol @@ -112,7 +112,7 @@ impl RemoteServerClient { } /// Returns a handle to the root channel (channel 0) - pub fn root_channel(&mut self) -> Channel { + pub fn root_channel<'c>(&'c mut self) -> Channel<'c, R> { Channel { client: self, channel: 0, @@ -131,10 +131,10 @@ impl RemoteServerClient { /// # Errors /// * `IdeviceError::UnexpectedResponse` if server responds with unexpected data /// * Other IO or serialization errors - pub async fn make_channel( - &mut self, + pub async fn make_channel<'c>( + &'c mut self, identifier: impl Into, - ) -> Result, IdeviceError> { + ) -> Result, IdeviceError> { let code = self.new_channel; self.new_channel += 1; @@ -164,7 +164,7 @@ impl RemoteServerClient { self.build_channel(code) } - fn build_channel(&mut self, code: u32) -> Result, IdeviceError> { + fn build_channel<'c>(&'c mut self, code: u32) -> Result, IdeviceError> { Ok(Channel { client: self, channel: code, diff --git a/idevice/src/services/installation_proxy.rs b/idevice/src/services/installation_proxy.rs index b7111f2..9cf28fb 100644 --- a/idevice/src/services/installation_proxy.rs +++ b/idevice/src/services/installation_proxy.rs @@ -8,7 +8,7 @@ use std::collections::HashMap; use log::warn; use plist::Dictionary; -use crate::{obf, Idevice, IdeviceError, IdeviceService}; +use crate::{Idevice, IdeviceError, IdeviceService, obf}; /// Client for interacting with the iOS installation proxy service /// @@ -376,10 +376,10 @@ impl InstallationProxyClient { break; } - if let Some(status) = res.get("Status").and_then(|x| x.as_string()) { - if status == "Complete" { - break; - } + if let Some(status) = res.get("Status").and_then(|x| x.as_string()) + && status == "Complete" + { + break; } } Ok(values) @@ -424,10 +424,10 @@ impl InstallationProxyClient { callback((c, state.clone())).await; } - if let Some(c) = res.remove("Status").and_then(|x| x.into_string()) { - if c == "Complete" { - break; - } + if let Some(c) = res.remove("Status").and_then(|x| x.into_string()) + && c == "Complete" + { + break; } } Ok(()) diff --git a/idevice/src/services/mobile_image_mounter.rs b/idevice/src/services/mobile_image_mounter.rs index 8ec22d3..d0735bd 100644 --- a/idevice/src/services/mobile_image_mounter.rs +++ b/idevice/src/services/mobile_image_mounter.rs @@ -9,7 +9,7 @@ use log::debug; -use crate::{obf, Idevice, IdeviceError, IdeviceService}; +use crate::{Idevice, IdeviceError, IdeviceService, obf}; use sha2::{Digest, Sha384}; #[cfg(feature = "tss")] @@ -710,10 +710,9 @@ impl ImageMounter { .and_then(|l| l.as_dictionary()) .and_then(|l| l.get("Info")) .and_then(|i| i.as_dictionary()) + && let Some(plist::Value::Array(rules)) = info.get("RestoreRequestRules") { - if let Some(plist::Value::Array(rules)) = info.get("RestoreRequestRules") { - crate::tss::apply_restore_request_rules(&mut tss_entry, ¶meters, rules); - } + crate::tss::apply_restore_request_rules(&mut tss_entry, ¶meters, rules); } if manifest_item.get("Digest").is_none() { diff --git a/idevice/src/tss.rs b/idevice/src/tss.rs index d240ecc..df7491c 100644 --- a/idevice/src/tss.rs +++ b/idevice/src/tss.rs @@ -8,7 +8,7 @@ use log::{debug, warn}; use plist::Value; -use crate::{util::plist_to_xml_bytes, IdeviceError}; +use crate::{IdeviceError, util::plist_to_xml_bytes}; /// TSS client version string sent in requests const TSS_CLIENT_VERSION_STRING: &str = "libauthinstall-1033.0.2"; @@ -172,15 +172,15 @@ pub fn apply_restore_request_rules( for (key, value) in actions { // Skip special values (255 typically means "ignore") - if let Some(i) = value.as_unsigned_integer() { - if i == 255 { - continue; - } + if let Some(i) = value.as_unsigned_integer() + && i == 255 + { + continue; } - if let Some(i) = value.as_signed_integer() { - if i == 255 { - continue; - } + if let Some(i) = value.as_signed_integer() + && i == 255 + { + continue; } input.remove(key); // Explicitly remove before inserting diff --git a/idevice/src/xpc/http2/mod.rs b/idevice/src/xpc/http2/mod.rs index 5679c66..b6ff0b1 100644 --- a/idevice/src/xpc/http2/mod.rs +++ b/idevice/src/xpc/http2/mod.rs @@ -17,7 +17,7 @@ pub struct Http2Client { cache: HashMap>>, } -impl<'a, R: ReadWrite + 'a> Http2Client { +impl Http2Client { /// Writes the magic and inits the caches pub async fn new(mut inner: R) -> Result { inner.write_all(HTTP2_MAGIC).await?; diff --git a/idevice/src/xpc/mod.rs b/idevice/src/xpc/mod.rs index aac5308..c6fc217 100644 --- a/idevice/src/xpc/mod.rs +++ b/idevice/src/xpc/mod.rs @@ -17,15 +17,14 @@ const REPLY_CHANNEL: u32 = 3; pub struct RemoteXpcClient { h2_client: http2::Http2Client, root_id: u64, - reply_id: u64, + // reply_id: u64 // maybe not used? } -impl<'a, R: ReadWrite + 'a> RemoteXpcClient { +impl RemoteXpcClient { pub async fn new(socket: R) -> Result { Ok(Self { h2_client: http2::Http2Client::new(socket).await?, root_id: 1, - reply_id: 1, }) } @@ -86,11 +85,11 @@ impl<'a, R: ReadWrite + 'a> RemoteXpcClient { match msg.message { Some(msg) => { - if let Some(d) = msg.as_dictionary() { - if d.is_empty() { - msg_buffer.clear(); - continue; - } + if let Some(d) = msg.as_dictionary() + && d.is_empty() + { + msg_buffer.clear(); + continue; } break Ok(msg.to_plist()); } diff --git a/tools/Cargo.toml b/tools/Cargo.toml index a2dc6ac..17d5510 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -3,7 +3,7 @@ name = "idevice-tools" description = "Rust binary tools to interact with services on iOS devices." authors = ["Jackson Coxson"] version = "0.1.0" -edition = "2021" +edition = "2024" license = "MIT" documentation = "https://docs.rs/idevice" repository = "https://github.com/jkcoxson/idevice" diff --git a/tools/src/common.rs b/tools/src/common.rs index 8e54744..34be9e5 100644 --- a/tools/src/common.rs +++ b/tools/src/common.rs @@ -38,14 +38,16 @@ pub async fn get_provider( } }; Box::new(dev.to_provider(UsbmuxdAddr::from_env_var().unwrap(), label)) - } else if host.is_some() && pairing_file.is_some() { - let host = match IpAddr::from_str(host.unwrap()) { + } else if let Some(host) = host + && let Some(pairing_file) = pairing_file + { + let host = match IpAddr::from_str(host) { Ok(h) => h, Err(e) => { return Err(format!("Invalid host: {e:?}")); } }; - let pairing_file = match PairingFile::read_from_file(pairing_file.unwrap()) { + let pairing_file = match PairingFile::read_from_file(pairing_file) { Ok(p) => p, Err(e) => { return Err(format!("Unable to read pairing file: {e:?}"));