From 0b396553d6ba6223ee7c19e0d29480972d2d0fc7 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 29 Feb 2024 10:52:45 +0200 Subject: refactor(tvix/store/protos): more granular nix-compat conversions implement From<&nix_compat::nixhash::CAHash> for nar_info::ca::Hash individually, and make From<&nix_compat::nixhash::CAHash> for nar_info::Ca a small wrapper that uses it, as well as the .hash().digest_as_bytes() for the digest. Change-Id: I7e9b6edd1e3f149eb270faf2928cd846d74e77ad Reviewed-on: https://cl.tvl.fyi/c/depot/+/11071 Autosubmit: flokli Reviewed-by: Brian Olsen Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/store/src/proto/mod.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'tvix/store/src/proto') diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs index 76178a7a770b..10fde33527cf 100644 --- a/tvix/store/src/proto/mod.rs +++ b/tvix/store/src/proto/mod.rs @@ -301,26 +301,27 @@ impl TryFrom<&nar_info::Ca> for nix_compat::nixhash::CAHash { } } +impl From<&nix_compat::nixhash::CAHash> for nar_info::ca::Hash { + fn from(value: &nix_compat::nixhash::CAHash) -> Self { + match value { + CAHash::Flat(NixHash::Md5(_)) => nar_info::ca::Hash::FlatMd5, + CAHash::Flat(NixHash::Sha1(_)) => nar_info::ca::Hash::FlatSha1, + CAHash::Flat(NixHash::Sha256(_)) => nar_info::ca::Hash::FlatSha256, + CAHash::Flat(NixHash::Sha512(_)) => nar_info::ca::Hash::FlatSha512, + CAHash::Nar(NixHash::Md5(_)) => nar_info::ca::Hash::NarMd5, + CAHash::Nar(NixHash::Sha1(_)) => nar_info::ca::Hash::NarSha1, + CAHash::Nar(NixHash::Sha256(_)) => nar_info::ca::Hash::NarSha256, + CAHash::Nar(NixHash::Sha512(_)) => nar_info::ca::Hash::NarSha512, + CAHash::Text(_) => nar_info::ca::Hash::TextSha256, + } + } +} + impl From<&nix_compat::nixhash::CAHash> for nar_info::Ca { fn from(value: &nix_compat::nixhash::CAHash) -> Self { nar_info::Ca { - r#type: match value { - CAHash::Flat(NixHash::Md5(_)) => nar_info::ca::Hash::FlatMd5.into(), - CAHash::Flat(NixHash::Sha1(_)) => nar_info::ca::Hash::FlatSha1.into(), - CAHash::Flat(NixHash::Sha256(_)) => nar_info::ca::Hash::FlatSha256.into(), - CAHash::Flat(NixHash::Sha512(_)) => nar_info::ca::Hash::FlatSha512.into(), - CAHash::Nar(NixHash::Md5(_)) => nar_info::ca::Hash::NarMd5.into(), - CAHash::Nar(NixHash::Sha1(_)) => nar_info::ca::Hash::NarSha1.into(), - CAHash::Nar(NixHash::Sha256(_)) => nar_info::ca::Hash::NarSha256.into(), - CAHash::Nar(NixHash::Sha512(_)) => nar_info::ca::Hash::NarSha512.into(), - CAHash::Text(_) => nar_info::ca::Hash::TextSha256.into(), - }, - digest: match value { - CAHash::Flat(ref nixhash) | CAHash::Nar(ref nixhash) => { - nixhash.digest_as_bytes().to_vec().into() - } - CAHash::Text(digest) => digest.to_vec().into(), - }, + r#type: Into::::into(value) as i32, + digest: value.hash().digest_as_bytes().to_vec().into(), } } } -- cgit 1.4.1