aboutsummaryrefslogtreecommitdiff
path: root/client/cmd/add-entry
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-03-16 00:26:07 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-03-16 00:26:07 +0100
commit9f7690327f8d74abdd86232546a154ab8408d174 (patch)
tree0abeaade1c7673579c1b6a76cd4c6c25395555ee /client/cmd/add-entry
parente2959d506de6067afe494315c3621b33613b5414 (diff)
started to re-add basic client commands
Diffstat (limited to 'client/cmd/add-entry')
-rw-r--r--client/cmd/add-entry/main.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/client/cmd/add-entry/main.go b/client/cmd/add-entry/main.go
new file mode 100644
index 0000000..03844fa
--- /dev/null
+++ b/client/cmd/add-entry/main.go
@@ -0,0 +1,52 @@
+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 (
+ identifier = flag.String("identifier", "foobar-1.2.3", "checksum identifier")
+ checksum = flag.String("checksum", "50e7967bce266a506f8f614bb5096beba580d205046b918f47d23b2ec626d75e", "base64-encoded checksum")
+)
+
+func main() {
+ flag.Parse()
+ defer glog.Flush()
+
+ client, err := client.NewClientFromFlags()
+ if err != nil {
+ glog.Errorf("NewClientFromFlags: %v", err)
+ return
+ }
+ data, err := NewChecksumV1FromFlags()
+ if err != nil {
+ glog.Errorf("NewChecksumV1FromFlags: %v", err)
+ return
+ }
+ leafHash, err := client.AddEntry(context.Background(), data)
+ if err != nil {
+ glog.Errorf("AddEntry: %v", err)
+ return
+ }
+ fmt.Println("leaf hash:", base64.StdEncoding.EncodeToString(leafHash))
+}
+
+func NewChecksumV1FromFlags() (*types.ChecksumV1, error) {
+ var err error
+ data := types.ChecksumV1{
+ Identifier: []byte(*identifier),
+ }
+ data.Checksum, err = base64.StdEncoding.DecodeString(*checksum)
+ if err != nil {
+ return nil, fmt.Errorf("entry_checksum: DecodeString: %v", err)
+ }
+ return &data, nil
+}