about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2022-12-30T14·14+0100
committerflokli <flokli@flokli.de>2022-12-30T14·43+0000
commit4036740ca78e82ed0b9c3923b585fe383216f5a8 (patch)
treef5a023d8b0614e1ae0713ec8be359c4b123bbf83 /tvix
parent5520bf3682040fc0eabba9cd55d6c403f35c8775 (diff)
feat(tvix/store): parameterise validate_digest error r/5552
Similar to cl/7682, we also want to make that error configurable.

Change-Id: I64f1a4570b3d75af4741abe10c2855959766e107
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7708
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/store/src/proto.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/tvix/store/src/proto.rs b/tvix/store/src/proto.rs
index 8a5a10c21233..eac37820658e 100644
--- a/tvix/store/src/proto.rs
+++ b/tvix/store/src/proto.rs
@@ -38,9 +38,9 @@ fn validate_node_name<E>(name: &str, err: fn(String) -> E) -> Result<(), E> {
 
 /// Checks a digest for validity.
 /// Digests are 32 bytes long, as we store blake3 digests.
-fn validate_digest(digest: &Vec<u8>) -> Result<(), ValidateDirectoryError> {
+fn validate_digest<E>(digest: &Vec<u8>, err: fn(usize) -> E) -> Result<(), E> {
     if digest.len() != 32 {
-        return Err(ValidateDirectoryError::InvalidDigestLen(digest.len()));
+        return Err(err(digest.len()));
     }
     Ok(())
 }
@@ -105,7 +105,10 @@ impl Directory {
         // check directories
         for directory_node in &self.directories {
             validate_node_name(&directory_node.name, ValidateDirectoryError::InvalidName)?;
-            validate_digest(&directory_node.digest)?;
+            validate_digest(
+                &directory_node.digest,
+                ValidateDirectoryError::InvalidDigestLen,
+            )?;
 
             update_if_lt_prev(&mut last_directory_name, directory_node.name.as_str())?;
             insert_once(&mut seen_names, directory_node.name.as_str())?;
@@ -114,7 +117,7 @@ impl Directory {
         // check files
         for file_node in &self.files {
             validate_node_name(&file_node.name, ValidateDirectoryError::InvalidName)?;
-            validate_digest(&file_node.digest)?;
+            validate_digest(&file_node.digest, ValidateDirectoryError::InvalidDigestLen)?;
 
             update_if_lt_prev(&mut last_file_name, file_node.name.as_str())?;
             insert_once(&mut seen_names, file_node.name.as_str())?;