Files
narratio/internal/manifest/semantic_fingerprint.go

33 lines
923 B
Go

package manifest
import (
"fmt"
"regexp"
)
var lowercaseSHA256Pattern = regexp.MustCompile(`^[0-9a-f]{64}$`)
// SemanticConfigFingerprint identifies the versioned, result-affecting
// configuration observed by one pipeline stage.
type SemanticConfigFingerprint struct {
Version int `json:"version"`
Digest string `json:"digest"`
}
// Validate checks the durable fingerprint contract.
func (f SemanticConfigFingerprint) Validate() error {
if f.Version <= 0 {
return fmt.Errorf("version must be positive")
}
if !lowercaseSHA256Pattern.MatchString(f.Digest) {
return fmt.Errorf("digest must be a lowercase SHA-256 value")
}
return nil
}
// Equal reports whether two valid fingerprint records identify the same
// semantic configuration contract and payload.
func (f SemanticConfigFingerprint) Equal(other SemanticConfigFingerprint) bool {
return f.Version == other.Version && f.Digest == other.Digest
}