From 9971d4f33b97be51d9bff73b6fd1c30eeb12f5b6 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 07:23:39 +0000 Subject: [PATCH] Remove DNS hex init helper --- pkg/dns/common.go | 23 ++++++----------------- pkg/dns/common_test.go | 12 ++++++------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/pkg/dns/common.go b/pkg/dns/common.go index e7dba15..21e15ba 100644 --- a/pkg/dns/common.go +++ b/pkg/dns/common.go @@ -2,8 +2,6 @@ package dns -import "encoding/hex" - // DUMMY mirrors the JS zero-length buffer export used by the DNS reference // helpers. var DUMMY = []byte{} @@ -23,12 +21,12 @@ func GetDefaultTTL() int { // Type map bitmaps mirror the JS DNS reference constants. var ( - TYPE_MAP_ROOT = mustHex("000722000000000380") - TYPE_MAP_EMPTY = mustHex("0006000000000003") - TYPE_MAP_NS = mustHex("0006200000000003") - TYPE_MAP_TXT = mustHex("0006000080000003") - TYPE_MAP_A = mustHex("0006400000000003") - TYPE_MAP_AAAA = mustHex("0006000000080003") + TYPE_MAP_ROOT = []byte{0x00, 0x07, 0x22, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80} + TYPE_MAP_EMPTY = []byte{0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03} + TYPE_MAP_NS = []byte{0x00, 0x06, 0x20, 0x00, 0x00, 0x00, 0x00, 0x03} + TYPE_MAP_TXT = []byte{0x00, 0x06, 0x00, 0x00, 0x80, 0x00, 0x00, 0x03} + TYPE_MAP_A = []byte{0x00, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x03} + TYPE_MAP_AAAA = []byte{0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03} ) // GetTypeMapRoot returns the reference type bitmap for the root zone. @@ -112,12 +110,3 @@ func GetHSTypes() map[string]HSType { func GetHSTypesByVal() map[HSType]string { return HSTypesByVal } - -func mustHex(s string) []byte { - buf, err := hex.DecodeString(s) - if err != nil { - panic(err) - } - - return buf -} diff --git a/pkg/dns/common_test.go b/pkg/dns/common_test.go index 0a77144..eb4793c 100644 --- a/pkg/dns/common_test.go +++ b/pkg/dns/common_test.go @@ -25,12 +25,12 @@ func TestCommonConstants(t *testing.T) { got []byte want []byte }{ - {name: "TYPE_MAP_ROOT", got: TYPE_MAP_ROOT, want: mustHex("000722000000000380")}, - {name: "TYPE_MAP_EMPTY", got: TYPE_MAP_EMPTY, want: mustHex("0006000000000003")}, - {name: "TYPE_MAP_NS", got: TYPE_MAP_NS, want: mustHex("0006200000000003")}, - {name: "TYPE_MAP_TXT", got: TYPE_MAP_TXT, want: mustHex("0006000080000003")}, - {name: "TYPE_MAP_A", got: TYPE_MAP_A, want: mustHex("0006400000000003")}, - {name: "TYPE_MAP_AAAA", got: TYPE_MAP_AAAA, want: mustHex("0006000000080003")}, + {name: "TYPE_MAP_ROOT", got: TYPE_MAP_ROOT, want: []byte{0x00, 0x07, 0x22, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80}}, + {name: "TYPE_MAP_EMPTY", got: TYPE_MAP_EMPTY, want: []byte{0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}, + {name: "TYPE_MAP_NS", got: TYPE_MAP_NS, want: []byte{0x00, 0x06, 0x20, 0x00, 0x00, 0x00, 0x00, 0x03}}, + {name: "TYPE_MAP_TXT", got: TYPE_MAP_TXT, want: []byte{0x00, 0x06, 0x00, 0x00, 0x80, 0x00, 0x00, 0x03}}, + {name: "TYPE_MAP_A", got: TYPE_MAP_A, want: []byte{0x00, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x03}}, + {name: "TYPE_MAP_AAAA", got: TYPE_MAP_AAAA, want: []byte{0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x03}}, } for _, tc := range cases {