diff options
author | Florian Klink <flokli@flokli.de> | 2024-02-29T08·52+0200 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2024-03-03T17·12+0000 |
commit | 0b396553d6ba6223ee7c19e0d29480972d2d0fc7 (patch) | |
tree | 7bd80e8c984e1fa1779cfd5e9bfe21599b4f7661 /tvix/store | |
parent | ef3f8936cbb581e615e1e3c96f01ec9b42ceaa9e (diff) |
refactor(tvix/store/protos): more granular nix-compat conversions r/7649
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 <flokli@flokli.de> Reviewed-by: Brian Olsen <me@griff.name> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store')
-rw-r--r-- | tvix/store/src/proto/mod.rs | 35 |
1 files changed, 18 insertions, 17 deletions
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::<nar_info::ca::Hash>::into(value) as i32, + digest: value.hash().digest_as_bytes().to_vec().into(), } } } |