government / ratify / error.go

@ 5c83a9c6b185121b6a79d1e44755763853b4b6d5 | history


package ratify

import "fmt"

// Ratification error codes. Every ratification failure exits with code 2.
const (
	// ErrMalformed: the file is not a readable certificate chain.
	ErrMalformed = "E-MALFORMED"
	// ErrChain: the certificates do not form one valid path from the
	// anchor down.
	ErrChain = "E-CHAIN"
	// ErrTampered: a signature does not match the bytes it covers.
	ErrTampered = "E-TAMPERED"
	// ErrNotInForce: the check time is before the program takes effect.
	ErrNotInForce = "E-NOT-IN-FORCE"
	// ErrLapsed: the check time is after the program expired.
	ErrLapsed = "E-LAPSED"
	// ErrForeign: the program is ratified by a key other than the pinned
	// one.
	ErrForeign = "E-FOREIGN"
)

type Error struct {
	Code string
	Msg  string
}

func (e *Error) Error() string { return e.Code + ": " + e.Msg }

func errorf(code, format string, args ...any) *Error {
	return &Error{Code: code, Msg: fmt.Sprintf(format, args...)}
}