diff --git a/tvix/castore/src/digests.rs b/tvix/castore/src/digests.rs index 4df11b389..a9e810aac 100644 --- a/tvix/castore/src/digests.rs +++ b/tvix/castore/src/digests.rs @@ -12,6 +12,8 @@ pub enum Error { InvalidDigestLen(usize), } +pub const B3_LEN: usize = 32; + impl B3Digest { // returns a copy of the inner [Vec]. pub fn to_vec(&self) -> Vec { @@ -31,7 +33,7 @@ impl TryFrom> for B3Digest { // constructs a [B3Digest] from a [Vec]. // Returns an error if the digest has the wrong length. fn try_from(value: Vec) -> Result { - if value.len() != 32 { + if value.len() != B3_LEN { Err(Error::InvalidDigestLen(value.len())) } else { Ok(Self(value.into())) @@ -45,7 +47,7 @@ impl TryFrom for B3Digest { // constructs a [B3Digest] from a [bytes::Bytes]. // Returns an error if the digest has the wrong length. fn try_from(value: bytes::Bytes) -> Result { - if value.len() != 32 { + if value.len() != B3_LEN { Err(Error::InvalidDigestLen(value.len())) } else { Ok(Self(value)) @@ -53,8 +55,8 @@ impl TryFrom for B3Digest { } } -impl From<&[u8; 32]> for B3Digest { - fn from(value: &[u8; 32]) -> Self { +impl From<&[u8; B3_LEN]> for B3Digest { + fn from(value: &[u8; B3_LEN]) -> Self { Self(value.to_vec().into()) } } diff --git a/tvix/castore/src/lib.rs b/tvix/castore/src/lib.rs index 76490fb7e..d51022428 100644 --- a/tvix/castore/src/lib.rs +++ b/tvix/castore/src/lib.rs @@ -8,7 +8,7 @@ pub mod import; pub mod proto; pub mod utils; -pub use digests::B3Digest; +pub use digests::{B3Digest, B3_LEN}; pub use errors::Error; #[cfg(test)]