diff --git a/Cargo.lock b/Cargo.lock index 89b9fdb..a8b294f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -529,9 +529,9 @@ dependencies = [ [[package]] name = "idevice" -version = "0.1.50" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "effc7c8fe1bfa5051717c4dc20c3bcc4828b13009a6c95ff6fc8c3f8ccdf4d43" +checksum = "d99be8d1969168237987908274fe41bcb2c8a1f9a37aa12fd15d5713acb9dd2b" dependencies = [ "base64", "plist", @@ -866,7 +866,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -1027,7 +1027,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -1619,7 +1619,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/examples/minimal/src/main.rs b/examples/minimal/src/main.rs index f6db85d..b9dadba 100644 --- a/examples/minimal/src/main.rs +++ b/examples/minimal/src/main.rs @@ -1,3 +1,20 @@ +use std::{env, path::PathBuf}; + +use isideload::auth::apple_account::AppleAccountBuilder; + fn main() { - isideload::test(); + let args: Vec = env::args().collect(); + let app_path = PathBuf::from( + args.get(1) + .expect("Please provide the path to the app to install"), + ); + let apple_id = args + .get(2) + .expect("Please provide the Apple ID to use for installation"); + let apple_password = args.get(3).expect("Please provide the Apple ID password"); + + let account = AppleAccountBuilder::new(apple_id) + .danger_debug(true) + .build() + .unwrap(); } diff --git a/isideload/Cargo.toml b/isideload/Cargo.toml index 0cf797a..2ed76ae 100644 --- a/isideload/Cargo.toml +++ b/isideload/Cargo.toml @@ -15,7 +15,7 @@ default = ["install"] install = ["dep:idevice"] [dependencies] -idevice = { version = "0.1.50", optional = true } +idevice = { version = "0.1.51", optional = true } plist = "1.8.0" plist-macro = "0.1.0" reqwest = { version = "0.13.1", features = ["json", "gzip"] } diff --git a/isideload/src/auth/apple_account.rs b/isideload/src/auth/apple_account.rs index 03a4904..af88953 100644 --- a/isideload/src/auth/apple_account.rs +++ b/isideload/src/auth/apple_account.rs @@ -10,16 +10,63 @@ pub struct AppleAccount { pub anisette: Box, } -impl AppleAccount { - /// Create a new AppleAccount with the given email +#[derive(Debug)] +pub struct AppleAccountBuilder { + email: String, + debug: Option, +} + +impl AppleAccountBuilder { + /// Create a new AppleAccountBuilder with the given email /// /// # Arguments /// - `email`: The Apple ID email address - pub fn new(email: &str) -> Result { + pub fn new(email: &str) -> Self { + Self { + email: email.to_string(), + debug: None, + } + } + + /// DANGER Set whether to enable debug mode + /// + /// # Arguments + /// - `debug`: If true, accept invalid certificates and enable verbose connection logging + pub fn danger_debug(mut self, debug: bool) -> Self { + self.debug = Some(debug); + self + } + + /// Build the AppleAccount + /// + /// # Errors + /// Returns an error if the reqwest client cannot be built + pub fn login(self) -> Result { + let debug = self.debug.unwrap_or(false); + + AppleAccount::login(&self.email, debug) + } +} + +impl AppleAccount { + /// Create a new AppleAccountBuilder with the given email + /// + /// # Arguments + /// - `email`: The Apple ID email address + pub fn builder(email: &str) -> AppleAccountBuilder { + AppleAccountBuilder::new(email) + } + + /// Log in to an Apple account with the given email + /// + /// Reccomended to use the AppleAccountBuilder instead + pub fn login(email: &str, debug: bool) -> Result { + let client = Self::build_client(debug)?; + Ok(AppleAccount { email: email.to_string(), spd: None, - client: Self::build_client(false)?, + client, anisette: Box::new(crate::anisette::DefaultAnisetteProvider {}), }) } @@ -28,6 +75,8 @@ impl AppleAccount { /// /// # Arguments /// - `debug`: DANGER, If true, accept invalid certificates and enable verbose connection logging + /// # Errors + /// Returns an error if the reqwest client cannot be built pub fn build_client(debug: bool) -> Result { let cert = Certificate::from_der(APPLE_ROOT)?; let client = ClientBuilder::new() diff --git a/isideload/src/lib.rs b/isideload/src/lib.rs index 0bf7265..c5b0051 100644 --- a/isideload/src/lib.rs +++ b/isideload/src/lib.rs @@ -10,5 +10,3 @@ pub enum Error { } pub type Result = std::result::Result; - -pub fn test() -> () {}