fix(tvix/store): add missing nar_info::ca::Hash::TextSha256

Also reorder to how it's ordered in the .proto file.

Change-Id: I87c422feac4d12f6a84f99aa889f9c524a9878b9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11985
Tested-by: BuildkiteCI
Reviewed-by: Brian Olsen <me@griff.name>
This commit is contained in:
Florian Klink 2024-07-20 11:43:09 +02:00 committed by flokli
parent 18da8a205e
commit c64c028366

View file

@ -260,16 +260,41 @@ impl TryFrom<&nar_info::Ca> for nix_compat::nixhash::CAHash {
fn try_from(value: &nar_info::Ca) -> Result<Self, Self::Error> {
Ok(match value.r#type {
typ if typ == nar_info::ca::Hash::FlatMd5 as i32 => {
Self::Flat(NixHash::Md5(value.digest[..].try_into().map_err(|_| {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "FlatMd5")
typ if typ == nar_info::ca::Hash::NarSha256 as i32 => {
Self::Nar(NixHash::Sha256(value.digest[..].try_into().map_err(
|_| ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarSha256"),
)?))
}
typ if typ == nar_info::ca::Hash::NarSha1 as i32 => {
Self::Nar(NixHash::Sha1(value.digest[..].try_into().map_err(
|_| ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarSha1"),
)?))
}
typ if typ == nar_info::ca::Hash::NarSha512 as i32 => Self::Nar(NixHash::Sha512(
Box::new(value.digest[..].try_into().map_err(|_| {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarSha512")
})?),
)),
typ if typ == nar_info::ca::Hash::NarMd5 as i32 => {
Self::Nar(NixHash::Md5(value.digest[..].try_into().map_err(|_| {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarMd5")
})?))
}
typ if typ == nar_info::ca::Hash::TextSha256 as i32 => {
Self::Text(value.digest[..].try_into().map_err(|_| {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "TextSha256")
})?)
}
typ if typ == nar_info::ca::Hash::FlatSha1 as i32 => {
Self::Flat(NixHash::Sha1(value.digest[..].try_into().map_err(
|_| ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "FlatSha1"),
)?))
}
typ if typ == nar_info::ca::Hash::FlatMd5 as i32 => {
Self::Flat(NixHash::Md5(value.digest[..].try_into().map_err(|_| {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "FlatMd5")
})?))
}
typ if typ == nar_info::ca::Hash::FlatSha256 as i32 => {
Self::Flat(NixHash::Sha256(value.digest[..].try_into().map_err(
|_| ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "FlatSha256"),
@ -280,26 +305,6 @@ impl TryFrom<&nar_info::Ca> for nix_compat::nixhash::CAHash {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "FlatSha512")
})?),
)),
typ if typ == nar_info::ca::Hash::NarMd5 as i32 => {
Self::Nar(NixHash::Md5(value.digest[..].try_into().map_err(|_| {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarMd5")
})?))
}
typ if typ == nar_info::ca::Hash::NarSha1 as i32 => {
Self::Nar(NixHash::Sha1(value.digest[..].try_into().map_err(
|_| ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarSha1"),
)?))
}
typ if typ == nar_info::ca::Hash::NarSha256 as i32 => {
Self::Nar(NixHash::Sha256(value.digest[..].try_into().map_err(
|_| ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarSha256"),
)?))
}
typ if typ == nar_info::ca::Hash::NarSha512 as i32 => Self::Nar(NixHash::Sha512(
Box::new(value.digest[..].try_into().map_err(|_| {
ConvertCAError::InvalidReferenceDigestLen(value.digest.len(), "NarSha512")
})?),
)),
typ => return Err(ConvertCAError::UnknownHashType(typ)),
})
}