From 235821407ae7590a1c03f3cac596f85fa61b030a Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Sun, 12 Oct 2025 11:49:17 +0200 Subject: [PATCH 1/2] hash: Add feature flag `sha1` Instead of providing a non-additive feature `no_sha1` in the future, if ever dependents want to build, say, a SHA-256 version only, anticipate this today by requiring the feature `sha1`. For now, since this crate is useless without support for SHA-1, omitting the feature `sha1` results in a compile error. But in the future, this error could be removed. Dependents that have `default-features = false` will see breakage, and they will have to adjust to default-features = false features = ["sha1"] to recover. --- gix-hash/Cargo.toml | 3 +++ gix-hash/src/lib.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/gix-hash/Cargo.toml b/gix-hash/Cargo.toml index c56eccaed2a..d7ff1054e30 100644 --- a/gix-hash/Cargo.toml +++ b/gix-hash/Cargo.toml @@ -16,6 +16,9 @@ doctest = false test = false [features] +default = ["sha1"] +## Support for SHA-1 digests. +sha1 = [] ## Data structures implement `serde::Serialize` and `serde::Deserialize`. serde = ["dep:serde", "faster-hex/serde"] diff --git a/gix-hash/src/lib.rs b/gix-hash/src/lib.rs index 785fbe28c1a..af9d343c986 100644 --- a/gix-hash/src/lib.rs +++ b/gix-hash/src/lib.rs @@ -9,6 +9,11 @@ #![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))] #![deny(missing_docs, rust_2018_idioms, unsafe_code)] +// Remove this once other hashes (e.g., SHA-256, and potentially others) +// are supported, and this crate can build without [`ObjectId::Sha1`]. +#[cfg(not(feature = "sha1"))] +compile_error!("The feature `sha1` feature is required."); + #[path = "oid.rs"] mod borrowed; pub use borrowed::{oid, Error}; From 492b9cd99df825f18e983325237c9cb9b6412991 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Sun, 12 Oct 2025 11:52:55 +0200 Subject: [PATCH 2/2] hash: Mark `enum ObjectId` as non-exhaustive This will allow adding other variants, such as for SHA-256, without breaking dependents. --- gix-hash/src/object_id.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/gix-hash/src/object_id.rs b/gix-hash/src/object_id.rs index 2e320039b1e..a2deb178294 100644 --- a/gix-hash/src/object_id.rs +++ b/gix-hash/src/object_id.rs @@ -9,6 +9,7 @@ use crate::{borrowed::oid, Kind, SIZE_OF_SHA1_DIGEST}; /// An owned hash identifying objects, most commonly `Sha1` #[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Copy)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[non_exhaustive] pub enum ObjectId { /// A SHA 1 hash digest Sha1([u8; SIZE_OF_SHA1_DIGEST]),