forked from theupdateframework/go-tuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroles.go
41 lines (33 loc) · 751 Bytes
/
roles.go
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
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 {
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
}