diff options
Diffstat (limited to 'pkg/db')
-rw-r--r-- | pkg/db/trillian.go | 15 | ||||
-rw-r--r-- | pkg/db/trillian_test.go | 47 |
2 files changed, 32 insertions, 30 deletions
diff --git a/pkg/db/trillian.go b/pkg/db/trillian.go index 3147c8d..ccb5334 100644 --- a/pkg/db/trillian.go +++ b/pkg/db/trillian.go @@ -7,6 +7,7 @@ import ( "git.sigsum.org/sigsum-go/pkg/log" "git.sigsum.org/sigsum-go/pkg/requests" + "git.sigsum.org/sigsum-go/pkg/merkle" "git.sigsum.org/sigsum-go/pkg/types" "github.com/google/trillian" trillianTypes "github.com/google/trillian/types" @@ -26,14 +27,14 @@ func (c *TrillianClient) AddLeaf(ctx context.Context, req *requests.Leaf) error leaf := types.Leaf{ Statement: types.Statement{ ShardHint: req.ShardHint, - Checksum: *types.HashFn(req.Message[:]), + Checksum: *merkle.HashFn(req.Message[:]), }, Signature: req.Signature, - KeyHash: *types.HashFn(req.PublicKey[:]), + KeyHash: *merkle.HashFn(req.PublicKey[:]), } serialized := leaf.ToBinary() - log.Debug("queueing leaf request: %x", types.LeafHash(serialized)) + log.Debug("queueing leaf request: %x", merkle.HashLeafNode(serialized)) rsp, err := c.GRPC.QueueLeaf(ctx, &trillian.QueueLeafRequest{ LogId: c.TreeID, Leaf: &trillian.LogLeaf{ @@ -75,7 +76,7 @@ func (c *TrillianClient) GetTreeHead(ctx context.Context) (*types.TreeHead, erro if err := r.UnmarshalBinary(rsp.SignedLogRoot.LogRoot); err != nil { return nil, fmt.Errorf("no log root: unmarshal failed: %v", err) } - if len(r.RootHash) != types.HashSize { + if len(r.RootHash) != merkle.HashSize { return nil, fmt.Errorf("unexpected hash length: %d", len(r.RootHash)) } return treeHeadFromLogRoot(&r), nil @@ -181,10 +182,10 @@ func treeHeadFromLogRoot(lr *trillianTypes.LogRootV1) *types.TreeHead { return &th } -func nodePathFromHashes(hashes [][]byte) ([]types.Hash, error) { - path := make([]types.Hash, len(hashes)) +func nodePathFromHashes(hashes [][]byte) ([]merkle.Hash, error) { + path := make([]merkle.Hash, len(hashes)) for i := 0; i < len(hashes); i++ { - if len(hashes[i]) != types.HashSize { + if len(hashes[i]) != merkle.HashSize { return nil, fmt.Errorf("unexpected hash length: %v", len(hashes[i])) } diff --git a/pkg/db/trillian_test.go b/pkg/db/trillian_test.go index 2b19096..cff23da 100644 --- a/pkg/db/trillian_test.go +++ b/pkg/db/trillian_test.go @@ -9,6 +9,7 @@ import ( "time" "git.sigsum.org/log-go/pkg/db/mocks" + "git.sigsum.org/sigsum-go/pkg/merkle" "git.sigsum.org/sigsum-go/pkg/requests" "git.sigsum.org/sigsum-go/pkg/types" "github.com/golang/mock/gomock" @@ -21,7 +22,7 @@ import ( func TestAddLeaf(t *testing.T) { req := &requests.Leaf{ ShardHint: 0, - Message: types.Hash{}, + Message: merkle.Hash{}, Signature: types.Signature{}, PublicKey: types.PublicKey{}, DomainHint: "example.com", @@ -96,7 +97,7 @@ func TestGetTreeHead(t *testing.T) { // valid root root := &ttypes.LogRootV1{ TreeSize: 0, - RootHash: make([]byte, types.HashSize), + RootHash: make([]byte, merkle.HashSize), TimestampNanos: 1622585623133599429, } buf, err := root.MarshalBinary() @@ -104,7 +105,7 @@ func TestGetTreeHead(t *testing.T) { t.Fatalf("must marshal log root: %v", err) } // invalid root - root.RootHash = make([]byte, types.HashSize+1) + root.RootHash = make([]byte, merkle.HashSize+1) bufBadHash, err := root.MarshalBinary() if err != nil { t.Fatalf("must marshal log root: %v", err) @@ -166,7 +167,7 @@ func TestGetTreeHead(t *testing.T) { wantTh: &types.TreeHead{ Timestamp: 1622585623, TreeSize: 0, - RootHash: types.Hash{}, + RootHash: merkle.Hash{}, }, }, } { @@ -248,8 +249,8 @@ func TestGetConsistencyProof(t *testing.T) { rsp: &trillian.GetConsistencyProofResponse{ Proof: &trillian.Proof{ Hashes: [][]byte{ - make([]byte, types.HashSize), - make([]byte, types.HashSize+1), + make([]byte, merkle.HashSize), + make([]byte, merkle.HashSize+1), }, }, }, @@ -261,17 +262,17 @@ func TestGetConsistencyProof(t *testing.T) { rsp: &trillian.GetConsistencyProofResponse{ Proof: &trillian.Proof{ Hashes: [][]byte{ - make([]byte, types.HashSize), - make([]byte, types.HashSize), + make([]byte, merkle.HashSize), + make([]byte, merkle.HashSize), }, }, }, wantProof: &types.ConsistencyProof{ OldSize: 1, NewSize: 3, - Path: []types.Hash{ - types.Hash{}, - types.Hash{}, + Path: []merkle.Hash{ + merkle.Hash{}, + merkle.Hash{}, }, }, }, @@ -301,7 +302,7 @@ func TestGetConsistencyProof(t *testing.T) { func TestGetInclusionProof(t *testing.T) { req := &requests.InclusionProof{ TreeSize: 4, - LeafHash: types.Hash{}, + LeafHash: merkle.Hash{}, } for _, table := range []struct { description string @@ -354,8 +355,8 @@ func TestGetInclusionProof(t *testing.T) { &trillian.Proof{ LeafIndex: 1, Hashes: [][]byte{ - make([]byte, types.HashSize), - make([]byte, types.HashSize+1), + make([]byte, merkle.HashSize), + make([]byte, merkle.HashSize+1), }, }, }, @@ -370,8 +371,8 @@ func TestGetInclusionProof(t *testing.T) { &trillian.Proof{ LeafIndex: 1, Hashes: [][]byte{ - make([]byte, types.HashSize), - make([]byte, types.HashSize), + make([]byte, merkle.HashSize), + make([]byte, merkle.HashSize), }, }, }, @@ -379,9 +380,9 @@ func TestGetInclusionProof(t *testing.T) { wantProof: &types.InclusionProof{ TreeSize: 4, LeafIndex: 1, - Path: []types.Hash{ - types.Hash{}, - types.Hash{}, + Path: []merkle.Hash{ + merkle.Hash{}, + merkle.Hash{}, }, }, }, @@ -416,18 +417,18 @@ func TestGetLeaves(t *testing.T) { firstLeaf := &types.Leaf{ Statement: types.Statement{ ShardHint: 0, - Checksum: types.Hash{}, + Checksum: merkle.Hash{}, }, Signature: types.Signature{}, - KeyHash: types.Hash{}, + KeyHash: merkle.Hash{}, } secondLeaf := &types.Leaf{ Statement: types.Statement{ ShardHint: 0, - Checksum: types.Hash{}, + Checksum: merkle.Hash{}, }, Signature: types.Signature{}, - KeyHash: types.Hash{}, + KeyHash: merkle.Hash{}, } for _, table := range []struct { |