Conditionally compile crypto backend

This commit is contained in:
Jackson Coxson
2025-07-31 11:52:42 -06:00
parent 8549a82b55
commit 1515b1bab4
3 changed files with 39 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ edition = "2024"
[dependencies]
idevice = { path = "../idevice" }
idevice = { path = "../idevice", default-features = false }
log = "0.4.26"
simplelog = "0.12.2"
once_cell = "1.21.1"
@@ -15,6 +15,10 @@ plist = "1.7.1"
plist_ffi = "0.1.3"
[features]
aws-lc = ["idevice/aws-lc"]
ring = ["idevice/ring"]
afc = ["idevice/afc"]
amfi = ["idevice/amfi"]
core_device = ["idevice/core_device"]
@@ -64,7 +68,7 @@ full = [
"springboardservices",
"syslog_relay",
]
default = ["full"]
default = ["full", "aws-lc"]
[build-dependencies]
cbindgen = "0.29.0"

View File

@@ -390,15 +390,34 @@ impl Idevice {
pairing_file: &pairing_file::PairingFile,
) -> Result<(), IdeviceError> {
if CryptoProvider::get_default().is_none() {
let crypto_provider = if cfg!(feature = "ring") {
let crypto_provider = {
#[cfg(all(feature = "ring", not(feature = "aws-lc")))]
{
debug!("Using ring crypto backend");
rustls::crypto::ring::default_provider()
} else if cfg!(feature = "aws-lc") {
}
#[cfg(all(feature = "aws-lc", not(feature = "ring")))]
{
debug!("Using aws-lc crypto backend");
rustls::crypto::aws_lc_rs::default_provider()
} else {
panic!("No crypto provider compiled in! Use one of the features for idevice to specify a provider");
}
#[cfg(not(any(feature = "ring", feature = "aws-lc")))]
{
panic!(
"No crypto backend was selected! Specify an idevice feature for a crypto backend"
);
}
#[cfg(all(feature = "ring", feature = "aws-lc"))]
{
compile_error!(
"Cannot enable both `ring` and `aws-lc` features at the same time"
);
}
};
if let Err(e) = CryptoProvider::install_default(crypto_provider) {
// For whatever reason, getting the default provider will return None on iOS at
// random. Installing the default provider a second time will return an error, so

View File

@@ -94,7 +94,7 @@ name = "restore_service"
path = "src/restore_service.rs"
[dependencies]
idevice = { path = "../idevice", features = ["full"] }
idevice = { path = "../idevice", features = ["full"], default-features = false }
tokio = { version = "1.43", features = ["full"] }
log = { version = "0.4" }
env_logger = { version = "0.11" }
@@ -105,3 +105,8 @@ clap = { version = "4.5" }
plist = { version = "1.7" }
ns-keyed-archive = "0.1.2"
uuid = "1.16"
[features]
default = ["aws-lc"]
aws-lc = ["idevice/aws-lc"]
ring = ["idevice/ring"]