refactor(nix-compat/nixhash/ca_hash): construct algo and digest separately
This is more readable. Change-Id: I632afc53c3e4b3c07fd913355a02e0fd575f4e02 Reviewed-on: https://cl.snix.dev/c/snix/+/30565 Autosubmit: Florian Klink <flokli@flokli.de> Reviewed-by: edef <edef@edef.eu> Tested-by: besadii
This commit is contained in:
parent
b90da345ab
commit
3c23b323d5
1 changed files with 16 additions and 18 deletions
|
|
@ -77,25 +77,23 @@ impl CAHash {
|
|||
/// Formats a [CAHash] in the Nix default hash format, which is the format
|
||||
/// that's used in NARInfos for example.
|
||||
pub fn to_nix_nixbase32_string(&self) -> String {
|
||||
format!(
|
||||
"{}:{}",
|
||||
match self.mode() {
|
||||
HashMode::Flat => match self.hash().as_ref() {
|
||||
NixHash::Md5(_) => "fixed:md5",
|
||||
NixHash::Sha1(_) => "fixed:sha1",
|
||||
NixHash::Sha256(_) => "fixed:sha256",
|
||||
NixHash::Sha512(_) => "fixed:sha512",
|
||||
let (algo, hash) = match self {
|
||||
CAHash::Flat(h) => match h {
|
||||
NixHash::Md5(h) => ("fixed:md5", &h[..]),
|
||||
NixHash::Sha1(h) => ("fixed:sha1", &h[..]),
|
||||
NixHash::Sha256(h) => ("fixed:sha256", &h[..]),
|
||||
NixHash::Sha512(h) => ("fixed:sha512", &h[..]),
|
||||
},
|
||||
HashMode::Nar => match self.hash().as_ref() {
|
||||
NixHash::Md5(_) => "fixed:r:md5",
|
||||
NixHash::Sha1(_) => "fixed:r:sha1",
|
||||
NixHash::Sha256(_) => "fixed:r:sha256",
|
||||
NixHash::Sha512(_) => "fixed:r:sha512",
|
||||
CAHash::Nar(h) => match h {
|
||||
NixHash::Md5(h) => ("fixed:r:md5", &h[..]),
|
||||
NixHash::Sha1(h) => ("fixed:r:sha1", &h[..]),
|
||||
NixHash::Sha256(h) => ("fixed:r:sha256", &h[..]),
|
||||
NixHash::Sha512(h) => ("fixed:r:sha512", &h[..]),
|
||||
},
|
||||
HashMode::Text => "text:sha256",
|
||||
},
|
||||
nixbase32::encode(self.hash().digest_as_bytes())
|
||||
)
|
||||
CAHash::Text(h) => ("text:sha256", &h[..]),
|
||||
};
|
||||
|
||||
format!("{}:{}", algo, nixbase32::encode(hash))
|
||||
}
|
||||
|
||||
/// This takes a serde_json::Map and turns it into this structure. This is necessary to do such
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue