package bind import ( "crypto/sha1" "encoding/hex" "strings" ) // catalogHash returns the unique member label for a catalog zone entry: the // hex-encoded SHA-1 digest of the member zone name in DNS wire format, per the // BIND catalog-zone schema (RFC 9432). func catalogHash(zone string) string { sum := sha1.Sum(wireName(zone)) return hex.EncodeToString(sum[:]) } // wireName encodes a domain name into uncompressed DNS wire format: each label // length-prefixed, terminated by a zero-length root label. Names are lowercased. func wireName(name string) []byte { name = strings.TrimSuffix(strings.ToLower(strings.TrimSpace(name)), ".") var out []byte if name != "" { for _, label := range strings.Split(name, ".") { out = append(out, byte(len(label))) out = append(out, []byte(label)...) } } return append(out, 0) }