Files
core/trust/home.go
T

37 lines
1.1 KiB
Go
Raw Normal View History

package trust
import (
"yetano.dev/yetano/core"
"yetano.dev/yetano/core/paths"
)
// Home is the directory of a host's trust state: yet's data directory
// (core/paths' DataDir for "yet" in scope), which holds
// trust-policy.json (DefaultPolicyPath) and known-keys.json
// (DefaultKnownKeysPath). Every program that checks signatures reads
// these, so a host has one trust policy and one set of pinned keys,
// whichever program pulled first.
func Home(scope core.Scope) (string, error) {
r, err := paths.New(core.Application{Name: "yet", Kind: core.CLI, Scope: scope})
if err != nil {
return "", err
}
return r.DataDir()
}
// Curated reports whether a rule of p covers the namespace of name (any
// type): only its allowed keys satisfy such a namespace (Evaluate).
func (p Policy) Curated(name string) bool {
for _, rule := range p.Rules {
if matchesNamespace(rule.Namespace, name) {
return true
}
}
return false
}
// Pinned reports whether keys accept a key for repoKey: its content has
// been seen signed (Reconcile), or a key was added for it.
func (keys KnownKeys) Pinned(repoKey string) bool {
return len(keys[repoKey]) > 0
}