diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-03 11:57:34 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-11-03 11:57:34 +0100 |
commit | 6d3eb5bd4c9f5f3ec4cfdcf18e48ab86a6c247bf (patch) | |
tree | fa985b5910b7afd0803281a39bd06a2fd0a3c2de /client/client.go | |
parent | e5be97bd0132fbdce6eb345441b0ebdeadd96c35 (diff) |
refactored setup() from paths to client package
Diffstat (limited to 'client/client.go')
-rw-r--r-- | client/client.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/client/client.go b/client/client.go index c2d6407..551eff7 100644 --- a/client/client.go +++ b/client/client.go @@ -39,6 +39,37 @@ func NewClient(log *descriptor.Log, client *http.Client, useHttp bool, chain []* } } +// NewClientFromPath loads necessary data from file before creating a new +// client, namely, a pem-encoded certificate chain, a pem-encoded ed25519 +// private key, and a json-encoded list of log operators (see descriptor). +func NewClientFromPath(logId, chainPath, keyPath, operatorsPath string, cli *http.Client, useHttp bool) (*Client, error) { + c, err := stfe.LoadChain(chainPath) + if err != nil { + return nil, err + } + + k, err := stfe.LoadEd25519SigningKey(keyPath) + if err != nil { + return nil, err + } + + ops, err := descriptor.LoadOperators(operatorsPath) + if err != nil { + return nil, err + } + + id, err := base64.StdEncoding.DecodeString(logId) + if err != nil { + return nil, fmt.Errorf("failed decoding log identifier: %v", err) + } + + log, err := descriptor.FindLog(ops, id) + if err != nil { + return nil, err + } + return NewClient(log, cli, useHttp, c, &k), nil +} + // AddEntry creates, signs, and adds a new ChecksumV1 entry to the log func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StItem, error) { leaf, err := stfe.NewChecksumV1(name, checksum).Marshal() |