format long multi-string dkim txt records for rsa 2048 as a mult-line record, enclosed in ()'s

more easily readable, though still long
This commit is contained in:
Mechiel Lukkien 2023-10-13 09:14:42 +02:00
parent 40040542f6
commit 14d09bb308
No known key found for this signature in database

View File

@ -35,9 +35,14 @@ import (
) )
// TXTStrings returns a TXT record value as one or more quoted strings, taking the max // TXTStrings returns a TXT record value as one or more quoted strings, taking the max
// length of 255 characters for a string into account. // length of 255 characters for a string into account. In case of multiple
// strings, a multi-line record is returned.
func TXTStrings(s string) string { func TXTStrings(s string) string {
r := "" if len(s) <= 255 {
return `"` + s + `"`
}
r := "(\n"
for len(s) > 0 { for len(s) > 0 {
n := len(s) n := len(s)
if n > 255 { if n > 255 {
@ -46,9 +51,10 @@ func TXTStrings(s string) string {
if r != "" { if r != "" {
r += " " r += " "
} }
r += `"` + s[:n] + `"` r += "\t\t\"" + s[:n] + "\"\n"
s = s[n:] s = s[n:]
} }
r += "\t)"
return r return r
} }