diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-05 18:17:23 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-05 18:17:23 +0100 |
commit | 5ba3cec231989ba1deb5926f8fdcd8caec169821 (patch) | |
tree | 6f86d8b9d7defea543ab87de67c9f406433365e4 /client/get-entries | |
parent | f806c09af385c6bafded7ff9c7290e10a4d666b9 (diff) |
added client-side get-entries
Diffstat (limited to 'client/get-entries')
-rw-r--r-- | client/get-entries/main.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/client/get-entries/main.go b/client/get-entries/main.go new file mode 100644 index 0000000..6a45707 --- /dev/null +++ b/client/get-entries/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "context" + "flag" + "fmt" + + "net/http" + + "github.com/golang/glog" + "github.com/system-transparency/stfe" + "github.com/system-transparency/stfe/client" +) + +var ( + operators = flag.String("operators", "../../descriptor/stfe.json", "path to json-encoded list of log operators") + logId = flag.String("log_id", "B9oCJk4XIOMXba8dBM5yUj+NLtqTE6xHwbvR9dYkHPM=", "base64-encoded log identifier") + start = flag.Uint64("start", 50, "inclusive start index to download") + end = flag.Uint64("end", 60, "inclusive stop index to download") +) + +func main() { + flag.Parse() + + client, err := client.NewClientFromPath(*logId, "", "", *operators, &http.Client{}, true) + if err != nil { + glog.Fatal(err) + } + + items := make([]*stfe.StItem, 0, *end-*start+1) + i := *start + for len(items) != cap(items) { + rsps, err := client.GetEntries(context.Background(), i, *end) + if err != nil { + glog.Fatal(err) + } + + for _, rsp := range rsps { + var item stfe.StItem + if err := item.Unmarshal(rsp.Leaf); err != nil { + glog.Fatalf("bad StItem: unmarshal failed: %v", err) + } else if item.Format != stfe.StFormatChecksumV1 { + glog.Fatalf("bad StFormat: %v", item.Format) + } + items = append(items, &item) + } + i += uint64(len(rsps)) + } + + for i, item := range items { + glog.V(2).Infof("Index(%d): %s", *start+uint64(i), item) + str, err := item.MarshalB64() + if err != nil { + glog.Fatalf("bad StItem: marshal failed: %v", err) + } + fmt.Printf("Index(%d): %s\n", *start+uint64(i), str) + } + + glog.Flush() +} |