diff options
author | Rasmus Dahlberg <rasmus@mullvad.net> | 2022-05-21 20:31:09 +0200 |
---|---|---|
committer | Rasmus Dahlberg <rasmus@mullvad.net> | 2022-06-21 19:46:54 +0200 |
commit | cb6485bb6075179dc2521b8e82db961deae74faf (patch) | |
tree | bf05c3d83686cc056b3ef41b90a37a07b4269833 /cmd/sigsum-debug/head/consistency/consistency.go | |
parent | bbd6591c4f87b3f2c3e870b6418c6234d90a82e6 (diff) |
add proof verification to sigsum-debug
Diffstat (limited to 'cmd/sigsum-debug/head/consistency/consistency.go')
-rw-r--r-- | cmd/sigsum-debug/head/consistency/consistency.go | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/cmd/sigsum-debug/head/consistency/consistency.go b/cmd/sigsum-debug/head/consistency/consistency.go index 18fbdd6..c4feb94 100644 --- a/cmd/sigsum-debug/head/consistency/consistency.go +++ b/cmd/sigsum-debug/head/consistency/consistency.go @@ -1,9 +1,35 @@ package consistency import ( + "bytes" "fmt" + + "git.sigsum.org/sigsum-go/internal/fmtio" + "git.sigsum.org/sigsum-go/pkg/types" ) -func Main(args []string, oldSize, newSize uint64, oldRoot, newRoot string) error { - return fmt.Errorf("TODO") +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 } |