Add error struct

This commit is contained in:
nab138
2026-01-07 11:26:14 -05:00
parent d88c8a19fd
commit d97e4b95d0
5 changed files with 43 additions and 10 deletions

1
Cargo.lock generated
View File

@@ -598,6 +598,7 @@ dependencies = [
"plist", "plist",
"plist-macro", "plist-macro",
"reqwest", "reqwest",
"thiserror 2.0.17",
] ]
[[package]] [[package]]

View File

@@ -19,3 +19,4 @@ idevice = { version = "0.1.50", optional = true }
plist = "1.8.0" plist = "1.8.0"
plist-macro = "0.1.0" plist-macro = "0.1.0"
reqwest = { version = "0.13.1", features = ["json", "gzip"] } reqwest = { version = "0.13.1", features = ["json", "gzip"] }
thiserror = "2.0.17"

View File

@@ -0,0 +1,6 @@
pub trait AnisetteProvider {}
// tmp
pub struct DefaultAnisetteProvider {}
impl AnisetteProvider for DefaultAnisetteProvider {}

View File

@@ -1,3 +1,4 @@
use crate::Result;
use reqwest::{Certificate, ClientBuilder}; use reqwest::{Certificate, ClientBuilder};
const APPLE_ROOT: &[u8] = include_bytes!("./apple_root.der"); const APPLE_ROOT: &[u8] = include_bytes!("./apple_root.der");
@@ -6,22 +7,36 @@ pub struct AppleAccount {
pub email: String, pub email: String,
pub spd: Option<plist::Dictionary>, pub spd: Option<plist::Dictionary>,
pub client: reqwest::Client, pub client: reqwest::Client,
pub anisette: Box<dyn crate::anisette::AnisetteProvider>,
} }
impl AppleAccount { impl AppleAccount {
pub fn new(email: &str) -> reqwest::Result<Self> { /// Create a new AppleAccount with the given email
let client = ClientBuilder::new() ///
.add_root_certificate(Certificate::from_der(APPLE_ROOT)?) /// # Arguments
// uncomment when debugging w/ charles proxy /// - `email`: The Apple ID email address
// .danger_accept_invalid_certs(true) pub fn new(email: &str) -> Result<Self> {
.http1_title_case_headers()
.connection_verbose(true)
.build()?;
Ok(AppleAccount { Ok(AppleAccount {
email: email.to_string(), email: email.to_string(),
spd: None, spd: None,
client, client: Self::build_client(false)?,
anisette: Box::new(crate::anisette::DefaultAnisetteProvider {}),
}) })
} }
/// Build a reqwest client with the Apple root certificate
///
/// # Arguments
/// - `debug`: DANGER, If true, accept invalid certificates and enable verbose connection logging
pub fn build_client(debug: bool) -> Result<reqwest::Client> {
let cert = Certificate::from_der(APPLE_ROOT)?;
let client = ClientBuilder::new()
.add_root_certificate(cert)
.http1_title_case_headers()
.danger_accept_invalid_certs(debug)
.connection_verbose(debug)
.build()?;
Ok(client)
}
} }

View File

@@ -1,4 +1,14 @@
use thiserror::Error as ThisError;
pub mod anisette; pub mod anisette;
pub mod auth; pub mod auth;
#[derive(Debug, ThisError)]
pub enum Error {
#[error("Reqwest error: {0}")]
Reqwest(#[from] reqwest::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
pub fn test() -> () {} pub fn test() -> () {}