about summary refs log tree commit diff
path: root/tvix/castore/src/digests.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-05T07·57+0300
committerflokli <flokli@flokli.de>2023-10-05T09·50+0000
commitc67ab911ebdefddda5b05981834c783c0e7a3d7a (patch)
tree15b9bc04e8dca3d02707142eedaae111a4d31917 /tvix/castore/src/digests.rs
parent8239f32b62c4363377f0c513dbcd76dd1e50d01e (diff)
refactor(tvix/castore): move magic number to B3_LEN const r/6704
… and export it.

Change-Id: I47d2dc2f5a8174da65c614b43801d648506e2d73
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9544
Tested-by: BuildkiteCI
Reviewed-by: edef <edef@edef.eu>
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/castore/src/digests.rs')
-rw-r--r--tvix/castore/src/digests.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/tvix/castore/src/digests.rs b/tvix/castore/src/digests.rs
index 4df11b389e93..a9e810aac5dd 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<u8>].
     pub fn to_vec(&self) -> Vec<u8> {
@@ -31,7 +33,7 @@ impl TryFrom<Vec<u8>> for B3Digest {
     // constructs a [B3Digest] from a [Vec<u8>].
     // Returns an error if the digest has the wrong length.
     fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
-        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<bytes::Bytes> 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<Self, Self::Error> {
-        if value.len() != 32 {
+        if value.len() != B3_LEN {
             Err(Error::InvalidDigestLen(value.len()))
         } else {
             Ok(Self(value))
@@ -53,8 +55,8 @@ impl TryFrom<bytes::Bytes> 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())
     }
 }