aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/add-entry/main.go14
-rw-r--r--server/descriptor/descriptor.go15
2 files changed, 19 insertions, 10 deletions
diff --git a/client/add-entry/main.go b/client/add-entry/main.go
index 9047529..60fabf8 100644
--- a/client/add-entry/main.go
+++ b/client/add-entry/main.go
@@ -6,8 +6,6 @@ import (
"fmt"
"encoding/base64"
- "encoding/json"
- "io/ioutil"
"net/http"
"github.com/golang/glog"
@@ -62,21 +60,17 @@ func params() ([]byte, []byte, error) {
func setup() (*client.Client, error) {
c, err := stfe.LoadChain(*chain)
if err != nil {
- return nil, fmt.Errorf("failed loading certificate chain: %v", err)
+ return nil, err
}
k, err := stfe.LoadEd25519SigningKey(*key)
if err != nil {
- return nil, fmt.Errorf("failed loading key: %v", err)
+ return nil, err
}
- blob, err := ioutil.ReadFile(*operators)
+ ops, err := descriptor.LoadOperators(*operators)
if err != nil {
- return nil, fmt.Errorf("failed reading log operators: %v", err)
- }
- var ops []descriptor.Operator
- if err := json.Unmarshal(blob, &ops); err != nil {
- return nil, fmt.Errorf("failed decoding log operators: %v", err)
+ return nil, err
}
id, err := base64.StdEncoding.DecodeString(*logId)
diff --git a/server/descriptor/descriptor.go b/server/descriptor/descriptor.go
index 016d1cc..6e46790 100644
--- a/server/descriptor/descriptor.go
+++ b/server/descriptor/descriptor.go
@@ -6,6 +6,8 @@ import (
"crypto/tls"
"encoding/base64"
+ "encoding/json"
+ "io/ioutil"
)
const (
@@ -40,3 +42,16 @@ func FindLog(ops []Operator, logId []byte) (*Log, error) {
}
return nil, fmt.Errorf("no such log: %s", base64.StdEncoding.EncodeToString(logId))
}
+
+// LoadOperators loads a list of json-encoded log operators from a given path
+func LoadOperators(path string) ([]Operator, error) {
+ blob, err := ioutil.ReadFile(path)
+ if err != nil {
+ return nil, fmt.Errorf("failed reading log operators: %v", err)
+ }
+ var ops []Operator
+ if err := json.Unmarshal(blob, &ops); err != nil {
+ return nil, fmt.Errorf("failed decoding log operators: %v", err)
+ }
+ return ops, nil
+}