From 1224f565a27155c3abef3ecf4d86cf6f472b1374 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sat, 21 May 2022 20:32:17 +0200 Subject: pick-up merkle package TODO(ln5): upgrade sigsum-go dependency in go.mod file --- pkg/state/single.go | 13 +++++++------ pkg/state/single_test.go | 13 +++++++------ pkg/state/state_manager.go | 3 ++- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'pkg/state') diff --git a/pkg/state/single.go b/pkg/state/single.go index 695f0e3..7e7c804 100644 --- a/pkg/state/single.go +++ b/pkg/state/single.go @@ -10,6 +10,7 @@ import ( "git.sigsum.org/log-go/pkg/db" "git.sigsum.org/sigsum-go/pkg/log" + "git.sigsum.org/sigsum-go/pkg/merkle" "git.sigsum.org/sigsum-go/pkg/types" ) @@ -17,7 +18,7 @@ import ( type StateManagerSingle struct { client db.Client signer crypto.Signer - namespace types.Hash + namespace merkle.Hash interval time.Duration deadline time.Duration @@ -29,14 +30,14 @@ type StateManagerSingle struct { // Syncronized and deduplicated witness cosignatures for signedTreeHead events chan *event - cosignatures map[types.Hash]*types.Signature + cosignatures map[merkle.Hash]*types.Signature } func NewStateManagerSingle(client db.Client, signer crypto.Signer, interval, deadline time.Duration) (*StateManagerSingle, error) { sm := &StateManagerSingle{ client: client, signer: signer, - namespace: *types.HashFn(signer.Public().(ed25519.PublicKey)), + namespace: *merkle.HashFn(signer.Public().(ed25519.PublicKey)), interval: interval, deadline: deadline, } @@ -97,7 +98,7 @@ func (sm *StateManagerSingle) AddCosignature(ctx context.Context, pub *types.Pub return fmt.Errorf("invalid cosignature") } select { - case sm.events <- &event{types.HashFn(pub[:]), sig}: + case sm.events <- &event{merkle.HashFn(pub[:]), sig}: return nil case <-ctx.Done(): return fmt.Errorf("request timeout") @@ -136,7 +137,7 @@ func (sm *StateManagerSingle) setCosignedTreeHead() { var cth types.CosignedTreeHead cth.SignedTreeHead = *sm.signedTreeHead cth.Cosignature = make([]types.Signature, 0, n) - cth.KeyHash = make([]types.Hash, 0, n) + cth.KeyHash = make([]merkle.Hash, 0, n) for keyHash, cosignature := range sm.cosignatures { cth.KeyHash = append(cth.KeyHash, keyHash) cth.Cosignature = append(cth.Cosignature, *cosignature) @@ -145,7 +146,7 @@ func (sm *StateManagerSingle) setCosignedTreeHead() { } func (sm *StateManagerSingle) setToCosignTreeHead(nextSTH *types.SignedTreeHead) { - sm.cosignatures = make(map[types.Hash]*types.Signature) + sm.cosignatures = make(map[merkle.Hash]*types.Signature) sm.signedTreeHead = nextSTH } diff --git a/pkg/state/single_test.go b/pkg/state/single_test.go index 8e89020..c859603 100644 --- a/pkg/state/single_test.go +++ b/pkg/state/single_test.go @@ -12,6 +12,7 @@ import ( db "git.sigsum.org/log-go/pkg/db/mocks" "git.sigsum.org/log-go/pkg/state/mocks" + "git.sigsum.org/sigsum-go/pkg/merkle" "git.sigsum.org/sigsum-go/pkg/types" "github.com/golang/mock/gomock" ) @@ -87,7 +88,7 @@ func TestToCosignTreeHead(t *testing.T) { func TestCosignedTreeHead(t *testing.T) { want := &types.CosignedTreeHead{ Cosignature: make([]types.Signature, 1), - KeyHash: make([]types.Hash, 1), + KeyHash: make([]merkle.Hash, 1), } sm := StateManagerSingle{ cosignedTreeHead: want, @@ -130,7 +131,7 @@ func TestAddCosignature(t *testing.T) { }, } { sm := &StateManagerSingle{ - namespace: *types.HashFn(nil), + namespace: *merkle.HashFn(nil), signedTreeHead: &types.SignedTreeHead{}, events: make(chan *event, 1), } @@ -161,17 +162,17 @@ func TestRotate(t *testing.T) { sth := &types.SignedTreeHead{} nextSTH := &types.SignedTreeHead{TreeHead: types.TreeHead{Timestamp: 1}} ev := &event{ - keyHash: &types.Hash{}, + keyHash: &merkle.Hash{}, cosignature: &types.Signature{}, } wantCTH := &types.CosignedTreeHead{ SignedTreeHead: *sth, - KeyHash: []types.Hash{*ev.keyHash}, + KeyHash: []merkle.Hash{*ev.keyHash}, Cosignature: []types.Signature{*ev.cosignature}, } sm := &StateManagerSingle{ signedTreeHead: sth, - cosignatures: make(map[types.Hash]*types.Signature), + cosignatures: make(map[merkle.Hash]*types.Signature), events: make(chan *event, 1), } defer close(sm.events) @@ -207,7 +208,7 @@ func mustKeyPair(t *testing.T) (crypto.Signer, types.PublicKey) { return sk, pub } -func mustSign(t *testing.T, s crypto.Signer, th *types.TreeHead, kh *types.Hash) *types.SignedTreeHead { +func mustSign(t *testing.T, s crypto.Signer, th *types.TreeHead, kh *merkle.Hash) *types.SignedTreeHead { t.Helper() sth, err := th.Sign(s, kh) if err != nil { diff --git a/pkg/state/state_manager.go b/pkg/state/state_manager.go index 9533479..ce9fc0a 100644 --- a/pkg/state/state_manager.go +++ b/pkg/state/state_manager.go @@ -3,6 +3,7 @@ package state import ( "context" + "git.sigsum.org/sigsum-go/pkg/merkle" "git.sigsum.org/sigsum-go/pkg/types" ) @@ -24,6 +25,6 @@ type StateManager interface { // event is a verified cosignature request type event struct { - keyHash *types.Hash + keyHash *merkle.Hash cosignature *types.Signature } -- cgit v1.2.3