summaryrefslogtreecommitdiff
path: root/lib/dns/rdata_https.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-03-25 13:42:20 +0700
committerShulhan <ms@kilabit.info>2024-03-26 23:07:02 +0700
commit71eaafc5119b178be61abf6ae7b8a2fbcdfacc44 (patch)
tree04d227d6f7d01bce8a082a98216a6f271145ef7d /lib/dns/rdata_https.go
parentaba79f63972515f3849f35641ef7de3f93f812e2 (diff)
downloadpakakeh.go-71eaafc5119b178be61abf6ae7b8a2fbcdfacc44.tar.xz
lib/dns: implements RFC 9460 for SVCB RR and HTTPS RR
Diffstat (limited to 'lib/dns/rdata_https.go')
-rw-r--r--lib/dns/rdata_https.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/dns/rdata_https.go b/lib/dns/rdata_https.go
new file mode 100644
index 00000000..dae748e4
--- /dev/null
+++ b/lib/dns/rdata_https.go
@@ -0,0 +1,48 @@
+// Copyright 2024, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package dns
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+)
+
+// RDataHTTPS the resource record for type 65 [HTTPS RR].
+//
+// [HTTPS RR]: https://datatracker.ietf.org/doc/html/rfc9460
+type RDataHTTPS struct {
+ RDataSVCB
+}
+
+// WriteTo write the SVCB record as zone format to out.
+func (https *RDataHTTPS) WriteTo(out io.Writer) (_ int64, err error) {
+ var buf bytes.Buffer
+
+ fmt.Fprintf(&buf, `HTTPS %d %s`, https.Priority, https.TargetName)
+
+ var (
+ keys = https.keys()
+
+ keyid int
+ )
+ for _, keyid = range keys {
+ buf.WriteByte(' ')
+
+ if keyid == svcbKeyIDNoDefaultALPN {
+ buf.WriteString(svcbKeyNameNoDefaultALPN)
+ continue
+ }
+
+ https.writeParam(&buf, keyid)
+ }
+ buf.WriteByte('\n')
+
+ var n int
+
+ n, err = out.Write(buf.Bytes())
+
+ return int64(n), err
+}