2021-09-19 12:00:00 +00:00
|
|
|
// Copyright (c) 2019, Drone IO Inc.
|
|
|
|
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
|
2019-02-10 19:00:16 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Signature is a resource that provides an hmac
|
|
|
|
// signature of combined resources. This signature
|
|
|
|
// can be used to validate authenticity and prevent
|
|
|
|
// tampering.
|
|
|
|
Signature struct {
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
Kind string `json:"kind"`
|
|
|
|
Hmac string `json:"hmac"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-02-08 09:14:20 +00:00
|
|
|
var ErrInvalidSignature = errors.New("yaml: invalid signature due to missing hash")
|
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
// GetVersion returns the resource version.
|
|
|
|
func (s *Signature) GetVersion() string { return s.Version }
|
|
|
|
|
|
|
|
// GetKind returns the resource kind.
|
|
|
|
func (s *Signature) GetKind() string { return s.Kind }
|
|
|
|
|
|
|
|
// Validate returns an error if the signature is invalid.
|
|
|
|
func (s Signature) Validate() error {
|
|
|
|
if s.Hmac == "" {
|
2023-02-08 09:14:20 +00:00
|
|
|
return ErrInvalidSignature
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
2023-02-08 09:14:20 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
return nil
|
|
|
|
}
|