...

Source file src/github.com/theupdateframework/go-tuf/internal/roles/roles.go

Documentation: github.com/theupdateframework/go-tuf/internal/roles

     1  package roles
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  )
     7  
     8  var TopLevelRoles = map[string]struct{}{
     9  	"root":      {},
    10  	"targets":   {},
    11  	"snapshot":  {},
    12  	"timestamp": {},
    13  }
    14  
    15  func IsTopLevelRole(name string) bool {
    16  	_, ok := TopLevelRoles[name]
    17  	return ok
    18  }
    19  
    20  func IsDelegatedTargetsRole(name string) bool {
    21  	return !IsTopLevelRole(name)
    22  }
    23  
    24  func IsTopLevelManifest(name string) bool {
    25  	if IsVersionedManifest(name) {
    26  		var found bool
    27  		_, name, found = strings.Cut(name, ".")
    28  		if !found {
    29  			panic("expected a versioned manifest of the form x.role.json")
    30  		}
    31  	}
    32  	return IsTopLevelRole(strings.TrimSuffix(name, ".json"))
    33  }
    34  
    35  func IsDelegatedTargetsManifest(name string) bool {
    36  	return !IsTopLevelManifest(name)
    37  }
    38  
    39  func IsVersionedManifest(name string) bool {
    40  	parts := strings.Split(name, ".")
    41  	// Versioned manifests have the form "x.role.json"
    42  	if len(parts) < 3 {
    43  		return false
    44  	}
    45  
    46  	_, err := strconv.Atoi(parts[0])
    47  	return err == nil
    48  }
    49  

View as plain text