aboutsummaryrefslogtreecommitdiff
path: root/cmd/sigsum-debug/head/consistency/consistency.go
blob: c4feb9404c1bf8097ba131f50616581c522243e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package consistency

import (
	"bytes"
	"fmt"

	"git.sigsum.org/sigsum-go/internal/fmtio"
	"git.sigsum.org/sigsum-go/pkg/types"
)

func Main(args []string, optOldSize, optNewSize uint64, optOldRoot, optNewRoot string) error {
	if len(args) != 0 {
		return fmt.Errorf("trailing arguments: %v", args)
	}
	b, err := fmtio.BytesFromStdin()
	if err != nil {
		return fmt.Errorf("read: %w", err)
	}
	var proof types.ConsistencyProof
	if err := proof.FromASCII(bytes.NewBuffer(b), optOldSize, optNewSize); err != nil {
		return fmt.Errorf("parse proof: %w", err)
	}
	oldRoot, err := fmtio.HashFromHex(optOldRoot)
	if err != nil {
		return fmt.Errorf("parse old root: %w", err)
	}
	newRoot, err := fmtio.HashFromHex(optNewRoot)
	if err != nil {
		return fmt.Errorf("parse new root: %w", err)
	}
	if err := proof.Verify(&oldRoot, &newRoot); err != nil {
		return fmt.Errorf("verify: %w", err)
	}
	return nil
}