From 4036740ca78e82ed0b9c3923b585fe383216f5a8 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 30 Dec 2022 15:14:41 +0100 Subject: feat(tvix/store): parameterise validate_digest error 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 --- tvix/store/src/proto.rs | 11 +++++++---- 1 file 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(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) -> Result<(), ValidateDirectoryError> { +fn validate_digest(digest: &Vec, 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())?; -- cgit 1.4.1