Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Avoid comparison with `SHA1_ZERO`
Lorenz Leutgeb committed 10 days ago
commit 93003ece6492f09d01d8526a748484eead4396be
parent 422ff5e33bb9ab814940a479f6640b176f274b3e
2 files changed +6 -1
modified crates/radicle-oid/src/lib.rs
@@ -87,6 +87,11 @@ pub enum Oid {
// for forwards compatibility: What if another hash with digests of the same
// length becomes popular?
impl Oid {
+
    /// A SHA-1 object identifier with all digest bytes set to zero.
+
    /// This is sometimes used as a sentinel value to indicate the absence of
+
    /// an object.
+
    /// To compare whether an object identifier is zero, prefer the method
+
    /// [`Oid::is_zero`] over checking equality with this constant.
    pub const SHA1_ZERO: Self = Self::Sha1([0u8; SHA1_DIGEST_LEN]);

    pub fn from_sha1(digest: [u8; SHA1_DIGEST_LEN]) -> Self {
modified crates/radicle/src/storage/refs.rs
@@ -177,7 +177,7 @@ impl Refs {
        let mut buf = String::new();

        for (name, oid) in self.0.iter() {
-
            debug_assert_ne!(oid, &Oid::SHA1_ZERO);
+
            debug_assert!(!oid.is_zero());
            debug_assert_ne!(name, &SIGREFS_BRANCH.to_ref_string());

            buf.push_str(&oid.to_string());