Rename MerkleTreeBuilder.size to numLeaves
This commit is contained in:
parent
f920ef0ec3
commit
39737f33ec
16
auditing.go
16
auditing.go
|
@ -33,7 +33,7 @@ func VerifyConsistencyProof(proof ct.ConsistencyProof, first *ct.SignedTreeHead,
|
||||||
if !(bytes.Equal(first.SHA256RootHash[:], second.SHA256RootHash[:]) && len(proof) == 0) {
|
if !(bytes.Equal(first.SHA256RootHash[:], second.SHA256RootHash[:]) && len(proof) == 0) {
|
||||||
return false, nil
|
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 {
|
if first.TreeSize == 0 {
|
||||||
// The purpose of the consistency proof is to ensure the append-only
|
// 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 {
|
if len(proof) != 0 {
|
||||||
return false, nil
|
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
|
// Guaranteed that 0 < first.TreeSize < second.TreeSize
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ func VerifyConsistencyProof(proof ct.ConsistencyProof, first *ct.SignedTreeHead,
|
||||||
|
|
||||||
reverseHashes(leftHashes)
|
reverseHashes(leftHashes)
|
||||||
|
|
||||||
return true, &MerkleTreeBuilder{stack: leftHashes, size: first.TreeSize}
|
return true, &MerkleTreeBuilder{stack: leftHashes, numLeaves: first.TreeSize}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashNothing() ct.MerkleTreeNode {
|
func hashNothing() ct.MerkleTreeNode {
|
||||||
|
@ -138,18 +138,18 @@ func hashChildren(left ct.MerkleTreeNode, right ct.MerkleTreeNode) ct.MerkleTree
|
||||||
|
|
||||||
type MerkleTreeBuilder struct {
|
type MerkleTreeBuilder struct {
|
||||||
stack []ct.MerkleTreeNode
|
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) {
|
func (builder *MerkleTreeBuilder) Add(hash ct.MerkleTreeNode) {
|
||||||
builder.stack = append(builder.stack, hash)
|
builder.stack = append(builder.stack, hash)
|
||||||
builder.size++
|
builder.numLeaves++
|
||||||
size := builder.size
|
numLeaves := builder.numLeaves
|
||||||
for size%2 == 0 {
|
for numLeaves%2 == 0 {
|
||||||
left, right := builder.stack[len(builder.stack)-2], builder.stack[len(builder.stack)-1]
|
left, right := builder.stack[len(builder.stack)-2], builder.stack[len(builder.stack)-1]
|
||||||
builder.stack = builder.stack[:len(builder.stack)-2]
|
builder.stack = builder.stack[:len(builder.stack)-2]
|
||||||
builder.stack = append(builder.stack, hashChildren(left, right))
|
builder.stack = append(builder.stack, hashChildren(left, right))
|
||||||
size /= 2
|
numLeaves /= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,9 +254,9 @@ func (s *Scanner) MakeMerkleTreeBuilder(sth *ct.SignedTreeHead) (*MerkleTreeBuil
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
reverseHashes(auditPath)
|
reverseHashes(auditPath)
|
||||||
builder = &MerkleTreeBuilder{size: sth.TreeSize - 1, stack: auditPath}
|
builder = &MerkleTreeBuilder{numLeaves: sth.TreeSize - 1, stack: auditPath}
|
||||||
} else {
|
} else {
|
||||||
builder = &MerkleTreeBuilder{size: 0}
|
builder = &MerkleTreeBuilder{numLeaves: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.Add(leafHash)
|
builder.Add(leafHash)
|
||||||
|
|
Loading…
Reference in New Issue