about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-08-19T19·32+0200
committerflokli <flokli@flokli.de>2023-08-20T22·40+0000
commitbba7bbf820d64d4d46e75dd590d0cf04e648ac41 (patch)
tree3d9069fafd53cf65cff6851e49942bd0286a4c2e /tvix
parent0193f07642db752c3e14e02064c02b0fd1cc060b (diff)
docs(tvix/nix-compat/nixhash): update comments r/6513
Change-Id: I46660da84065fd6938f581e14d67e231dca3c3ea
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9112
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/nix-compat/src/nixhash/mod.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/tvix/nix-compat/src/nixhash/mod.rs b/tvix/nix-compat/src/nixhash/mod.rs
index 2bd24d4ed3db..1a8c0534b08a 100644
--- a/tvix/nix-compat/src/nixhash/mod.rs
+++ b/tvix/nix-compat/src/nixhash/mod.rs
@@ -89,7 +89,7 @@ pub fn from_str(s: &str, algo_str: Option<&str>) -> Result<NixHash, Error> {
         None => None,
     };
 
-    // peek at the beginning of the string. Let's detect the SRI path first.
+    // Peek at the beginning of the string to detect SRI hashes.
     if s.starts_with("sha1-")
         || s.starts_with("sha256-")
         || s.starts_with("sha512-")
@@ -108,7 +108,7 @@ pub fn from_str(s: &str, algo_str: Option<&str>) -> Result<NixHash, Error> {
         return Ok(parsed_nixhash);
     }
 
-    // Now, peek at the beginning again to see if it's a Nix Hash
+    // Peek at the beginning again to see if it's a Nix Hash
     if s.starts_with("sha1:")
         || s.starts_with("sha256:")
         || s.starts_with("sha512:")
@@ -127,7 +127,7 @@ pub fn from_str(s: &str, algo_str: Option<&str>) -> Result<NixHash, Error> {
         return Ok(parsed_nixhash);
     }
 
-    // In all other cases, we assume a bare digest, so there MUST be an externally-passed algo.
+    // Neither of these, assume a bare digest, so there MUST be an externally-passed algo.
     match algo {
         // Fail if there isn't.
         None => Err(Error::MissingInlineHashAlgo(s.to_string())),
@@ -197,7 +197,9 @@ pub fn from_sri_str(s: &str) -> Result<NixHash, Error> {
     }
 }
 
-/// decode a plain digest depending on the hash algo specified externally.
+/// Decode a plain digest depending on the hash algo specified externally.
+/// hexlower, nixbase32 and base64 encodings are supported - the encoding is
+/// inferred from the input length.
 fn decode_digest(s: &str, algo: HashAlgo) -> Result<NixHash, Error> {
     // for the chosen hash algo, calculate the expected (decoded) digest length
     // (as bytes)