Support empty trees

This commit is contained in:
Andrew Ayer 2017-01-05 14:32:22 -08:00
parent 4868243259
commit 55d12ee013
1 changed files with 5 additions and 1 deletions

View File

@ -116,6 +116,10 @@ func VerifyConsistencyProof(proof ct.ConsistencyProof, first *ct.SignedTreeHead,
return true, &MerkleTreeBuilder{stack: leftHashes, size: first.TreeSize}
}
func hashNothing() ct.MerkleTreeNode {
return sha256.New().Sum(nil)
}
func hashLeaf(leafBytes []byte) ct.MerkleTreeNode {
hasher := sha256.New()
hasher.Write([]byte{0x00})
@ -150,7 +154,7 @@ func (builder *MerkleTreeBuilder) Add(hash ct.MerkleTreeNode) {
func (builder *MerkleTreeBuilder) CalculateRoot() ct.MerkleTreeNode {
if len(builder.stack) == 0 {
panic("MerkleTreeBuilder.CalculateRoot called on an empty tree")
return hashNothing()
}
i := len(builder.stack) - 1
hash := builder.stack[i]