pub struct DerivationTree<const N: usize = DEFAULT_CAP_TABLE_CAPACITY> { /* private fields */ }Expand description
Derivation tree for tracking parent-child capability relationships.
Fixed-size array indexed by slot index. No heap allocation.
Implementations§
Source§impl<const N: usize> DerivationTree<N>
impl<const N: usize> DerivationTree<N>
Sourcepub fn add_root(&mut self, index: u32, epoch: u64) -> CapResult<()>
pub fn add_root(&mut self, index: u32, epoch: u64) -> CapResult<()>
Registers a root capability in the tree.
§Errors
Returns CapError::TreeFull if the index is out of bounds.
Sourcepub fn add_child(
&mut self,
parent_index: u32,
child_index: u32,
depth: u8,
epoch: u64,
) -> CapResult<()>
pub fn add_child( &mut self, parent_index: u32, child_index: u32, depth: u8, epoch: u64, ) -> CapResult<()>
Registers a derived capability in the tree, linking it to its parent.
§Errors
Returns CapError::TreeFull if either index is out of bounds.
Returns CapError::Revoked if the parent node has been revoked.
Sourcepub fn revoke(&mut self, index: u32) -> CapResult<usize>
pub fn revoke(&mut self, index: u32) -> CapResult<usize>
Revokes a node and all its descendants. Returns the count of revoked nodes.
§Errors
Returns CapError::InvalidHandle if the index is out of bounds.
Returns CapError::Revoked if the node has already been revoked.
Sourcepub fn depth(&self, index: u32) -> CapResult<u8>
pub fn depth(&self, index: u32) -> CapResult<u8>
Returns the depth of the node at the given index.
§Errors
Returns CapError::InvalidHandle if the index is invalid or the node is revoked.
Sourcepub fn is_valid(&self, index: u32) -> bool
pub fn is_valid(&self, index: u32) -> bool
Returns true if the node at the given index is valid.
Sourcepub fn get(&self, index: u32) -> Option<&DerivationNode>
pub fn get(&self, index: u32) -> Option<&DerivationNode>
Returns a reference to a node by index.
Sourcepub fn collect_subtree(&self, index: u32) -> [u32; N]
pub fn collect_subtree(&self, index: u32) -> [u32; N]
Collect all valid indices in the subtree rooted at index.
Returns a fixed-size array of indices (up to N). This is used by revocation to synchronize the capability table.
Uses an iterative stack to avoid stack overflow on wide trees.
Sourcepub fn find_parent(&self, child_index: u32) -> Option<u32>
pub fn find_parent(&self, child_index: u32) -> Option<u32>
Find the parent of a given node.
Uses the cached parent_index field for O(1) lookup. Falls back
to O(N) scan if the cached index is stale (should not happen in
normal operation).
Returns None for root nodes or if the parent is not found.