aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/proof.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus@mullvad.net>2022-05-21 20:31:09 +0200
committerRasmus Dahlberg <rasmus@mullvad.net>2022-06-21 19:46:54 +0200
commit8d097316c0a12f14de4b9e27e1fe4c458c32f4b0 (patch)
tree84ff3998b167bb5e12f26842ddff2c565c7a86bb /pkg/types/proof.go
parent97540f9ded30f68f9fda62f66f3006414cbfd5b7 (diff)
use hashing from merkle package
Diffstat (limited to 'pkg/types/proof.go')
-rw-r--r--pkg/types/proof.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/pkg/types/proof.go b/pkg/types/proof.go
index 8c1474e..f2df332 100644
--- a/pkg/types/proof.go
+++ b/pkg/types/proof.go
@@ -4,18 +4,19 @@ import (
"io"
"git.sigsum.org/sigsum-go/pkg/ascii"
+ "git.sigsum.org/sigsum-go/pkg/merkle"
)
type InclusionProof struct {
TreeSize uint64
LeafIndex uint64 `ascii:"leaf_index"`
- Path []Hash `ascii:"inclusion_path"`
+ Path []merkle.Hash `ascii:"inclusion_path"`
}
type ConsistencyProof struct {
NewSize uint64
OldSize uint64
- Path []Hash `ascii:"consistency_path"`
+ Path []merkle.Hash `ascii:"consistency_path"`
}
func (p *InclusionProof) ToASCII(w io.Writer) error {
@@ -27,8 +28,8 @@ func (p *InclusionProof) FromASCII(r io.Reader, treeSize uint64) error {
return ascii.StdEncoding.Deserialize(r, p)
}
-func (p *InclusionProof) Verify(treeSize uint64) bool {
- return false // TODO: verify inclusion proof
+func (p *InclusionProof) Verify(leaf *merkle.Hash, root *merkle.Hash) error {
+ return merkle.VerifyInclusion(*leaf, p.LeafIndex, p.TreeSize, *root, p.Path)
}
func (p *ConsistencyProof) ToASCII(w io.Writer) error {
@@ -41,6 +42,6 @@ func (p *ConsistencyProof) FromASCII(r io.Reader, oldSize, newSize uint64) error
return ascii.StdEncoding.Deserialize(r, p)
}
-func (p *ConsistencyProof) Verify(newRoot, oldRoot *Hash) bool {
- return false // TODO: verify consistency proof
+func (p *ConsistencyProof) Verify(oldRoot, newRoot *merkle.Hash) error {
+ return merkle.VerifyConsistency(p.OldSize, p.NewSize, *oldRoot, *newRoot, p.Path)
}