dns_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. package dns
  2. import (
  3. "bytes"
  4. "io"
  5. "strings"
  6. "testing"
  7. )
  8. func namesEqual(a, b Name) bool {
  9. if len(a) != len(b) {
  10. return false
  11. }
  12. for i := 0; i < len(a); i++ {
  13. if !bytes.Equal(a[i], b[i]) {
  14. return false
  15. }
  16. }
  17. return true
  18. }
  19. func anyLabelContainsDot(labels [][]byte) bool {
  20. for _, label := range labels {
  21. if bytes.Contains(label, []byte(".")) {
  22. return true
  23. }
  24. }
  25. return false
  26. }
  27. func TestName(t *testing.T) {
  28. for _, test := range []struct {
  29. labels [][]byte
  30. err error
  31. s string
  32. }{
  33. {[][]byte{}, nil, "."},
  34. {[][]byte{[]byte("test")}, nil, "test"},
  35. {[][]byte{[]byte("a"), []byte("b"), []byte("c")}, nil, "a.b.c"},
  36. {[][]byte{{}}, ErrZeroLengthLabel, ""},
  37. {[][]byte{[]byte("a"), {}, []byte("c")}, ErrZeroLengthLabel, ""},
  38. // 63 octets.
  39. {[][]byte{[]byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE")}, nil,
  40. "0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE"},
  41. // 64 octets.
  42. {[][]byte{[]byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDEF")}, ErrLabelTooLong, ""},
  43. // 64+64+64+62 octets.
  44. {[][]byte{
  45. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE"),
  46. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE"),
  47. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE"),
  48. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABC"),
  49. }, nil,
  50. "0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE.0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE.0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE.0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABC"},
  51. // 64+64+64+63 octets.
  52. {[][]byte{
  53. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE"),
  54. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE"),
  55. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCDE"),
  56. []byte("0123456789abcdef0123456789ABCDEF0123456789abcdef0123456789ABCD"),
  57. }, ErrNameTooLong, ""},
  58. // 127 one-octet labels.
  59. {[][]byte{
  60. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  61. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'}, {'F'},
  62. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  63. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'}, {'F'},
  64. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  65. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'}, {'F'},
  66. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  67. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'},
  68. }, nil,
  69. "0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.0.1.2.3.4.5.6.7.8.9.A.B.C.D.E.F.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.0.1.2.3.4.5.6.7.8.9.A.B.C.D.E.F.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.0.1.2.3.4.5.6.7.8.9.A.B.C.D.E.F.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.0.1.2.3.4.5.6.7.8.9.A.B.C.D.E"},
  70. // 128 one-octet labels.
  71. {[][]byte{
  72. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  73. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'}, {'F'},
  74. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  75. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'}, {'F'},
  76. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  77. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'}, {'F'},
  78. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'},
  79. {'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}, {'8'}, {'9'}, {'A'}, {'B'}, {'C'}, {'D'}, {'E'}, {'F'},
  80. }, ErrNameTooLong, ""},
  81. // Labels may contain any octets, though ones containing dots
  82. // cannot be losslessly roundtripped through a string.
  83. {[][]byte{[]byte("\x00"), []byte("a.b")}, nil, "\x00.a.b"},
  84. } {
  85. // Test that NewName returns proper error codes, and otherwise
  86. // returns an equal slice of labels.
  87. name, err := NewName(test.labels)
  88. if err != test.err || (err == nil && !namesEqual(name, test.labels)) {
  89. t.Errorf("%+q returned (%+q, %v), expected (%+q, %v)",
  90. test.labels, name, err, test.labels, test.err)
  91. continue
  92. }
  93. if test.err != nil {
  94. continue
  95. }
  96. // Test that the string version of the name comes out as
  97. // expected.
  98. s := name.String()
  99. if s != test.s {
  100. t.Errorf("%+q became string %+q, expected %+q", test.labels, s, test.s)
  101. continue
  102. }
  103. // Test that parsing from a string back to a Name results in the
  104. // original slice of labels.
  105. if !anyLabelContainsDot(test.labels) {
  106. name, err := ParseName(s)
  107. if err != nil || !namesEqual(name, test.labels) {
  108. t.Errorf("%+q parsing %+q returned (%+q, %v), expected (%+q, %v)",
  109. test.labels, s, name, err, test.labels, nil)
  110. continue
  111. }
  112. // A trailing dot should be ignored.
  113. if !strings.HasSuffix(s, ".") {
  114. dotName, dotErr := ParseName(s + ".")
  115. if dotErr != err || !namesEqual(dotName, name) {
  116. t.Errorf("%+q parsing %+q returned (%+q, %v), expected (%+q, %v)",
  117. test.labels, s+".", dotName, dotErr, name, err)
  118. continue
  119. }
  120. }
  121. }
  122. }
  123. }
  124. func TestParseName(t *testing.T) {
  125. for _, test := range []struct {
  126. s string
  127. name Name
  128. err error
  129. }{
  130. // This case can't be tested by TestName above because String
  131. // will never produce "" (it produces "." instead).
  132. {"", [][]byte{}, nil},
  133. } {
  134. name, err := ParseName(test.s)
  135. if err != test.err || (err == nil && !namesEqual(name, test.name)) {
  136. t.Errorf("%+q returned (%+q, %v), expected (%+q, %v)",
  137. test.s, name, err, test.name, test.err)
  138. continue
  139. }
  140. }
  141. }
  142. func TestNameTrimSuffix(t *testing.T) {
  143. for _, test := range []struct {
  144. name, suffix string
  145. trimmed string
  146. ok bool
  147. }{
  148. {"", "", ".", true},
  149. {".", ".", ".", true},
  150. {"abc", "", "abc", true},
  151. {"abc", ".", "abc", true},
  152. {"", "abc", ".", false},
  153. {".", "abc", ".", false},
  154. {"example.com", "com", "example", true},
  155. {"example.com", "net", ".", false},
  156. {"example.com", "example.com", ".", true},
  157. {"example.com", "test.com", ".", false},
  158. {"example.com", "xample.com", ".", false},
  159. {"example.com", "example", ".", false},
  160. {"example.com", "COM", "example", true},
  161. {"EXAMPLE.COM", "com", "EXAMPLE", true},
  162. } {
  163. tmp, ok := mustParseName(test.name).TrimSuffix(mustParseName(test.suffix))
  164. trimmed := tmp.String()
  165. if ok != test.ok || trimmed != test.trimmed {
  166. t.Errorf("TrimSuffix %+q %+q returned (%+q, %v), expected (%+q, %v)",
  167. test.name, test.suffix, trimmed, ok, test.trimmed, test.ok)
  168. continue
  169. }
  170. }
  171. }
  172. func TestReadName(t *testing.T) {
  173. // Good tests.
  174. for _, test := range []struct {
  175. start int64
  176. end int64
  177. input string
  178. s string
  179. }{
  180. // Empty name.
  181. {0, 1, "\x00abcd", "."},
  182. // No pointers.
  183. {12, 25, "AAAABBBBCCCC\x07example\x03com\x00", "example.com"},
  184. // Backward pointer.
  185. {25, 31, "AAAABBBBCCCC\x07example\x03com\x00\x03sub\xc0\x0c", "sub.example.com"},
  186. // Forward pointer.
  187. {0, 4, "\x01a\xc0\x04\x03bcd\x00", "a.bcd"},
  188. // Two backwards pointers.
  189. {31, 38, "AAAABBBBCCCC\x07example\x03com\x00\x03sub\xc0\x0c\x04sub2\xc0\x19", "sub2.sub.example.com"},
  190. // Forward then backward pointer.
  191. {25, 31, "AAAABBBBCCCC\x07example\x03com\x00\x03sub\xc0\x1f\x04sub2\xc0\x0c", "sub.sub2.example.com"},
  192. // Overlapping codons.
  193. {0, 4, "\x01a\xc0\x03bcd\x00", "a.bcd"},
  194. // Pointer to empty label.
  195. {0, 10, "\x07example\xc0\x0a\x00", "example"},
  196. {1, 11, "\x00\x07example\xc0\x00", "example"},
  197. // Pointer to pointer to empty label.
  198. {0, 10, "\x07example\xc0\x0a\xc0\x0c\x00", "example"},
  199. {1, 11, "\x00\x07example\xc0\x0c\xc0\x00", "example"},
  200. } {
  201. r := bytes.NewReader([]byte(test.input))
  202. _, err := r.Seek(test.start, io.SeekStart)
  203. if err != nil {
  204. panic(err)
  205. }
  206. name, err := readName(r)
  207. if err != nil {
  208. t.Errorf("%+q returned error %s", test.input, err)
  209. continue
  210. }
  211. s := name.String()
  212. if s != test.s {
  213. t.Errorf("%+q returned %+q, expected %+q", test.input, s, test.s)
  214. continue
  215. }
  216. cur, _ := r.Seek(0, io.SeekCurrent)
  217. if cur != test.end {
  218. t.Errorf("%+q left offset %d, expected %d", test.input, cur, test.end)
  219. continue
  220. }
  221. }
  222. // Bad tests.
  223. for _, test := range []struct {
  224. start int64
  225. input string
  226. err error
  227. }{
  228. {0, "", io.ErrUnexpectedEOF},
  229. // Reserved label type.
  230. {0, "\x80example", ErrReservedLabelType},
  231. // Reserved label type.
  232. {0, "\x40example", ErrReservedLabelType},
  233. // No Terminating empty label.
  234. {0, "\x07example\x03com", io.ErrUnexpectedEOF},
  235. // Pointer past end of buffer.
  236. {0, "\x07example\xc0\xff", io.ErrUnexpectedEOF},
  237. // Pointer to self.
  238. {0, "\x07example\x03com\xc0\x0c", ErrTooManyPointers},
  239. // Pointer to self with intermediate label.
  240. {0, "\x07example\x03com\xc0\x08", ErrTooManyPointers},
  241. // Two pointers that point to each other.
  242. {0, "\xc0\x02\xc0\x00", ErrTooManyPointers},
  243. // Two pointers that point to each other, with intermediate labels.
  244. {0, "\x01a\xc0\x04\x01b\xc0\x00", ErrTooManyPointers},
  245. // EOF while reading label.
  246. {0, "\x0aexample", io.ErrUnexpectedEOF},
  247. // EOF before second byte of pointer.
  248. {0, "\xc0", io.ErrUnexpectedEOF},
  249. {0, "\x07example\xc0", io.ErrUnexpectedEOF},
  250. } {
  251. r := bytes.NewReader([]byte(test.input))
  252. _, err := r.Seek(test.start, io.SeekStart)
  253. if err != nil {
  254. panic(err)
  255. }
  256. name, err := readName(r)
  257. if err == io.EOF {
  258. err = io.ErrUnexpectedEOF
  259. }
  260. if err != test.err {
  261. t.Errorf("%+q returned (%+q, %v), expected %v", test.input, name, err, test.err)
  262. continue
  263. }
  264. }
  265. }
  266. func mustParseName(s string) Name {
  267. name, err := ParseName(s)
  268. if err != nil {
  269. panic(err)
  270. }
  271. return name
  272. }
  273. func questionsEqual(a, b *Question) bool {
  274. if !namesEqual(a.Name, b.Name) {
  275. return false
  276. }
  277. if a.Type != b.Type || a.Class != b.Class {
  278. return false
  279. }
  280. return true
  281. }
  282. func rrsEqual(a, b *RR) bool {
  283. if !namesEqual(a.Name, b.Name) {
  284. return false
  285. }
  286. if a.Type != b.Type || a.Class != b.Class || a.TTL != b.TTL {
  287. return false
  288. }
  289. if !bytes.Equal(a.Data, b.Data) {
  290. return false
  291. }
  292. return true
  293. }
  294. func messagesEqual(a, b *Message) bool {
  295. if a.ID != b.ID || a.Flags != b.Flags {
  296. return false
  297. }
  298. if len(a.Question) != len(b.Question) {
  299. return false
  300. }
  301. for i := 0; i < len(a.Question); i++ {
  302. if !questionsEqual(&a.Question[i], &b.Question[i]) {
  303. return false
  304. }
  305. }
  306. for _, rec := range []struct{ rrA, rrB []RR }{
  307. {a.Answer, b.Answer},
  308. {a.Authority, b.Authority},
  309. {a.Additional, b.Additional},
  310. } {
  311. if len(rec.rrA) != len(rec.rrB) {
  312. return false
  313. }
  314. for i := 0; i < len(rec.rrA); i++ {
  315. if !rrsEqual(&rec.rrA[i], &rec.rrB[i]) {
  316. return false
  317. }
  318. }
  319. }
  320. return true
  321. }
  322. func TestMessageFromWireFormat(t *testing.T) {
  323. for _, test := range []struct {
  324. buf string
  325. expected Message
  326. err error
  327. }{
  328. {
  329. "\x12\x34",
  330. Message{},
  331. io.ErrUnexpectedEOF,
  332. },
  333. {
  334. "\x12\x34\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x07example\x03com\x00\x00\x01\x00\x01",
  335. Message{
  336. ID: 0x1234,
  337. Flags: 0x0100,
  338. Question: []Question{
  339. {
  340. Name: mustParseName("www.example.com"),
  341. Type: 1,
  342. Class: 1,
  343. },
  344. },
  345. Answer: []RR{},
  346. Authority: []RR{},
  347. Additional: []RR{},
  348. },
  349. nil,
  350. },
  351. {
  352. "\x12\x34\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03www\x07example\x03com\x00\x00\x01\x00\x01X",
  353. Message{},
  354. ErrTrailingBytes,
  355. },
  356. {
  357. "\x12\x34\x81\x80\x00\x01\x00\x01\x00\x00\x00\x00\x03www\x07example\x03com\x00\x00\x01\x00\x01\x03www\x07example\x03com\x00\x00\x01\x00\x01\x00\x00\x00\x80\x00\x04\xc0\x00\x02\x01",
  358. Message{
  359. ID: 0x1234,
  360. Flags: 0x8180,
  361. Question: []Question{
  362. {
  363. Name: mustParseName("www.example.com"),
  364. Type: 1,
  365. Class: 1,
  366. },
  367. },
  368. Answer: []RR{
  369. {
  370. Name: mustParseName("www.example.com"),
  371. Type: 1,
  372. Class: 1,
  373. TTL: 128,
  374. Data: []byte{192, 0, 2, 1},
  375. },
  376. },
  377. Authority: []RR{},
  378. Additional: []RR{},
  379. },
  380. nil,
  381. },
  382. } {
  383. message, err := MessageFromWireFormat([]byte(test.buf))
  384. if err != test.err || (err == nil && !messagesEqual(&message, &test.expected)) {
  385. t.Errorf("%+q\nreturned (%+v, %v)\nexpected (%+v, %v)",
  386. test.buf, message, err, test.expected, test.err)
  387. continue
  388. }
  389. }
  390. }
  391. func TestMessageWireFormatRoundTrip(t *testing.T) {
  392. for _, message := range []Message{
  393. {
  394. ID: 0x1234,
  395. Flags: 0x0100,
  396. Question: []Question{
  397. {
  398. Name: mustParseName("www.example.com"),
  399. Type: 1,
  400. Class: 1,
  401. },
  402. {
  403. Name: mustParseName("www2.example.com"),
  404. Type: 2,
  405. Class: 2,
  406. },
  407. },
  408. Answer: []RR{
  409. {
  410. Name: mustParseName("abc"),
  411. Type: 2,
  412. Class: 3,
  413. TTL: 0xffffffff,
  414. Data: []byte{1},
  415. },
  416. {
  417. Name: mustParseName("xyz"),
  418. Type: 2,
  419. Class: 3,
  420. TTL: 255,
  421. Data: []byte{},
  422. },
  423. },
  424. Authority: []RR{
  425. {
  426. Name: mustParseName("."),
  427. Type: 65535,
  428. Class: 65535,
  429. TTL: 0,
  430. Data: []byte("XXXXXXXXXXXXXXXXXXX"),
  431. },
  432. },
  433. Additional: []RR{},
  434. },
  435. } {
  436. buf, err := message.WireFormat()
  437. if err != nil {
  438. t.Errorf("%+v cannot make wire format: %v", message, err)
  439. continue
  440. }
  441. message2, err := MessageFromWireFormat(buf)
  442. if err != nil {
  443. t.Errorf("%+q cannot parse wire format: %v", buf, err)
  444. continue
  445. }
  446. if !messagesEqual(&message, &message2) {
  447. t.Errorf("messages unequal\nbefore: %+v\n after: %+v", message, message2)
  448. continue
  449. }
  450. }
  451. }
  452. func TestDecodeRDataTXT(t *testing.T) {
  453. for _, test := range []struct {
  454. p []byte
  455. decoded []byte
  456. err error
  457. }{
  458. {[]byte{}, nil, io.ErrUnexpectedEOF},
  459. {[]byte("\x00"), []byte{}, nil},
  460. {[]byte("\x01"), nil, io.ErrUnexpectedEOF},
  461. } {
  462. decoded, err := DecodeRDataTXT(test.p)
  463. if err != test.err || (err == nil && !bytes.Equal(decoded, test.decoded)) {
  464. t.Errorf("%+q\nreturned (%+q, %v)\nexpected (%+q, %v)",
  465. test.p, decoded, err, test.decoded, test.err)
  466. continue
  467. }
  468. }
  469. }
  470. func TestEncodeRDataTXT(t *testing.T) {
  471. // Encoding 0 bytes needs to return at least a single length octet of
  472. // zero, not an empty slice.
  473. p := make([]byte, 0)
  474. encoded := EncodeRDataTXT(p)
  475. if len(encoded) < 0 {
  476. t.Errorf("EncodeRDataTXT(%v) returned %v", p, encoded)
  477. }
  478. // 255 bytes should be able to be encoded into 256 bytes.
  479. p = make([]byte, 255)
  480. encoded = EncodeRDataTXT(p)
  481. if len(encoded) > 256 {
  482. t.Errorf("EncodeRDataTXT(%d bytes) returned %d bytes", len(p), len(encoded))
  483. }
  484. }
  485. func TestRDataTXTRoundTrip(t *testing.T) {
  486. for _, p := range [][]byte{
  487. {},
  488. []byte("\x00"),
  489. {
  490. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  491. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  492. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  493. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  494. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  495. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  496. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  497. 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
  498. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  499. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
  500. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
  501. 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  502. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
  503. 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
  504. 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  505. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
  506. },
  507. } {
  508. rdata := EncodeRDataTXT(p)
  509. decoded, err := DecodeRDataTXT(rdata)
  510. if err != nil || !bytes.Equal(decoded, p) {
  511. t.Errorf("%+q returned (%+q, %v)", p, decoded, err)
  512. continue
  513. }
  514. }
  515. }