From e97a48b90fe0b1dd1bcf058a7bf6ed371ea2b127 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Fri, 27 Oct 2023 15:34:10 -0400 Subject: [PATCH] NEW: rfc1035.go --- pkg/txtutil/rfc1035.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pkg/txtutil/rfc1035.go diff --git a/pkg/txtutil/rfc1035.go b/pkg/txtutil/rfc1035.go new file mode 100644 index 000000000..da4e75dc8 --- /dev/null +++ b/pkg/txtutil/rfc1035.go @@ -0,0 +1,29 @@ +package txtutil + +import ( + "strings" + //"github.com/facebook/dns/dnsrocks/dnsdata/quote" +) + +func RFC1035Quoted(s string) string { + s = strings.ReplaceAll(s, `\`, `\\`) + s = strings.ReplaceAll(s, `"`, `\"`) + return `"` + s + `"` + + //sb := []byte(s) // The string, as []byte + //qb := quote.Bquote(sb) // Quote it. + //q := string(qb[:]) // Convert to string + //return `"` + q + `"` +} + +func RFC1035ChunkedAndQuoted(s string) string { + + parts := ToChunks(s) + var quotedParts []string + + for _, part := range parts { + quotedParts = append(quotedParts, RFC1035Quoted(part)) + } + + return strings.Join(quotedParts, " ") +}