diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-03-16 00:26:07 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-03-16 00:26:07 +0100 |
commit | 9f7690327f8d74abdd86232546a154ab8408d174 (patch) | |
tree | 0abeaade1c7673579c1b6a76cd4c6c25395555ee /descriptor/descriptor.go | |
parent | e2959d506de6067afe494315c3621b33613b5414 (diff) |
started to re-add basic client commands
Diffstat (limited to 'descriptor/descriptor.go')
-rw-r--r-- | descriptor/descriptor.go | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/descriptor/descriptor.go b/descriptor/descriptor.go deleted file mode 100644 index efe2cf1..0000000 --- a/descriptor/descriptor.go +++ /dev/null @@ -1,58 +0,0 @@ -package descriptor - -import ( - "bytes" - "fmt" - - "encoding/base64" - "encoding/json" - "io/ioutil" - - "github.com/system-transparency/stfe/namespace" -) - -// Operator is an stfe log operator that runs zero or more logs -type Operator struct { - Name string `json:"name"` - Email string `json:"email"` - Logs []*Log `json:"logs"` -} - -// Log is a collection of immutable stfe log parameters -type Log struct { - Id []byte `json:"id"` // Serialized namespace - BaseUrl string `json:"base_url"` // E.g., example.com/st/v1 - // TODO: List of supported namespace types? -} - -func FindLog(ops []Operator, logId []byte) (*Log, error) { - for _, op := range ops { - for _, log := range op.Logs { - if bytes.Equal(logId, log.Id) { - return log, nil - } - } - } - 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 -} - -func (l *Log) Namespace() (*namespace.Namespace, error) { - var n namespace.Namespace - if err := n.Unmarshal(l.Id); err != nil { - return nil, fmt.Errorf("invalid namespace: %v", err) - } - return &n, nil -} |