diff --git a/Cargo.lock b/Cargo.lock index 775bb9b..d9ec68a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,6 +120,15 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "assert_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e2651f366b7ee3f97729fded1441539b49d5f39eeb05b842689e11e84501b2" +dependencies = [ + "const_panic", +] + [[package]] name = "async-backtrace" version = "0.2.7" @@ -531,6 +540,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const_panic" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7782af8f90fe69a4bb41e460abe1727d493403d8b2cc43201a3a3e906b24379f" + [[package]] name = "core-foundation" version = "0.9.4" @@ -1517,6 +1532,7 @@ name = "librqbit-core" version = "4.0.1" dependencies = [ "anyhow", + "assert_cfg", "bytes", "data-encoding", "directories", @@ -1583,6 +1599,7 @@ dependencies = [ name = "librqbit-sha1-wrapper" version = "4.0.0" dependencies = [ + "assert_cfg", "crypto-hash", "ring", ] diff --git a/crates/librqbit/Cargo.toml b/crates/librqbit/Cargo.toml index 840771c..7cc9b25 100644 --- a/crates/librqbit/Cargo.toml +++ b/crates/librqbit/Cargo.toml @@ -17,8 +17,19 @@ http-api = ["axum", "tower-http"] upnp-serve-adapter = ["upnp-serve"] webui = [] timed_existence = [] -default-tls = ["reqwest/default-tls", "sha1w/sha1-crypto-hash"] -rust-tls = ["reqwest/rustls-tls", "sha1w/sha1-ring"] +default-tls = [ + "reqwest/default-tls", + "sha1w/sha1-crypto-hash", + "bencode/sha1-crypto-hash", + "librqbit-core/sha1-crypto-hash", +] +rust-tls = [ + "reqwest/rustls-tls", + "sha1w/sha1-ring", + "sha1w/sha1-ring", + "bencode/sha1-ring", + "librqbit-core/sha1-ring", +] storage_middleware = ["lru"] storage_examples = [] tracing-subscriber-utils = ["tracing-subscriber"] diff --git a/crates/librqbit_core/Cargo.toml b/crates/librqbit_core/Cargo.toml index 552012b..403b0ce 100644 --- a/crates/librqbit_core/Cargo.toml +++ b/crates/librqbit_core/Cargo.toml @@ -31,6 +31,7 @@ directories = "5" tokio-util = "0.7.10" data-encoding = "2.6.0" bytes = "1.7.1" +assert_cfg = "0.1.0" [dev-dependencies] diff --git a/crates/librqbit_core/src/lib.rs b/crates/librqbit_core/src/lib.rs index 63577d6..eb6d654 100644 --- a/crates/librqbit_core/src/lib.rs +++ b/crates/librqbit_core/src/lib.rs @@ -9,3 +9,8 @@ pub mod speed_estimator; pub mod torrent_metainfo; pub use hash_id::Id20; + +assert_cfg::exactly_one! { + feature = "sha1-crypto-hash", + feature = "sha1-ring", +} diff --git a/crates/librqbit_core/src/torrent_metainfo.rs b/crates/librqbit_core/src/torrent_metainfo.rs index b1caf55..ee61bd5 100644 --- a/crates/librqbit_core/src/torrent_metainfo.rs +++ b/crates/librqbit_core/src/torrent_metainfo.rs @@ -29,7 +29,11 @@ pub fn torrent_from_bytes_ext<'de, BufType: Deserialize<'de> + From<&'de [u8]>>( let mut t = TorrentMetaV1::deserialize(&mut de)?; let (digest, info_bytes) = match (de.torrent_info_digest, de.torrent_info_bytes) { (Some(digest), Some(info_bytes)) => (digest, info_bytes), - _ => anyhow::bail!("programming error"), + (o1, o2) => anyhow::bail!( + "programming error: digest.is_some()={}, info_bytes.is_some()={}. Probably one of bencode/sha1* features isn't enabled.", + o1.is_some(), + o2.is_some() + ), }; t.info_hash = Id20::new(digest); Ok(ParsedTorrent { diff --git a/crates/sha1w/Cargo.toml b/crates/sha1w/Cargo.toml index 486c3b9..bd2fd17 100644 --- a/crates/sha1w/Cargo.toml +++ b/crates/sha1w/Cargo.toml @@ -16,5 +16,6 @@ sha1-crypto-hash = ["crypto-hash"] sha1-ring = ["ring"] [dependencies] +assert_cfg = "0.1.0" crypto-hash = { version = "0.3", optional = true } ring = { version = "0.17", optional = true } diff --git a/crates/sha1w/src/lib.rs b/crates/sha1w/src/lib.rs index 1982a07..6a7ec22 100644 --- a/crates/sha1w/src/lib.rs +++ b/crates/sha1w/src/lib.rs @@ -11,6 +11,11 @@ pub trait ISha1 { fn finish(self) -> [u8; 20]; } +assert_cfg::exactly_one! { + feature = "sha1-crypto-hash", + feature = "sha1-ring", +} + #[cfg(feature = "sha1-crypto-hash")] mod crypto_hash_impl { use super::ISha1;