Skip to content

Commit

Permalink
style: rename ErrInsufficientKeys to ErrNoKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
znewman01 committed Apr 19, 2022
1 parent ee3e8ee commit 147d3e2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func (e ErrFileNotFound) Error() string {
return fmt.Sprintf("tuf: file not found %s", e.Path)
}

type ErrInsufficientKeys struct {
type ErrNoKeys struct {
Name string
}

func (e ErrInsufficientKeys) Error() string {
return fmt.Sprintf("tuf: insufficient keys to sign %s", e.Name)
func (e ErrNoKeys) Error() string {
return fmt.Sprintf("tuf: no keys available to sign %s", e.Name)
}

type ErrInsufficientSignatures struct {
Expand Down
9 changes: 4 additions & 5 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ func (r *Repo) setTopLevelMeta(roleFilename string, meta interface{}) error {
// SignPayload signs the given payload using the key(s) associated with role.
//
// It returns the total number of keys used for signing, 0 (along with
// ErrInsufficientKeys) if no keys were found, or -1 (along with an error) in
// error cases.
// ErrNoKeys) if no keys were found, or -1 (along with an error) in error cases.
func (r *Repo) SignPayload(role string, payload *data.Signed) (int, error) {
if !roles.IsTopLevelRole(role) {
return -1, ErrInvalidRole{role, "only signing top-level metadata supported"}
Expand All @@ -524,7 +523,7 @@ func (r *Repo) SignPayload(role string, payload *data.Signed) (int, error) {
return -1, err
}
if len(keys) == 0 {
return 0, ErrInsufficientKeys{role}
return 0, ErrNoKeys{role}
}
for _, k := range keys {
if err = sign.Sign(payload, k); err != nil {
Expand All @@ -542,8 +541,8 @@ func (r *Repo) Sign(roleFilename string) error {

role := strings.TrimSuffix(roleFilename, ".json")
numKeys, err := r.SignPayload(role, signed)
if errors.Is(err, ErrInsufficientKeys{role}) {
return ErrInsufficientKeys{roleFilename}
if errors.Is(err, ErrNoKeys{role}) {
return ErrNoKeys{roleFilename}
} else if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ func (rs *RepoSuite) TestSign(c *C) {

c.Assert(r.Sign("foo.json"), Equals, ErrMissingMetadata{"foo.json"})

// signing with no keys returns ErrInsufficientKeys
c.Assert(r.Sign("root.json"), Equals, ErrInsufficientKeys{"root.json"})
// signing with no keys returns ErrNoKeys
c.Assert(r.Sign("root.json"), Equals, ErrNoKeys{"root.json"})

checkSigIDs := func(keyIDs ...string) {
meta, err := local.GetMeta()
Expand Down Expand Up @@ -1908,7 +1908,7 @@ func (rs *RepoSuite) TestOfflineFlow(c *C) {
_, err = r.SignPayload("badrole", &signed)
c.Assert(err, Equals, ErrInvalidRole{"badrole", "only signing top-level metadata supported"})
_, err = r.SignPayload("targets", &signed)
c.Assert(err, Equals, ErrInsufficientKeys{"targets"})
c.Assert(err, Equals, ErrNoKeys{"targets"})
numKeys, err := r.SignPayload("root", &signed)
c.Assert(err, IsNil)
c.Assert(numKeys, Equals, 1)
Expand Down

0 comments on commit 147d3e2

Please sign in to comment.