Skip to content

Commit

Permalink
[Delegations prereq] Make snapshot manifest list dynamic
Browse files Browse the repository at this point in the history
Splitting up #175
  • Loading branch information
ethan-lowman-dd committed Dec 10, 2021
1 parent 84c43e5 commit 8ef2e3d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ var topLevelMetadata = []string{
"timestamp.json",
}

var snapshotMetadata = []string{
"root.json",
"targets.json",
}

// TargetsWalkFunc is a function of a target path name and a target payload used to
// execute some function on each staged target file. For example, it may normalize path
// names and generate target file metadata with additional custom metadata.
Expand Down Expand Up @@ -812,6 +807,12 @@ func (r *Repo) Snapshot() error {
return r.SnapshotWithExpires(data.DefaultExpires("snapshot"))
}

func (r *Repo) snapshotManifests() []string {
// Note: root pinning is not supported in Spec 1.0.19.
// root.json might need to be removed.
return []string{"root.json", "targets.json"}
}

func (r *Repo) SnapshotWithExpires(expires time.Time) error {
if !validExpires(expires) {
return ErrInvalidExpires{expires}
Expand All @@ -826,12 +827,12 @@ func (r *Repo) SnapshotWithExpires(expires time.Time) error {
return err
}

for _, name := range snapshotMetadata {
if err := r.verifySignature(name, db); err != nil {
for _, manifestName := range r.snapshotManifests() {
if err := r.verifySignature(manifestName, db); err != nil {
return err
}
var err error
snapshot.Meta[name], err = r.snapshotFileMeta(name)
snapshot.Meta[manifestName], err = r.snapshotFileMeta(manifestName)
if err != nil {
return err
}
Expand Down Expand Up @@ -958,7 +959,7 @@ func (r *Repo) Commit() error {
if err != nil {
return err
}
for _, name := range snapshotMetadata {
for _, name := range r.snapshotManifests() {
expected, ok := snapshot.Meta[name]
if !ok {
return fmt.Errorf("tuf: snapshot.json missing hash for %s", name)
Expand Down

0 comments on commit 8ef2e3d

Please sign in to comment.