pub struct Tree { /* private fields */ }Expand description
A complete tree with its encoding scheme and per-entry salts kept together.
Use Self::from_entries_salted_v4 to supply explicit salts for a new tree;
mutations through Self::insert maintain the selected scheme.
Explicit salt mutation is internal, so it cannot corrupt a flat tree:
use heddle_object_model::object::{ContentHash, Tree, TreeEntry};
let mut tree = Tree::new();
if let Ok(entry) = TreeEntry::file("readme", ContentHash::compute(b"text"), false) {
tree.insert_salted(entry, [7; 32]);
}Implementations§
Source§impl Tree
impl Tree
pub fn new() -> Tree
pub fn from_entries(entries: Vec<TreeEntry>) -> Tree
Sourcepub fn from_entries_salted_v4(
entries: Vec<TreeEntry>,
salts: Vec<[u8; 32]>,
) -> Result<Tree, TreeError>
pub fn from_entries_salted_v4( entries: Vec<TreeEntry>, salts: Vec<[u8; 32]>, ) -> Result<Tree, TreeError>
Build a salted V4 tree from entries and their parallel salts.
salts[i] is the salt for entries[i] (before sorting); the pair is
sorted together by entry name so the parallel-vector invariant holds.
The sticky-salt inheritance policy is a later capture-leg concern —
this constructor carries whatever salts it is given.
Sourcepub fn try_from_decoded_entries(
entries: Vec<TreeEntry>,
) -> Result<Tree, TreeError>
pub fn try_from_decoded_entries( entries: Vec<TreeEntry>, ) -> Result<Tree, TreeError>
Build a tree from entries that are already in canonical name order.
Unlike Self::from_entries, this does not sort. Decoders use it so
eager and streaming paths reject the same out-of-order or duplicate
encodings instead of silently canonicalizing them.
Sourcepub fn try_from_decoded_entries_salted_v4(
entries: Vec<TreeEntry>,
salts: Vec<[u8; 32]>,
) -> Result<Tree, TreeError>
pub fn try_from_decoded_entries_salted_v4( entries: Vec<TreeEntry>, salts: Vec<[u8; 32]>, ) -> Result<Tree, TreeError>
Build a salted V4 tree from already-name-ordered entries and their parallel salts. Decoders (HSR1, msgpack v4) use this: it does not sort, so it rejects the same out-of-order/duplicate encodings V3 does.
Sourcepub fn scheme(&self) -> TreeScheme
pub fn scheme(&self) -> TreeScheme
The hashing scheme this tree’s id is computed under.
Sourcepub fn salt_at(&self, index: usize) -> Option<[u8; 32]>
pub fn salt_at(&self, index: usize) -> Option<[u8; 32]>
The salt for the entry at index (V4 only), or None for V3 / out of
range.
pub fn validate(&self) -> Result<(), TreeError>
pub fn entries(&self) -> &[TreeEntry]
pub fn get(&self, name: &str) -> Option<&TreeEntry>
pub fn insert(&mut self, entry: TreeEntry)
pub fn remove(&mut self, name: &str) -> Option<TreeEntry>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn hash(&self) -> ContentHash
Sourcepub fn v4_leaf_hash_at(&self, index: usize) -> Option<ContentHash>
pub fn v4_leaf_hash_at(&self, index: usize) -> Option<ContentHash>
The salted per-entry leaf commitment for the entry at index, or None
for a V3 tree / out-of-range index. This is the name-free handle a
redacted serve projection is keyed by; capture-time entry-visibility
authoring resolves a path to its enclosing tree + this leaf hash.
Sourcepub fn v4_leaf_hash_for(&self, name: &str) -> Option<ContentHash>
pub fn v4_leaf_hash_for(&self, name: &str) -> Option<ContentHash>
The salted leaf commitment for the entry named name, or None if the
name is absent or this is a V3 tree.
pub fn iter(&self) -> impl Iterator<Item = &TreeEntry>
pub fn get_path(&self, path: &Path) -> Option<&TreeEntry>
Source§impl Tree
impl Tree
pub fn decode_current_msgpack(data: &[u8]) -> Result<Tree, TreeDecodeError>
Source§impl Tree
impl Tree
Sourcepub fn encode_canonical(&self) -> Result<Vec<u8>, TreeStreamError>
pub fn encode_canonical(&self) -> Result<Vec<u8>, TreeStreamError>
Encode this tree as an uncompressed canonical body: HTR4 for a V3 flat tree, HSR1 for a V4 salted tree. Scheme-total: a V4 tree is NEVER emitted through the salt-less HTR4 body.
Sourcepub fn decode_canonical(data: &[u8]) -> Result<Tree, TreeStreamError>
pub fn decode_canonical(data: &[u8]) -> Result<Tree, TreeStreamError>
Decode a complete canonical body. Dispatches on the body magic: HTR4 → flat V3 decode; HSR1 → salted V4 decode. A redacted projection (HRT1) is rejected here — it is serve-only and must never be read as a full tree.
Sourcepub fn encode_canonical_blocked(
&self,
level: i32,
min_size: usize,
) -> Result<Vec<u8>, TreeStreamError>
pub fn encode_canonical_blocked( &self, level: i32, min_size: usize, ) -> Result<Vec<u8>, TreeStreamError>
Encode block-compressed HTR4, falling back to raw v4 when the complete object would not be smaller. Callers apply the small-tree policy.
Source§impl Tree
impl Tree
Sourcepub fn encode_lean(&self) -> Result<Vec<u8>, TreeStreamError>
pub fn encode_lean(&self) -> Result<Vec<u8>, TreeStreamError>
Encode a cheap HLR1 materialized anchor. The content hash deliberately stays outside the body and must be supplied by the object store while decoding.
Sourcepub fn decode_lean(
data: &[u8],
expected: ContentHash,
) -> Result<Tree, TreeStreamError>
pub fn decode_lean( data: &[u8], expected: ContentHash, ) -> Result<Tree, TreeStreamError>
Decode a complete HLR1 anchor and validate it against its object key.
Source§impl Tree
impl Tree
Sourcepub fn decode_canonical_streamed(data: &[u8]) -> Result<Tree, TreeStreamError>
pub fn decode_canonical_streamed(data: &[u8]) -> Result<Tree, TreeStreamError>
Decode HTR4 through the streaming reader and collect the eager Tree.