aboutsummaryrefslogtreecommitdiff
path: root/client/cmd/get-consistency-proof
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-03-16 16:29:24 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-03-16 16:29:24 +0100
commit453a0c38516496052c5f570691c74516c8675e2d (patch)
treef56648b1073dc327b0cd1cc25e371cd5ebefa00d /client/cmd/get-consistency-proof
parent9f7690327f8d74abdd86232546a154ab8408d174 (diff)
added additional basic client commands
Diffstat (limited to 'client/cmd/get-consistency-proof')
-rw-r--r--client/cmd/get-consistency-proof/main.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/client/cmd/get-consistency-proof/main.go b/client/cmd/get-consistency-proof/main.go
new file mode 100644
index 0000000..bb8a7a6
--- /dev/null
+++ b/client/cmd/get-consistency-proof/main.go
@@ -0,0 +1,70 @@
+package main
+
+import (
+ "context"
+ "flag"
+ "fmt"
+
+ "encoding/base64"
+
+ "github.com/golang/glog"
+ "github.com/system-transparency/stfe/client"
+ "github.com/system-transparency/stfe/types"
+)
+
+var (
+ first = flag.String("first", "", "base64-encoded sth")
+ second = flag.String("second", "", "base64-encoded sth")
+)
+
+func main() {
+ flag.Parse()
+ defer glog.Flush()
+
+ client, err := client.NewClientFromFlags()
+ if err != nil {
+ glog.Errorf("NewClientFromFlags: %v", err)
+ return
+ }
+ sth1, sth2, err := newParamsFromFlags()
+ if err != nil {
+ glog.Errorf("NewRequestFromFlags: %v", err)
+ return
+ }
+
+ proof, err := client.GetConsistencyProof(context.Background(), sth1, sth2)
+ if err != nil {
+ glog.Errorf("GetConsistencyProof: %v", err)
+ return
+ }
+ serialized, err := types.Marshal(*proof)
+ if err != nil {
+ glog.Errorf("Marshal: %v", err)
+ return
+ }
+ fmt.Println("proof:", base64.StdEncoding.EncodeToString(serialized))
+}
+
+func newParamsFromFlags() (*types.StItem, *types.StItem, error) {
+ sth1, err := decodeSthStr(*first)
+ if err != nil {
+ return nil, nil, fmt.Errorf("first: decodeSthStr: %v", err)
+ }
+ sth2, err := decodeSthStr(*second)
+ if err != nil {
+ return nil, nil, fmt.Errorf("second: decodeSthStr: %v", err)
+ }
+ return sth1, sth2, nil
+}
+
+func decodeSthStr(sthStr string) (*types.StItem, error) {
+ serialized, err := base64.StdEncoding.DecodeString(sthStr)
+ if err != nil {
+ return nil, fmt.Errorf("DecodeString: %v", err)
+ }
+ var item types.StItem
+ if err = types.Unmarshal(serialized, &item); err != nil {
+ return nil, fmt.Errorf("Unmarshal: %v", err)
+ }
+ return &item, nil
+}