Skip to content

Commit

Permalink
add hashChain
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjit-bhat committed Jun 2, 2024
1 parent 9433688 commit 8903407
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ktmerkle/ktmerkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ const (
errSome errorTy = true
)

type hashChain []linkTy

func (c *hashChain) get(idx uint64) (errorTy, []byte) {
chain := *c
chainLen := uint64(len(chain))
if idx >= chainLen {
return errSome, nil
}
return errNone, chain[idx]
}

func (c *hashChain) put(data []byte) {
chain := *c
var lastLink linkTy
chainLen := uint64(len(chain))
if chainLen > 0 {
lastLink = chain[chainLen-1]
}

var hr cryptoutil.Hasher
cryptoutil.HasherWrite(&hr, lastLink)
cryptoutil.HasherWrite(&hr, data)
newLink := cryptoutil.HasherSum(hr, nil)
*c = append(chain, newLink)
}

// Key server.

type keyServ struct {
Expand Down

0 comments on commit 8903407

Please sign in to comment.