Class ListMerkleTreeNodeSource

java.lang.Object
org.bouncycastle.cert.plants.ListMerkleTreeNodeSource
All Implemented Interfaces:
MerkleTreeNodeSource

public class ListMerkleTreeNodeSource extends Object implements MerkleTreeNodeSource
MerkleTreeNodeSource over an in-memory list of entry hashes, computing each requested node from the entries beneath it (RFC 9162 Section 2.1.1).

This is what the List<byte[]> overloads of the MerkleTreePrimitives generators use, and it suits the tree sizes a test, a prototype or a standalone-certificate subtree handles in memory. A production log should implement MerkleTreeNodeSource over its own storage instead - or extend this class and override getFullSubtreeHash(long, long) to serve cached nodes, falling back to super for the rest.

  • Constructor Details

    • ListMerkleTreeNodeSource

      public ListMerkleTreeNodeSource(List<byte[]> entryHashes, MerkleTreeHash hash)
      Parameters:
      entryHashes - hashes of the tree's entries, entry i at position i (each MTH({entry}), i.e. MerkleTreeHash.hashLeaf(byte[]))
      hash - the Merkle tree hash implementation
  • Method Details

    • size

      public long size()
      Returns:
      the number of entries in the tree
    • getFullSubtreeHash

      public byte[] getFullSubtreeHash(long start, long end)
      Returns MTH(D[start:end]) computed from the entry hashes. Any non-empty range covered by the list is accepted, not only full subtrees.
      Specified by:
      getFullSubtreeHash in interface MerkleTreeNodeSource
      Parameters:
      start - subtree start index (inclusive), a multiple of end - start
      end - subtree end index (exclusive); end - start is a power of two
      Returns:
      the node hash; for end == start + 1 this is the entry hash MTH({entry}), i.e. MerkleTreeHash.hashLeaf(byte[]) of the entry
      Throws:
      IllegalArgumentException - if the range is empty or not covered by the list