Skip to content

Commit

Permalink
Merge pull request #3 from flynn/persist-repository
Browse files Browse the repository at this point in the history
Support creating and modifying repos
  • Loading branch information
lmars committed Dec 31, 2014
2 parents 0a53aeb + 5b9a59e commit 89be826
Show file tree
Hide file tree
Showing 22 changed files with 1,890 additions and 260 deletions.
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

0 comments on commit 89be826

Please sign in to comment.