From 39737f33ec1bddab9d23ae664adbd8a754be17cb Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Thu, 5 Jan 2017 14:41:44 -0800 Subject: [PATCH] Rename MerkleTreeBuilder.size to numLeaves --- auditing.go | 16 ++++++++-------- scanner.go | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/auditing.go b/auditing.go index 0ef7c41..fd2fc1d 100644 --- a/auditing.go +++ b/auditing.go @@ -33,7 +33,7 @@ func VerifyConsistencyProof(proof ct.ConsistencyProof, first *ct.SignedTreeHead, if !(bytes.Equal(first.SHA256RootHash[:], second.SHA256RootHash[:]) && len(proof) == 0) { return false, nil } - return true, &MerkleTreeBuilder{stack: []ct.MerkleTreeNode{first.SHA256RootHash[:]}, size: 1} + return true, &MerkleTreeBuilder{stack: []ct.MerkleTreeNode{first.SHA256RootHash[:]}, numLeaves: 1} } if first.TreeSize == 0 { // The purpose of the consistency proof is to ensure the append-only @@ -43,7 +43,7 @@ func VerifyConsistencyProof(proof ct.ConsistencyProof, first *ct.SignedTreeHead, if len(proof) != 0 { return false, nil } - return true, &MerkleTreeBuilder{stack: []ct.MerkleTreeNode{}, size: 0} + return true, &MerkleTreeBuilder{stack: []ct.MerkleTreeNode{}, numLeaves: 0} } // Guaranteed that 0 < first.TreeSize < second.TreeSize @@ -114,7 +114,7 @@ func VerifyConsistencyProof(proof ct.ConsistencyProof, first *ct.SignedTreeHead, reverseHashes(leftHashes) - return true, &MerkleTreeBuilder{stack: leftHashes, size: first.TreeSize} + return true, &MerkleTreeBuilder{stack: leftHashes, numLeaves: first.TreeSize} } func hashNothing() ct.MerkleTreeNode { @@ -138,18 +138,18 @@ func hashChildren(left ct.MerkleTreeNode, right ct.MerkleTreeNode) ct.MerkleTree type MerkleTreeBuilder struct { stack []ct.MerkleTreeNode - size uint64 // number of hashes added so far + numLeaves uint64 // number of hashes added so far } func (builder *MerkleTreeBuilder) Add(hash ct.MerkleTreeNode) { builder.stack = append(builder.stack, hash) - builder.size++ - size := builder.size - for size%2 == 0 { + builder.numLeaves++ + numLeaves := builder.numLeaves + for numLeaves%2 == 0 { left, right := builder.stack[len(builder.stack)-2], builder.stack[len(builder.stack)-1] builder.stack = builder.stack[:len(builder.stack)-2] builder.stack = append(builder.stack, hashChildren(left, right)) - size /= 2 + numLeaves /= 2 } } diff --git a/scanner.go b/scanner.go index 0028795..1331cec 100644 --- a/scanner.go +++ b/scanner.go @@ -254,9 +254,9 @@ func (s *Scanner) MakeMerkleTreeBuilder(sth *ct.SignedTreeHead) (*MerkleTreeBuil return nil, err } reverseHashes(auditPath) - builder = &MerkleTreeBuilder{size: sth.TreeSize - 1, stack: auditPath} + builder = &MerkleTreeBuilder{numLeaves: sth.TreeSize - 1, stack: auditPath} } else { - builder = &MerkleTreeBuilder{size: 0} + builder = &MerkleTreeBuilder{numLeaves: 0} } builder.Add(leafHash)