Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating and modifying repos #3

Merged
merged 9 commits into from
Dec 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
459 changes: 459 additions & 0 deletions README.md

Large diffs are not rendered by default.

237 changes: 0 additions & 237 deletions client.go

This file was deleted.

95 changes: 95 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package client

import (
"errors"
"io"
"time"

"github.com/flynn/go-tuf"
"github.com/flynn/go-tuf/data"
)

var (
ErrNotFound = errors.New("tuf: file not found")
ErrLatest = errors.New("tuf: the current version is the latest")
ErrWrongSize = errors.New("tuf: unexpected file size")
ErrNoRootKeys = errors.New("tuf: no root keys found in local meta store")
)

type RemoteStore interface {
Get(name string, size int64) (io.ReadCloser, error)
}

type Client struct {
repo *tuf.Repo
remote RemoteStore
}

// TODO: Client needs root keys
func NewClient(local tuf.LocalStore, remote RemoteStore) (*Client, error) {
repo, err := tuf.NewRepo(local)
if err != nil {
return nil, err
}
return &Client{repo, remote}, nil
}

func (c *Client) Update() error {
// check for root keys

// if no meta, get root.json
// if meta, get timestamp.json
// if new, get snapshot.json
// if new root.json, restart
// if new targets.json update
// fully check all signatures

/*
If at any point in the following process there is a problem (e.g., only expired
metadata can be retrieved), the Root file is downloaded and the process starts
over. Optionally, the software update system using the framework can decide how
to proceed rather than automatically downloading a new Root file.
TUF downloads and verifies timestamp.json.
If timestamp.json indicates that snapshot.json has changed, TUF downloads
and verifies snapshot.json.
TUF determines which metadata files listed in snapshot.json differ from
those described in the last snapshot.json that TUF has seen. If root.json
has changed, the update process starts over using the new root.json.
TUF provides the software update system with a list of available files
according to targets.json.
*/

return nil
}

func (c *Client) Expires() time.Time {
return time.Time{}
}

func (c *Client) Version() int {
return 0
}

func (c *Client) Files() data.Files {
return nil
}

type Destination interface {
io.Writer
Size() (int, error)
Delete() error
}

func (c *Client) Download(name string, dest Destination) error {
/*
The software update system instructs TUF to download a specific target file.
TUF downloads and verifies the file and then makes the file available to the
software update system.
*/
return nil
}
6 changes: 4 additions & 2 deletions client_test.go → client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tuf
package client

import (
"io"
"testing"

"github.com/flynn/go-tuf"
. "gopkg.in/check.v1"
)

Expand Down Expand Up @@ -34,6 +35,7 @@ type FakeFile struct {

func (ClientSuite) TestFirstUpdate(c *C) {
remote := make(FakeRemoteStore)
r := NewRepo(MemoryLocalStore(), remote)
r, err := NewClient(tuf.MemoryStore(nil, nil), remote)
c.Assert(err, IsNil)
_ = r
}
Loading