diff options
Diffstat (limited to 'tvix/nix-compat/src/nixhash/ca_hash.rs')
-rw-r--r-- | tvix/nix-compat/src/nixhash/ca_hash.rs | 16 |
1 files changed, 16 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` |