pub struct TransparencyLog { /* private fields */ }Expand description
Append-only Merkle log.
Maintains an internal subtree-roots cache keyed by (level, index) so Self::inclusion_proof runs in O(log n) instead of
O(n) (issue #36). The cache is in-memory only — no on-disk
format change.
subtree_roots[level][j] is the hash of the COMPLETE 2^level
subtree covering leaves [j*2^level, (j+1)*2^level). Only
fully-populated subtrees are stored; partial right-edge subtrees
are recomputed on demand from the cached children (still
O(log n) total).
Implementations§
Source§impl TransparencyLog
impl TransparencyLog
Sourcepub fn set_operator(&mut self, master_key: VerifyingKey)
pub fn set_operator(&mut self, master_key: VerifyingKey)
Register the operator master key used to verify STHs.
Sourcepub fn root_hash(&self) -> [u8; 32]
pub fn root_hash(&self) -> [u8; 32]
Current Merkle root hash. Returns the empty-tree sentinel when the log has no entries.
Uses the subtree-roots cache (issue #36): O(log n) for any tree size, vs O(n) before the cache.
Sourcepub fn leaf_hash_at(&self, index: u64) -> Option<[u8; 32]>
pub fn leaf_hash_at(&self, index: u64) -> Option<[u8; 32]>
Return the stored leaf hash for the entry at index, if any.
Pairs with Self::inclusion_proof and
verify_inclusion_proof: a verifier holding only the log
and a pinned root hash can verify any entry’s inclusion
without needing the original payload bytes.
Returns None when index >= tree_size() or when index
does not fit in usize.
Sourcepub fn append(
&mut self,
kind: LogEntryKind,
payload: &[u8],
timestamp_version: u64,
) -> Result<u64>
pub fn append( &mut self, kind: LogEntryKind, payload: &[u8], timestamp_version: u64, ) -> Result<u64>
Append a new leaf and return its sequence number.
§Errors
Returns Err on arithmetic overflow of the sequence counter
(unreachable in practice below 2^64 entries).
Sourcepub fn inclusion_proof(&self, leaf_index: u64) -> Result<InclusionProof>
pub fn inclusion_proof(&self, leaf_index: u64) -> Result<InclusionProof>
Generate an inclusion proof for the leaf at leaf_index.
§Errors
Returns Err if leaf_index >= tree_size.
Sourcepub fn canonical_tree_head(&self) -> Vec<u8> ⓘ
pub fn canonical_tree_head(&self) -> Vec<u8> ⓘ
Canonical bytes of the current tree head, used as the message the operator signs.
Sourcepub fn sign_tree_head(&self, operator_key: &SigningKey) -> SignedTreeHead
pub fn sign_tree_head(&self, operator_key: &SigningKey) -> SignedTreeHead
Produce a SignedTreeHead for the current state.
Sourcepub fn verify_tree_head(&self, sth: &SignedTreeHead) -> Result<()>
pub fn verify_tree_head(&self, sth: &SignedTreeHead) -> Result<()>
Verify a SignedTreeHead against the registered operator
master key and against the log’s current root.
§Errors
Returns Err if no operator is registered, if the signature
does not verify, or if the STH’s root_hash does not match
the log’s current root.
Trait Implementations§
Source§impl Debug for TransparencyLog
impl Debug for TransparencyLog
Source§impl Default for TransparencyLog
impl Default for TransparencyLog
Source§fn default() -> TransparencyLog
fn default() -> TransparencyLog
Auto Trait Implementations§
impl Freeze for TransparencyLog
impl RefUnwindSafe for TransparencyLog
impl Send for TransparencyLog
impl Sync for TransparencyLog
impl Unpin for TransparencyLog
impl UnsafeUnpin for TransparencyLog
impl UnwindSafe for TransparencyLog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more