aboutsummaryrefslogtreecommitdiff
path: root/client/flag.go
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/flag.go
parent9f7690327f8d74abdd86232546a154ab8408d174 (diff)
added additional basic client commands
Diffstat (limited to 'client/flag.go')
-rw-r--r--client/flag.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/client/flag.go b/client/flag.go
new file mode 100644
index 0000000..1e5e395
--- /dev/null
+++ b/client/flag.go
@@ -0,0 +1,55 @@
+package client
+
+import (
+ "flag"
+ "fmt"
+
+ "crypto/ed25519"
+ "encoding/base64"
+ "net/http"
+
+ "github.com/system-transparency/stfe/types"
+)
+
+var (
+ logId = flag.String("log_id", "AAEsY0retj4wa3S2fjsOCJCTVHab7ipEiMdqtW1uJ6Jvmg==", "base64-encoded log identifier")
+ logUrl = flag.String("log_url", "http://localhost:6965/st/v1", "log url")
+ ed25519_sk = flag.String("ed25519_sk", "d8i6nud7PS1vdO0sIk9H+W0nyxbM63Y3/mSeUPRafWaFh8iH8QXvL7NaAYn2RZPrnEey+FdpmTYXE47OFO70eg==", "base64-encoded ed25519 signing key")
+)
+
+func NewClientFromFlags() (*Client, error) {
+ var err error
+ c := Client{
+ HttpClient: &http.Client{},
+ }
+ if len(*ed25519_sk) != 0 {
+ sk, err := base64.StdEncoding.DecodeString(*ed25519_sk)
+ if err != nil {
+ return nil, fmt.Errorf("ed25519_sk: DecodeString: %v", err)
+ }
+ c.Signer = ed25519.PrivateKey(sk)
+ c.Namespace, err = types.NewNamespaceEd25519V1([]byte(ed25519.PrivateKey(sk).Public().(ed25519.PublicKey)))
+ if err != nil {
+ return nil, fmt.Errorf("ed25519_vk: NewNamespaceEd25519V1: %v", err)
+ }
+ }
+ if c.Log, err = NewDescriptorFromFlags(); err != nil {
+ return nil, fmt.Errorf("NewDescriptorFromFlags: %v", err)
+ }
+ return &c, nil
+}
+
+func NewDescriptorFromFlags() (*Descriptor, error) {
+ b, err := base64.StdEncoding.DecodeString(*logId)
+ if err != nil {
+ return nil, fmt.Errorf("LogId: DecodeString: %v", err)
+ }
+ var namespace types.Namespace
+ if err := types.Unmarshal(b, &namespace); err != nil {
+ return nil, fmt.Errorf("LogId: Unmarshal: %v", err)
+ }
+ return &Descriptor{
+ Namespace: &namespace,
+ Url: *logUrl,
+ }, nil
+}