From e570c2c947dbfc5cbcc7d677f784523ec3c04fe0 Mon Sep 17 00:00:00 2001 From: Pavel Kalinnikov Date: Mon, 25 Apr 2022 09:17:59 -0400 Subject: [PATCH] Unexport helper from a public interface --- 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 7dd5a4b383..04278cbea2 100644 --- a/client/log_verifier.go +++ b/client/log_verifier.go @@ -92,14 +92,3 @@ func (c *LogVerifier) VerifyInclusionByHash(trusted *types.LogRootV1, leafHash [ return c.v.VerifyInclusion(uint64(proof.LeafIndex), trusted.TreeSize, leafHash, proof.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, - } -}