From 7e0f0f84eac2e37edfd177196ed65afa0559f967 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Mon, 20 Dec 2021 14:37:43 +0100 Subject: types: Add types and tests --- pkg/types/proof.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pkg/types/proof.go (limited to 'pkg/types/proof.go') diff --git a/pkg/types/proof.go b/pkg/types/proof.go new file mode 100644 index 0000000..4311357 --- /dev/null +++ b/pkg/types/proof.go @@ -0,0 +1,46 @@ +package types + +import ( + "io" + + "git.sigsum.org/sigsum-lib-go/pkg/ascii" +) + +type InclusionProof struct { + TreeSize uint64 + LeafIndex uint64 `ascii:"leaf_index"` + Path []Hash `ascii:"inclusion_path"` +} + +type ConsistencyProof struct { + NewSize uint64 + OldSize uint64 + Path []Hash `ascii:"consistency_path"` +} + +func (p *InclusionProof) ToASCII(w io.Writer) error { + return ascii.StdEncoding.Serialize(w, p) +} + +func (p *InclusionProof) FromASCII(r io.Reader, treeSize uint64) error { + p.TreeSize = treeSize + return ascii.StdEncoding.Deserialize(r, p) +} + +func (p *InclusionProof) Verify(treeSize uint64) bool { + return false // TODO: verify inclusion proof +} + +func (p *ConsistencyProof) ToASCII(w io.Writer) error { + return ascii.StdEncoding.Serialize(w, p) +} + +func (p *ConsistencyProof) FromASCII(r io.Reader, oldSize, newSize uint64) error { + p.OldSize = oldSize + p.NewSize = newSize + return ascii.StdEncoding.Deserialize(r, p) +} + +func (p *ConsistencyProof) Verify(newRoot, oldRoot *Hash) bool { + return false // TODO: verify consistency proof +} -- cgit v1.2.3