From 55d12ee013aa0baa4c222b7c6a713da42756ad0e Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Thu, 5 Jan 2017 14:32:22 -0800 Subject: [PATCH] Support empty trees --- auditing.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/auditing.go b/auditing.go index 3fa39b9..6416460 100644 --- a/auditing.go +++ b/auditing.go @@ -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]