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