diff options
author | Peter Kolloch <info@eigenvalue.net> | 2024-02-19T17·17+0700 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-02-19T17·32+0000 |
commit | 46d89f899fa24c130246efd2feabe03323a2e3ca (patch) | |
tree | 403d83b3b730c60af455e4af3dd8b9475d927c07 /tvix/nix-compat/src/nixhash | |
parent | df73d5f242e3b737d356546450dc883214c14b37 (diff) |
feat(tvix/nix-compat): Extract to_plain_hex_string r/7560
Towards https://b.tvl.fyi/issues/264 Change-Id: Ibde971bfb6baa97b5c678d84ce1941189bc59f6f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10969 Reviewed-by: flokli <flokli@flokli.de> Autosubmit: Peter Kolloch <info@eigenvalue.net> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/nixhash')
-rw-r--r-- | tvix/nix-compat/src/nixhash/mod.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/tvix/nix-compat/src/nixhash/mod.rs b/tvix/nix-compat/src/nixhash/mod.rs index e148eb72ee9c..727bf77dc57d 100644 --- a/tvix/nix-compat/src/nixhash/mod.rs +++ b/tvix/nix-compat/src/nixhash/mod.rs @@ -61,11 +61,7 @@ impl NixHash { /// Formats a [NixHash] in the Nix default hash format, /// which is the algo, followed by a colon, then the lower hex encoded digest. pub fn to_nix_hex_string(&self) -> String { - format!( - "{}:{}", - self.algo(), - HEXLOWER.encode(self.digest_as_bytes()) - ) + format!("{}:{}", self.algo(), self.to_plain_hex_string()) } /// Formats a [NixHash] in the format that's used inside CAHash, @@ -77,6 +73,11 @@ impl NixHash { nixbase32::encode(self.digest_as_bytes()) ) } + + /// Returns the digest as a hex string -- without any algorithm prefix. + pub fn to_plain_hex_string(&self) -> String { + HEXLOWER.encode(self.digest_as_bytes()) + } } impl TryFrom<(HashAlgo, &[u8])> for NixHash { |