pub struct Hasher { /* private fields */ }Expand description
An incremental content hasher for a module directory.
try_add records relative paths into a BTreeSet, so they are kept in
lexicographic order as they are inserted. finalize walks them in that
order, opens each file under the configured root, and feeds path bytes
plus raw file contents into a single SHA-256 state.
Implementations§
Source§impl Hasher
impl Hasher
Sourcepub fn paths(&self) -> impl Iterator<Item = &RelativePath>
pub fn paths(&self) -> impl Iterator<Item = &RelativePath>
Returns an iterator over the recorded paths in lexicographic order.
Sourcepub fn try_add(
&mut self,
path: impl Into<String>,
) -> Result<&mut Self, HashError>
pub fn try_add( &mut self, path: impl Into<String>, ) -> Result<&mut Self, HashError>
Records a path relative to the hasher’s root.
Accepts an absolute path under root (which is converted to a relative
form) or any RelativePath-convertible input.
Sourcepub fn finalize(self) -> Result<ContentHash, HashError>
pub fn finalize(self) -> Result<ContentHash, HashError>
Computes the ContentHash of the recorded paths.
Each file’s full path is canonicalized (resolving symbolic links) before reading; if the resolved target falls outside the module root, the module is rejected per the spec’s symlink-containment rule. Without this check, a symbolic link inside the module could pull bytes from elsewhere on the filesystem into the digest.