From 8918181c47c837802cd47e58372861aa9d60feab Mon Sep 17 00:00:00 2001 From: Pavel Kalinnikov Date: Thu, 28 Apr 2022 15:06:37 +0100 Subject: [PATCH] Unexport helper from a public interface (#2720) --- client/log_client.go | 16 +++++++++++++--- client/log_verifier.go | 11 ----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/client/log_client.go b/client/log_client.go index e92bdd5ee8..4083200912 100644 --- a/client/log_client.go +++ b/client/log_client.go @@ -26,6 +26,7 @@ import ( "github.com/google/trillian" "github.com/google/trillian/client/backoff" "github.com/google/trillian/types" + "github.com/transparency-dev/merkle" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -231,7 +232,7 @@ func (c *LogClient) UpdateRoot(ctx context.Context) (*types.LogRootV1, error) { // It is best to call this method with a context that will timeout to avoid // waiting forever. func (c *LogClient) WaitForInclusion(ctx context.Context, data []byte) error { - leaf := c.BuildLeaf(data) + leaf := prepareLeaf(c.hasher, data) // If a minimum merge delay has been configured, wait at least that long before // starting to poll @@ -305,7 +306,7 @@ func (c *LogClient) AddSequencedLeaves(ctx context.Context, dataByIndex map[int6 if want := indexes[0] + int64(i); index != want { return fmt.Errorf("missing index in contiugous index range. got: %v, want: %v", index, want) } - leaf := c.BuildLeaf(dataByIndex[index]) + leaf := prepareLeaf(c.hasher, dataByIndex[index]) leaf.LeafIndex = index leaves = append(leaves, leaf) } @@ -319,10 +320,19 @@ func (c *LogClient) AddSequencedLeaves(ctx context.Context, dataByIndex map[int6 // QueueLeaf adds a leaf to a Trillian log without blocking. // AlreadyExists is considered a success case by this function. func (c *LogClient) QueueLeaf(ctx context.Context, data []byte) error { - leaf := c.BuildLeaf(data) + leaf := prepareLeaf(c.hasher, data) _, err := c.client.QueueLeaf(ctx, &trillian.QueueLeafRequest{ LogId: c.LogID, Leaf: leaf, }) return err } + +// prepareLeaf returns a trillian.LogLeaf prepopulated with leaf data and hash. +func prepareLeaf(hasher merkle.LogHasher, data []byte) *trillian.LogLeaf { + leafHash := hasher.HashLeaf(data) + return &trillian.LogLeaf{ + LeafValue: data, + MerkleLeafHash: leafHash, + } +} diff --git a/client/log_verifier.go b/client/log_verifier.go index 3154e1412a..3e8ecfff11 100644 --- a/client/log_verifier.go +++ b/client/log_verifier.go @@ -89,14 +89,3 @@ func (c *LogVerifier) VerifyInclusionByHash(trusted *types.LogRootV1, leafHash [ return proof.VerifyInclusion(c.hasher, uint64(pf.LeafIndex), trusted.TreeSize, leafHash, pf.Hashes, trusted.RootHash) } - -// BuildLeaf runs the leaf hasher over data and builds a leaf. -// TODO(pavelkalinnikov): This can be misleading as it creates a partially -// filled LogLeaf. Consider returning a pair instead, or leafHash only. -func (c *LogVerifier) BuildLeaf(data []byte) *trillian.LogLeaf { - leafHash := c.hasher.HashLeaf(data) - return &trillian.LogLeaf{ - LeafValue: data, - MerkleLeafHash: leafHash, - } -}