From 46d89f899fa24c130246efd2feabe03323a2e3ca Mon Sep 17 00:00:00 2001 From: Peter Kolloch Date: Tue, 20 Feb 2024 00:17:40 +0700 Subject: feat(tvix/nix-compat): Extract to_plain_hex_string Towards https://b.tvl.fyi/issues/264 Change-Id: Ibde971bfb6baa97b5c678d84ce1941189bc59f6f Reviewed-on: https://cl.tvl.fyi/c/depot/+/10969 Reviewed-by: flokli Autosubmit: Peter Kolloch Tested-by: BuildkiteCI --- tvix/nix-compat/src/nixhash/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tvix/nix-compat/src/nixhash/mod.rs') diff --git a/tvix/nix-compat/src/nixhash/mod.rs b/tvix/nix-compat/src/nixhash/mod.rs index e148eb72ee..727bf77dc5 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 { -- cgit 1.4.1