Merge branch 'vendor/BINUTILS220' into bu220
[dragonfly.git] / contrib / bind-9.3 / lib / dns / rdata / generic / ds_43.c
1 /*
2  * Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: ds_43.c,v 1.6.2.4 2005/09/06 07:29:31 marka Exp $ */
19
20 /* draft-ietf-dnsext-delegation-signer-05.txt */
21
22 #ifndef RDATA_GENERIC_DS_43_C
23 #define RDATA_GENERIC_DS_43_C
24
25 #define RRTYPE_DS_ATTRIBUTES \
26         (DNS_RDATATYPEATTR_DNSSEC|DNS_RDATATYPEATTR_ATPARENT)
27
28 static inline isc_result_t
29 fromtext_ds(ARGS_FROMTEXT) {
30         isc_token_t token;
31         unsigned char c;
32
33         REQUIRE(type == 43);
34
35         UNUSED(type);
36         UNUSED(rdclass);
37         UNUSED(origin);
38         UNUSED(options);
39         UNUSED(callbacks);
40
41         /*
42          * Key tag.
43          */
44         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45                                       ISC_FALSE));
46         if (token.value.as_ulong > 0xffffU)
47                 RETTOK(ISC_R_RANGE);
48         RETERR(uint16_tobuffer(token.value.as_ulong, target));
49
50         /*
51          * Algorithm.
52          */
53         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
54                                       ISC_FALSE));
55         RETTOK(dns_secalg_fromtext(&c, &token.value.as_textregion));
56         RETERR(mem_tobuffer(target, &c, 1));
57
58         /*
59          * Digest type.
60          */
61         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
62                                       ISC_FALSE));
63         if (token.value.as_ulong > 0xffU)
64                 RETTOK(ISC_R_RANGE);
65         RETERR(uint8_tobuffer(token.value.as_ulong, target));
66         type = (isc_uint16_t) token.value.as_ulong;
67
68         /*
69          * Digest.
70          */
71         return (isc_hex_tobuffer(lexer, target, -1));
72 }
73
74 static inline isc_result_t
75 totext_ds(ARGS_TOTEXT) {
76         isc_region_t sr;
77         char buf[sizeof("64000 ")];
78         unsigned int n;
79
80         REQUIRE(rdata->type == 43);
81         REQUIRE(rdata->length != 0);
82
83         UNUSED(tctx);
84
85         dns_rdata_toregion(rdata, &sr);
86
87         /*
88          * Key tag.
89          */
90         n = uint16_fromregion(&sr);
91         isc_region_consume(&sr, 2);
92         sprintf(buf, "%u ", n);
93         RETERR(str_totext(buf, target));
94
95         /*
96          * Algorithm.
97          */
98         n = uint8_fromregion(&sr);
99         isc_region_consume(&sr, 1);
100         sprintf(buf, "%u ", n);
101         RETERR(str_totext(buf, target));
102
103         /*
104          * Digest type.
105          */
106         n = uint8_fromregion(&sr);
107         isc_region_consume(&sr, 1);
108         sprintf(buf, "%u", n);
109         RETERR(str_totext(buf, target));
110
111         /*
112          * Digest.
113          */
114         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
115                 RETERR(str_totext(" (", target));
116         RETERR(str_totext(tctx->linebreak, target));
117         RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
118         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
119                 RETERR(str_totext(" )", target));
120         return (ISC_R_SUCCESS);
121 }
122
123 static inline isc_result_t
124 fromwire_ds(ARGS_FROMWIRE) {
125         isc_region_t sr;
126
127         REQUIRE(type == 43);
128
129         UNUSED(type);
130         UNUSED(rdclass);
131         UNUSED(dctx);
132         UNUSED(options);
133
134         isc_buffer_activeregion(source, &sr);
135         if (sr.length < 4)
136                 return (ISC_R_UNEXPECTEDEND);
137
138         isc_buffer_forward(source, sr.length);
139         return (mem_tobuffer(target, sr.base, sr.length));
140 }
141
142 static inline isc_result_t
143 towire_ds(ARGS_TOWIRE) {
144         isc_region_t sr;
145
146         REQUIRE(rdata->type == 43);
147         REQUIRE(rdata->length != 0);
148
149         UNUSED(cctx);
150
151         dns_rdata_toregion(rdata, &sr);
152         return (mem_tobuffer(target, sr.base, sr.length));
153 }
154
155 static inline int
156 compare_ds(ARGS_COMPARE) {
157         isc_region_t r1;
158         isc_region_t r2;
159
160         REQUIRE(rdata1->type == rdata2->type);
161         REQUIRE(rdata1->rdclass == rdata2->rdclass);
162         REQUIRE(rdata1->type == 43);
163         REQUIRE(rdata1->length != 0);
164         REQUIRE(rdata2->length != 0);
165
166         dns_rdata_toregion(rdata1, &r1);
167         dns_rdata_toregion(rdata2, &r2);
168         return (isc_region_compare(&r1, &r2));
169 }
170
171 static inline isc_result_t
172 fromstruct_ds(ARGS_FROMSTRUCT) {
173         dns_rdata_ds_t *ds = source;
174
175         REQUIRE(type == 43);
176         REQUIRE(source != NULL);
177         REQUIRE(ds->common.rdtype == type);
178         REQUIRE(ds->common.rdclass == rdclass);
179
180         UNUSED(type);
181         UNUSED(rdclass);
182
183         RETERR(uint16_tobuffer(ds->key_tag, target));
184         RETERR(uint8_tobuffer(ds->algorithm, target));
185         RETERR(uint8_tobuffer(ds->digest_type, target));
186
187         return (mem_tobuffer(target, ds->digest, ds->length));
188 }
189
190 static inline isc_result_t
191 tostruct_ds(ARGS_TOSTRUCT) {
192         dns_rdata_ds_t *ds = target;
193         isc_region_t region;
194
195         REQUIRE(rdata->type == 43);
196         REQUIRE(target != NULL);
197         REQUIRE(rdata->length != 0);
198
199         ds->common.rdclass = rdata->rdclass;
200         ds->common.rdtype = rdata->type;
201         ISC_LINK_INIT(&ds->common, link);
202
203         dns_rdata_toregion(rdata, &region);
204
205         ds->key_tag = uint16_fromregion(&region);
206         isc_region_consume(&region, 2);
207         ds->algorithm = uint8_fromregion(&region);
208         isc_region_consume(&region, 1);
209         ds->digest_type = uint8_fromregion(&region);
210         isc_region_consume(&region, 1);
211         ds->length = region.length;
212
213         ds->digest = mem_maybedup(mctx, region.base, region.length);
214         if (ds->digest == NULL)
215                 return (ISC_R_NOMEMORY);
216
217         ds->mctx = mctx;
218         return (ISC_R_SUCCESS);
219 }
220
221 static inline void
222 freestruct_ds(ARGS_FREESTRUCT) {
223         dns_rdata_ds_t *ds = source;
224
225         REQUIRE(ds != NULL);
226         REQUIRE(ds->common.rdtype == 43);
227
228         if (ds->mctx == NULL)
229                 return;
230
231         if (ds->digest != NULL)
232                 isc_mem_free(ds->mctx, ds->digest);
233         ds->mctx = NULL;
234 }
235
236 static inline isc_result_t
237 additionaldata_ds(ARGS_ADDLDATA) {
238         REQUIRE(rdata->type == 43);
239
240         UNUSED(rdata);
241         UNUSED(add);
242         UNUSED(arg);
243
244         return (ISC_R_SUCCESS);
245 }
246
247 static inline isc_result_t
248 digest_ds(ARGS_DIGEST) {
249         isc_region_t r;
250
251         REQUIRE(rdata->type == 43);
252
253         dns_rdata_toregion(rdata, &r);
254
255         return ((digest)(arg, &r));
256 }
257
258 static inline isc_boolean_t
259 checkowner_ds(ARGS_CHECKOWNER) {
260
261         REQUIRE(type == 43);
262
263         UNUSED(name);
264         UNUSED(type);
265         UNUSED(rdclass);
266         UNUSED(wildcard);
267
268         return (ISC_TRUE);
269 }
270
271 static inline isc_boolean_t
272 checknames_ds(ARGS_CHECKNAMES) {
273
274         REQUIRE(rdata->type == 43);
275
276         UNUSED(rdata);
277         UNUSED(owner);
278         UNUSED(bad);
279
280         return (ISC_TRUE);
281 }
282
283 #endif  /* RDATA_GENERIC_DS_43_C */