mirror of
https://github.com/nab138/isideload.git
synced 2026-03-02 14:36:16 +01:00
Add error struct
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -598,6 +598,7 @@ dependencies = [
|
|||||||
"plist",
|
"plist",
|
||||||
"plist-macro",
|
"plist-macro",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"thiserror 2.0.17",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
pub trait AnisetteProvider {}
|
||||||
|
|
||||||
|
// tmp
|
||||||
|
pub struct DefaultAnisetteProvider {}
|
||||||
|
|
||||||
|
impl AnisetteProvider for DefaultAnisetteProvider {}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() -> () {}
|
||||||
|
|||||||
Reference in New Issue
Block a user