1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <inttypes.h>
5 #include <ctype.h>
6
7 #include "test-common.h"
8
9 #include <libmy/ubuf.h>
10 #include <wdns.h>
11
12 #define NAME "test-str_to_rdata"
13
14 struct test {
15 char * input;
16 uint16_t rrtype;
17 uint16_t rrclass;
18 const void *expected;
19 size_t expected_len;
20 wdns_res expected_res;
21 };
22
23 static const struct test tdata[] = {
24 {
25 .rrtype = WDNS_TYPE_TLSA,
26 .rrclass = WDNS_CLASS_IN,
27 .input =
28 "0 0 1 "
29 "d2abde240d7cd3ee6b4b28c54df034b9"
30 "7983a1d16e8a410e4561cb106618e971",
31 .expected =
32 "\x00" "\x00" "\x01"
33 "\xd2\xab\xde\x24\x0d\x7c\xd3\xee\x6b\x4b\x28\xc5\x4d\xf0\x34\xb9"
34 "\x79\x83\xa1\xd1\x6e\x8a\x41\x0e\x45\x61\xcb\x10\x66\x18\xe9\x71",
35 .expected_len = 1 + 1 + 1 + 32,
36 .expected_res = wdns_res_success,
37 },
38
39 {
40 .rrtype = WDNS_TYPE_DNSKEY,
41 .rrclass = WDNS_CLASS_IN,
42 .input =
43 "256 3 5 "
44 "AQPSKmynfzW4kyBv015MUG2DeIQ3 "
45 "Cbl+BBZH4b/0PY1kxkmvHjcZc8no "
46 "kfzj31GajIQKY+5CptLr3buXA10h "
47 "WqTkF7H6RfoRqXQeogmMHfpftf6z "
48 "Mv1LyBUgia7za6ZEzOJBOztyvhjL "
49 "742iU/TpPSEDhm2SNKLijfUppn1U "
50 "aNvv4w==",
51 .expected =
52 "\x01\x00" "\x03" "\x05"
53 "\x01\x03\xd2\x2a\x6c\xa7\x7f\x35\xb8\x93\x20\x6f\xd3\x5e\x4c\x50"
54 "\x6d\x83\x78\x84\x37\x09\xb9\x7e\x04\x16\x47\xe1\xbf\xf4\x3d\x8d"
55 "\x64\xc6\x49\xaf\x1e\x37\x19\x73\xc9\xe8\x91\xfc\xe3\xdf\x51\x9a"
56 "\x8c\x84\x0a\x63\xee\x42\xa6\xd2\xeb\xdd\xbb\x97\x03\x5d\x21\x5a"
57 "\xa4\xe4\x17\xb1\xfa\x45\xfa\x11\xa9\x74\x1e\xa2\x09\x8c\x1d\xfa"
58 "\x5f\xb5\xfe\xb3\x32\xfd\x4b\xc8\x15\x20\x89\xae\xf3\x6b\xa6\x44"
59 "\xcc\xe2\x41\x3b\x3b\x72\xbe\x18\xcb\xef\x8d\xa2\x53\xf4\xe9\x3d"
60 "\x21\x03\x86\x6d\x92\x34\xa2\xe2\x8d\xf5\x29\xa6\x7d\x54\x68\xdb"
61 "\xef\xe3",
62 .expected_len = 2 + 1 + 1 + 130,
63 .expected_res = wdns_res_success,
64 },
65
66 {
67 .rrtype = WDNS_TYPE_CDNSKEY,
68 .rrclass = WDNS_CLASS_IN,
69 .input =
70 "256 3 5 "
71 "AQPSKmynfzW4kyBv015MUG2DeIQ3 "
72 "Cbl+BBZH4b/0PY1kxkmvHjcZc8no "
73 "kfzj31GajIQKY+5CptLr3buXA10h "
74 "WqTkF7H6RfoRqXQeogmMHfpftf6z "
75 "Mv1LyBUgia7za6ZEzOJBOztyvhjL "
76 "742iU/TpPSEDhm2SNKLijfUppn1U "
77 "aNvv4w==",
78 .expected =
79 "\x01\x00" "\x03" "\x05"
80 "\x01\x03\xd2\x2a\x6c\xa7\x7f\x35\xb8\x93\x20\x6f\xd3\x5e\x4c\x50"
81 "\x6d\x83\x78\x84\x37\x09\xb9\x7e\x04\x16\x47\xe1\xbf\xf4\x3d\x8d"
82 "\x64\xc6\x49\xaf\x1e\x37\x19\x73\xc9\xe8\x91\xfc\xe3\xdf\x51\x9a"
83 "\x8c\x84\x0a\x63\xee\x42\xa6\xd2\xeb\xdd\xbb\x97\x03\x5d\x21\x5a"
84 "\xa4\xe4\x17\xb1\xfa\x45\xfa\x11\xa9\x74\x1e\xa2\x09\x8c\x1d\xfa"
85 "\x5f\xb5\xfe\xb3\x32\xfd\x4b\xc8\x15\x20\x89\xae\xf3\x6b\xa6\x44"
86 "\xcc\xe2\x41\x3b\x3b\x72\xbe\x18\xcb\xef\x8d\xa2\x53\xf4\xe9\x3d"
87 "\x21\x03\x86\x6d\x92\x34\xa2\xe2\x8d\xf5\x29\xa6\x7d\x54\x68\xdb"
88 "\xef\xe3",
89 .expected_len = 2 + 1 + 1 + 130,
90 .expected_res = wdns_res_success,
91 },
92
93 {
94 .rrtype = WDNS_TYPE_DS,
95 .rrclass = WDNS_CLASS_IN,
96 .input = "60485 5 1 2BB183AF5F22588179A53B0A98631FAD1A292118",
97 .expected =
98 "\xec\x45" "\x05" "\x01"
99 "\x2b\xb1\x83\xaf\x5f\x22\x58\x81\x79\xa5\x3b\x0a\x98\x63\x1f\xad\x1a\x29\x21\x18",
100 .expected_len = 2 + 1 + 1 + 20,
101 .expected_res = wdns_res_success,
102 },
103
104 {
105 .rrtype = WDNS_TYPE_CDS,
106 .rrclass = WDNS_CLASS_IN,
107 .input = "60485 5 1 2BB183AF5F22588179A53B0A98631FAD1A292118",
108 .expected =
109 "\xec\x45" "\x05" "\x01"
110 "\x2b\xb1\x83\xaf\x5f\x22\x58\x81\x79\xa5\x3b\x0a\x98\x63\x1f\xad\x1a\x29\x21\x18",
111 .expected_len = 2 + 1 + 1 + 20,
112 .expected_res = wdns_res_success,
113 },
114
115 {
116 .rrtype = WDNS_TYPE_OPENPGPKEY,
117 .rrclass = WDNS_CLASS_IN,
118 .input = "AQIDBAUGBwg=",
119 .expected = "\x01\x02\x03\x04\x05\x06\x07\x08",
120 .expected_len = 8,
121 .expected_res = wdns_res_success,
122 },
123
124 {
125 .rrtype = WDNS_TYPE_CSYNC,
126 .rrclass = WDNS_CLASS_IN,
127 .input = "66 3 A NS AAAA",
128 .expected =
129 "\x00\x00\x00\x42"
130 "\x00\x03"
131 "\x00\x04\x60\x00\x00\x08",
132 .expected_len = 4 + 2 + 6,
133 .expected_res = wdns_res_success,
134 },
135
136 {
137 .rrtype = WDNS_TYPE_EUI48,
138 .rrclass = WDNS_CLASS_IN,
139 .input = "AB-CD-EF-01-02-03",
140 .expected = "\xAB\xCD\xEF\x01\x02\x03",
141 .expected_len = 6,
142 .expected_res = wdns_res_success,
143 },
144
145 {
146 .rrtype = WDNS_TYPE_EUI64,
147 .rrclass = WDNS_CLASS_IN,
148 .input = "AB-CD-EF-01-02-03-04-05",
149 .expected = "\xAB\xCD\xEF\x01\x02\x03\x04\x05",
150 .expected_len = 8,
151 .expected_res = wdns_res_success,
152 },
153
154 {
155 .rrtype = WDNS_TYPE_URI,
156 .rrclass = WDNS_CLASS_IN,
157 .input = "10 1 \"ftp://ftp1.example.com/public\"",
158 .expected =
159 "\x00\x0a"
160 "\x00\x01"
161 "ftp://ftp1.example.com/public",
162 .expected_len = 2 + 2 + 29,
163 .expected_res = wdns_res_success,
164 },
165
166 {
167 .rrtype = WDNS_TYPE_URI,
168 .rrclass = WDNS_CLASS_IN,
169 .input = "10 1 \"ftp://ftp1.ex\\097mple.com/public\"",
170 .expected =
171 "\x00\x0a"
172 "\x00\x01"
173 "ftp://ftp1.example.com/public",
174 .expected_len = 2 + 2 + 29,
175 .expected_res = wdns_res_success,
176 },
177
178 { "fsi.io.", WDNS_TYPE_CNAME, WDNS_CLASS_IN, "\x03""fsi\x02io\x00", 8, wdns_res_success },
179 { "fsi.io", WDNS_TYPE_CNAME, WDNS_CLASS_IN, "\x03""fsi\x02io\x00", 8, wdns_res_success },
180 { "fsi.io..", WDNS_TYPE_CNAME, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
181 { ".", WDNS_TYPE_CNAME, WDNS_CLASS_IN, "\x00", 1, wdns_res_success},
182 { "", WDNS_TYPE_CNAME, WDNS_CLASS_IN, "", 0, wdns_res_success},
183 { "\"hardware\" \"os\"", WDNS_TYPE_HINFO, WDNS_CLASS_IN, "\x08hardware\x02os", 12, wdns_res_success},
184 { "hardware os", WDNS_TYPE_HINFO, WDNS_CLASS_IN, "\x08hardware\x02os", 12, wdns_res_success},
185 { "hardware\\\" os", WDNS_TYPE_HINFO, WDNS_CLASS_IN, "\x09hardware\"\x02os", 13, wdns_res_success},
186 { "hardware\\032 os", WDNS_TYPE_HINFO, WDNS_CLASS_IN, "\x09hardware \x02os", 13, wdns_res_success},
187 { "hardware\\03a os", WDNS_TYPE_HINFO, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
188 { "hardware\\256 os", WDNS_TYPE_HINFO, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
189 { "hardware\\n os", WDNS_TYPE_HINFO, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
190 { "hardware os\\", WDNS_TYPE_HINFO, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
191 { "hardware os\x01", WDNS_TYPE_HINFO, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
192 { "fsi.io. farsightsecurity.com", WDNS_TYPE_MINFO, WDNS_CLASS_IN, "\x03""fsi\x02io\x00\x10""farsightsecurity\x03""com\x00", 30, wdns_res_success },
193 { "fsi.io.", WDNS_TYPE_MINFO, WDNS_CLASS_IN, "\x03""fsi\x02io\x00", 8, wdns_res_success },
194 { "", WDNS_TYPE_MINFO, WDNS_CLASS_IN, "", 0, wdns_res_success },
195 { "5 mail.fsi.io.", WDNS_TYPE_MX, WDNS_CLASS_IN, "\x00\x05\x04mail\x03""fsi\x02io\x00", 15, wdns_res_success },
196 { "foo mail.fsi.io.", WDNS_TYPE_MX, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error },
197 { "5", WDNS_TYPE_MX, WDNS_CLASS_IN, "\x00\x05", 2, wdns_res_success },
198 { "", WDNS_TYPE_MX, WDNS_CLASS_IN, 0, 0, wdns_res_success },
199 { "", WDNS_TYPE_NULL, WDNS_CLASS_IN, "", 0, wdns_res_success},
200 { "05", WDNS_TYPE_NULL, WDNS_CLASS_IN, "\x05", 1, wdns_res_success},
201 { "FF05", WDNS_TYPE_NULL, WDNS_CLASS_IN, "\xff\x05", 2, wdns_res_success},
202 { "ABFF05", WDNS_TYPE_NULL, WDNS_CLASS_IN, "\xab\xff\x05", 3, wdns_res_success},
203 { "abff05", WDNS_TYPE_NULL, WDNS_CLASS_IN, "\xab\xff\x05", 3, wdns_res_success},
204 { "abcdff05", WDNS_TYPE_NULL, WDNS_CLASS_IN, "\xab\xcd\xff\x05", 4, wdns_res_success},
205 { "5", WDNS_TYPE_NULL, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error },
206 { "12345", WDNS_TYPE_NULL, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error },
207 { "fsi.io. root.fsi.io. 65536 1024 127 33554432 0", WDNS_TYPE_SOA, WDNS_CLASS_IN, "\x03""fsi\x02io\x00\x04root\x03""fsi\x02io\x00\x00\x01\x00\x00\x00\x00\x04\x00\x00\x00\x00\x7f\x02\x00\x00\x00\x00\x00\x00\x00", 41, wdns_res_success },
208 { "", WDNS_TYPE_TXT, WDNS_CLASS_IN, "", 0, wdns_res_success},
209 { "txt", WDNS_TYPE_TXT, WDNS_CLASS_IN, "\x03txt", 4, wdns_res_success},
210 { "txt rec", WDNS_TYPE_TXT, WDNS_CLASS_IN, "\x03txt\x03rec", 8, wdns_res_success},
211 { "txt \"record\"", WDNS_TYPE_TXT, WDNS_CLASS_IN, "\x03txt\x06record", 11, wdns_res_success},
212 { "txt \"record\" three", WDNS_TYPE_TXT, WDNS_CLASS_IN, "\x03txt\x06record\x05three", 17, wdns_res_success},
213 { "txt \"record\" three\\", WDNS_TYPE_TXT, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
214 { "127.0.0.1", WDNS_TYPE_A, WDNS_CLASS_IN, "\x7f\x00\x00\x01", 4, wdns_res_success},
215 { "127.0.0.256", WDNS_TYPE_A, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
216 { "127.0.0", WDNS_TYPE_A, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
217 { "127.0.0.0.1", WDNS_TYPE_A, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
218 { "::1", WDNS_TYPE_A, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
219 { "fsi", WDNS_TYPE_A, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
220 { "305419896 127 00deadbeef00", WDNS_TYPE_WKS, WDNS_CLASS_IN, "\x12\x34\x56\x78\x7f\x00\xde\xad\xbe\xef\x00", 11, wdns_res_success},
221 { "4294967297 127 00deadbeef00", WDNS_TYPE_WKS, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
222 { "-1 127 00deadbeef00", WDNS_TYPE_WKS, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
223 { "128 2000::dead:beef fsi.io.", WDNS_TYPE_A6, WDNS_CLASS_IN, "\x80\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xad\xbe\xef\x03""fsi\x02io\x00", 25, wdns_res_success},
224 { "120 2000::dead:be00 fsi.io.", WDNS_TYPE_A6, WDNS_CLASS_IN, "\x78\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xad\xbe\x03""fsi\x02io\x00", 24, wdns_res_success},
225 { "2000::dead:beef fsi.io.", WDNS_TYPE_A6, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
226 { "0 ::", WDNS_TYPE_A6, WDNS_CLASS_IN, "\x00\x02::\x00", 5, wdns_res_success},
227 { "0 :: fsi.io", WDNS_TYPE_A6, WDNS_CLASS_IN, "\x00\x02::\x00", 5, wdns_res_success},
228 { "::", WDNS_TYPE_AAAA, WDNS_CLASS_IN, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16, wdns_res_success},
229 { "1234:4567::abcd:ef01", WDNS_TYPE_AAAA, WDNS_CLASS_IN, "\x12\x34\x45\x67\x00\x00\x00\x00\x00\x00\x00\x00\xab\xcd\xef\x01", 16, wdns_res_success},
230 { "::abcd:ef01", WDNS_TYPE_AAAA, WDNS_CLASS_IN, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xab\xcd\xef\x01", 16, wdns_res_success},
231 { "", WDNS_TYPE_AAAA, WDNS_CLASS_IN, "", 0, wdns_res_success},
232 { "127.0.0.1", WDNS_TYPE_AAAA, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
233 { "fsi.io", WDNS_TYPE_AAAA, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
234 { "65535 64 01 ZGVhZGJlZWY=", WDNS_TYPE_DNSKEY, WDNS_CLASS_IN, "\xff\xff@\x01""deadbeef", 12, wdns_res_success},
235 { "65535 64 01 ZGVhZGJlZWY==", WDNS_TYPE_DNSKEY, WDNS_CLASS_IN, "\xff\xff@\x01""deadbeef", 12, wdns_res_success},
236 { "65535 64 01 ZGVhZGJlZWY", WDNS_TYPE_DNSKEY, WDNS_CLASS_IN, "\xff\xff@\x01""deadbeef", 12, wdns_res_success},
237 { "65535 64 01 ZGVhZGJlZWZz", WDNS_TYPE_DNSKEY, WDNS_CLASS_IN, "\xff\xff@\x01""deadbeefs", 13, wdns_res_success},
238 { "fsi.io A NS MX", WDNS_TYPE_NSEC, WDNS_CLASS_IN, "\x03""fsi\x02io\x00\x00\x02\x60\x01", 12, wdns_res_success},
239 { "fsi.io", WDNS_TYPE_NSEC, WDNS_CLASS_IN, "\x03""fsi\x02io\x00", 8, wdns_res_success},
240 { "fsi.io A NS MD MF CNAME SOA MB MG MR WKS PTR HINFO MINFO MX TXT RP AFSDB URI CAA", WDNS_TYPE_NSEC, WDNS_CLASS_IN, "\x03""fsi\x02io\x00\x00\x03\x7f\xdf\xe0\x01\x01\xc0", 16, wdns_res_success},
241 /* The next test case uses the same rrtypes as the previous, but
242 * sorted by name in order to shuffle them by value. */
243 { "fsi.io A AFSDB CAA CNAME HINFO MB MD MF MG MINFO MR MX NS PTR RP SOA TXT URI WKS", WDNS_TYPE_NSEC, WDNS_CLASS_IN, "\x03""fsi\x02io\x00\x00\x03\x7f\xdf\xe0\x01\x01\xc0", 16, wdns_res_success},
244 { "fsi.io A NS MX FAKE", WDNS_TYPE_NSEC, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
245 { "1 2 3 -", WDNS_TYPE_NSEC3PARAM, WDNS_CLASS_IN, "\x01\x02\x00\x03\x00", 5, wdns_res_success},
246 { "1 2 3 deadbeef", WDNS_TYPE_NSEC3PARAM, WDNS_CLASS_IN, "\x01\x02\x00\x03\x04\xde\xad\xbe\xef", 9, wdns_res_success},
247 { "1 2 3 deadbeeff", WDNS_TYPE_NSEC3PARAM, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
248 { "1 2 3 deadbeef-", WDNS_TYPE_NSEC3PARAM, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
249 { "1 2 3 gg", WDNS_TYPE_NSEC3PARAM, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
250 { "1 2 3 --", WDNS_TYPE_NSEC3PARAM, WDNS_CLASS_IN, 0, 0, wdns_res_parse_error},
251 { "1 2 3", WDNS_TYPE_NSEC3PARAM, WDNS_CLASS_IN, "\x01\x02\x00\x03", 4, wdns_res_success },
252 { "1 1 10 7225a239d4230bba7be2 O4K23SKVI7PTGVR5LRITC8IDIQ6KJVA0 NS DS RRSIG", WDNS_TYPE_NSEC3, WDNS_CLASS_IN, "\x01\x01\x00\x0a\x0ar%\xa2""9\xd4#\x0b\xba{\xe2\x14\xc1(!\xf2\x9f\x91\xf3\xd8\x7f""e\xae\xe5\xd6\"M\x96\x8dI\xfd@\x00\x06 \x00\x00\x00\x00\x12", 44, wdns_res_success },
253 { "NSEC 5 5 7200 1442949945 1440354345 34572 5.in-addr.arpa. aTPqHqvtDsdyY6acy5BzbmjzJcdNWeFW2laTYY/+NJsMAedSryvDJKkA evVh4Fv4G+o9Ts3XKhYUihW2qXp7bbhHmlIvSY3qX67/Ti9DzRPymirt m5ffESFO7+4H2QFd5xIpoJH/WQysNWzCyLt+JeguH4/7PU5C9K30cqqd vJk=", WDNS_TYPE_RRSIG, WDNS_CLASS_IN, "\x00/\x05\x05\x00\x00\x1c V\x01\xab""9U\xda\x10)\x87\x0c\x01""5\x07in-addr\x04""arpa\x00i3\xea\x1e\xab\xed\x0e\xc7rc\xa6\x9c\xcb\x90snh\xf3%\xc7MY\xe1V\xdaV\x93""a\x8f\xfe""4\x9b\x0c\x01\xe7R\xaf+\xc3$\xa9\x00z\xf5""a\xe0[\xf8\x1b\xea=N\xcd\xd7*\x16\x14\x8a\x15\xb6\xa9z{m\xb8G\x9aR/I\x8d\xea_\xae\xffN/C\xcd\x13\xf2\x9a*\xed\x9b\x97\xdf\x11!N\xef\xee\x07\xd9\x01]\xe7\x12)\xa0\x91\xffY\x0c\xac""5l\xc2\xc8\xbb~%\xe8.\x1f\x8f\xfb=NB\xf4\xad\xf4r\xaa\x9d\xbc\x99", 162, wdns_res_success },
254 { "NSEC3 10 3 172800 1443179274 1440584754 25427 go.id. TzGzKBNpQysYIEBHzCMub5PSg6H564xt2c/JYW6fCOyoUesDqECbJHDl 6pgyQaicCrsdSuqImSi1Ej63OEgJ1o5gKUQh0brq7i8oDZ343M57j9O7 hk7Hm+066r2dEKAD2c0SKeFTdOhjWk01Opkw+DW0SbhvKbsngII3e5mb y7+uSW3TH0OX/nOZMte8F1z98UyGKjRsInlXfc4nh2TknrwvGFgRZoS1 X2PWLkzVQSjGsfLS1/N01TYVGe0IyDWoY6csNQhnSS53Z1WAIZOuSoV5 oBBCQIQFDjknqT9/YkqQNCJso0xGcr2CyQHKcVduxYGgVarEABANrDQV DxpuEeaYGS7+eGJT+sznItOTQeSSYougSu6DsxVwYyTix/alO+KpUwzP 7YZBJIssnHYdqUvXQlcxpYtlhEYcISlcP5Ate/A2hoDR+KXo1+6ydBUy gmNTLRYVX7N+ajRnBIAhAoaGotpgzUe3uZIoiKi8FY/L4glE93mFCBqb +4mJ7O5rtWlnHy9jMlW9AIzoqfDmLoNaTUF1D6mdkVU5Gs+E0gST6Mln arJtIHttDLz/GZMOnd79+GKTdKUr5Ch4QP5LALys6WDWa2EdUg2ZWH5m hqU+5XQDMcOFyeyLsqudy4DkXk2rFMtGQlU0crzaKKyf+qSeMbXMda1F GU+kwrQvgtE=", WDNS_TYPE_RRSIG, WDNS_CLASS_IN, "\x00""2\x0a\x03\x00\x02\xa3\x00V\x05+\x0aU\xdd\x94""2cS\x02go\x02id\x00O1\xb3(\x13iC+\x18 @G\xcc#.o\x93\xd2\x83\xa1\xf9\xeb\x8cm\xd9\xcf\xc9""an\x9f\x08\xec\xa8Q\xeb\x03\xa8@\x9b$p\xe5\xea\x98""2A\xa8\x9c\x0a\xbb\x1dJ\xea\x88\x99(\xb5\x12>\xb7""8H\x09\xd6\x8e`)D!\xd1\xba\xea\xee/(\x0d\x9d\xf8\xdc\xce{\x8f\xd3\xbb\x86N\xc7\x9b\xed:\xea\xbd\x9d\x10\xa0\x03\xd9\xcd\x12)\xe1St\xe8""cZM5:\x99""0\xf8""5\xb4I\xb8o)\xbb'\x80\x82""7{\x99\x9b\xcb\xbf\xaeIm\xd3\x1f""C\x97\xfes\x99""2\xd7\xbc\x17\\\xfd\xf1L\x86*4l\"yW}\xce'\x87""d\xe4\x9e\xbc/\x18X\x11""f\x84\xb5_c\xd6.L\xd5""A(\xc6\xb1\xf2\xd2\xd7\xf3t\xd5""6\x15\x19\xed\x08\xc8""5\xa8""c\xa7,5\x08gI.wgU\x80!\x93\xaeJ\x85y\xa0\x10""B@\x84\x05\x0e""9'\xa9?\x7f""bJ\x90""4\"l\xa3LFr\xbd\x82\xc9\x01\xcaqWn\xc5\x81\xa0U\xaa\xc4\x00\x10\x0d\xac""4\x15\x0f\x1an\x11\xe6\x98\x19.\xfexbS\xfa\xcc\xe7\"\xd3\x93""A\xe4\x92""b\x8b\xa0J\xee\x83\xb3\x15pc$\xe2\xc7\xf6\xa5;\xe2\xa9S\x0c\xcf\xed\x86""A$\x8b,\x9cv\x1d\xa9K\xd7""BW1\xa5\x8b""e\x84""F\x1c!)\\?\x90-{\xf0""6\x86\x80\xd1\xf8\xa5\xe8\xd7\xee\xb2t\x15""2\x82""cS-\x16\x15_\xb3~j4g\x04\x80!\x02\x86\x86\xa2\xda`\xcdG\xb7\xb9\x92(\x88\xa8\xbc\x15\x8f\xcb\xe2\x09""D\xf7y\x85\x08\x1a\x9b\xfb\x89\x89\xec\xeek\xb5ig\x1f/c2U\xbd\x00\x8c\xe8\xa9\xf0\xe6.\x83ZMAu\x0f\xa9\x9d\x91U9\x1a\xcf\x84\xd2\x04\x93\xe8\xc9gj\xb2m {m\x0c\xbc\xff\x19\x93\x0e\x9d\xde\xfd\xf8""b\x93t\xa5+\xe4(x@\xfeK\x00\xbc\xac\xe9`\xd6ka\x1dR\x0d\x99X~f\x86\xa5>\xe5t\x03""1\xc3\x85\xc9\xec\x8b\xb2\xab\x9d\xcb\x80\xe4^M\xab\x14\xcb""FBU4r\xbc\xda(\xac\x9f\xfa\xa4\x9e""1\xb5\xccu\xad""E\x19O\xa4\xc2\xb4/\x82\xd1", 537, wdns_res_success },
255 /* generic encodings */
256 { "\\# 24 d5 79 08 01 98 4e d2 96 9a 76 0c f6 09 8e a1 4a 84 65 16 9c aa 9c 48 07", 32769, WDNS_CLASS_IN, "\xd5\x79\x08\x01\x98\x4e\xd2\x96\x9a\x76\x0c\xf6\x09\x8e\xa1\x4a\x84\x65\x16\x9c\xaa\x9c\x48\x07", 24, wdns_res_success },
257 { 0 }
258 };
259
260
261 static size_t
test_str_to_rdata(void)262 test_str_to_rdata(void) {
263 ubuf *u;
264 size_t failures = 0;
265
266 u = ubuf_init(256);
267
268 for (const struct test *cur = tdata; cur->input != NULL; cur++) {
269 uint8_t *actual = NULL;
270 size_t actual_len = 0;
271 wdns_res res;
272
273 ubuf_reset(u);
274
275 res = wdns_str_to_rdata(cur->input, cur->rrtype, cur->rrclass, &actual, &actual_len);
276
277 if (res != cur->expected_res) {
278 ubuf_add_fmt(u, "FAIL %" PRIu64 ": input=", cur-tdata);
279 escape(u, (uint8_t*)cur->input, strlen(cur->input));
280 ubuf_add_fmt(u, " %s %s res=%s != %s",
281 wdns_rrclass_to_str(cur->rrclass),
282 wdns_rrtype_to_str(cur->rrtype),
283 wdns_res_to_str(res),
284 wdns_res_to_str(cur->expected_res));
285
286 if (res == wdns_res_success) {
287 ubuf_add_cstr(u, " value=");
288 escape(u, actual, actual_len);
289 }
290 failures++;
291 } else if (actual_len != cur->expected_len || memcmp(actual, cur->expected, actual_len)) {
292 ubuf_add_fmt(u, "FAIL %" PRIu64 ": input=", cur-tdata);
293 escape(u, (uint8_t*)cur->input, strlen(cur->input));
294
295 ubuf_add_fmt(u, " %s %s",
296 wdns_rrclass_to_str(cur->rrclass),
297 wdns_rrtype_to_str(cur->rrtype));
298
299 if (actual_len != cur->expected_len) {
300 ubuf_add_fmt(u, " len %d != %d",
301 actual_len, cur->expected_len);
302 }
303
304 ubuf_add_fmt(u, " res=%s",
305 wdns_res_to_str(res));
306
307 ubuf_add_cstr(u, " value=");
308 escape(u, actual, actual_len);
309 ubuf_add_cstr(u, " != ");
310 escape(u, cur->expected, cur->expected_len);
311
312 failures++;
313 } else {
314 ubuf_add_fmt(u, "PASS %" PRIu64 ": input=", cur-tdata);
315 escape(u, (uint8_t*)cur->input, strlen(cur->input));
316 ubuf_add_fmt(u, " %s %s res=%s",
317 wdns_rrclass_to_str(cur->rrclass),
318 wdns_rrtype_to_str(cur->rrtype),
319 wdns_res_to_str(res));
320
321 if (res == wdns_res_success) {
322 ubuf_add_cstr(u, " value=");
323 escape(u, actual, actual_len);
324 }
325 }
326
327 fprintf (stderr, "%s\n", ubuf_cstr(u));
328 if (actual != NULL) {
329 free(actual);
330 actual = NULL;
331 }
332 }
333
334 ubuf_destroy(&u);
335 return failures;
336 }
337
main(void)338 int main (void) {
339 int ret = 0;
340
341 ret |= check(test_str_to_rdata(), "test_str_to_rdata", NAME);
342
343 if (ret)
344 return (EXIT_FAILURE);
345 return (EXIT_SUCCESS);
346 }
347