| 1234567891011121314151617181920212223242526 |
- package caphash
- import (
- "crypto/sha256"
- "encoding/hex"
- "google.golang.org/protobuf/proto"
- hthv1 "hth/internal/gen/hth/api/v1"
- )
- // HashCanonicalCapabilities is the unique Capability Hash algorithm.
- // Callers: GetCapabilities, hthctl doctor, hth-capture, Replay, acceptance, manifests.
- // It is NOT profile.ProfileIdentityDigest (a profile-file digest).
- func HashCanonicalCapabilities(c *hthv1.Capabilities) string {
- if c == nil {
- return ""
- }
- cp := proto.Clone(c).(*hthv1.Capabilities)
- cp.CapabilityHash = ""
- b, err := proto.MarshalOptions{Deterministic: true}.Marshal(cp)
- if err != nil {
- return ""
- }
- sum := sha256.Sum256(b)
- return hex.EncodeToString(sum[:])
- }
|