diff options
-rw-r--r-- | tvix/nix-compat/src/nixhash/ca_hash.rs | 16 | ||||
-rw-r--r-- | tvix/nix-compat/src/nixhash/mod.rs | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/tvix/nix-compat/src/nixhash/ca_hash.rs b/tvix/nix-compat/src/nixhash/ca_hash.rs index 1c2f61dc6c65..2bf5f966cefe 100644 --- a/tvix/nix-compat/src/nixhash/ca_hash.rs +++ b/tvix/nix-compat/src/nixhash/ca_hash.rs @@ -22,6 +22,14 @@ pub enum CAHash { Text([u8; 32]), // "text", only supports sha256 } +/// Representation for the supported hash modes. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum HashMode { + Flat, + Nar, + Text, +} + impl CAHash { pub fn hash(&self) -> Cow<NixHash> { match *self { @@ -31,6 +39,14 @@ impl CAHash { } } + pub fn mode(&self) -> HashMode { + match self { + CAHash::Flat(_) => HashMode::Flat, + CAHash::Nar(_) => HashMode::Nar, + CAHash::Text(_) => HashMode::Text, + } + } + /// Constructs a [CAHash] from the textual representation, /// which is one of the three: /// - `text:sha256:$nixbase32sha256digest` diff --git a/tvix/nix-compat/src/nixhash/mod.rs b/tvix/nix-compat/src/nixhash/mod.rs index a6f2b967996a..25b89d8f8eb0 100644 --- a/tvix/nix-compat/src/nixhash/mod.rs +++ b/tvix/nix-compat/src/nixhash/mod.rs @@ -9,6 +9,7 @@ mod ca_hash; pub use algos::HashAlgo; pub use ca_hash::CAHash; +pub use ca_hash::HashMode as CAHashMode; /// NixHash represents hashes known by Nix. #[derive(Clone, Debug, Eq, PartialEq)] |