acpi.4: Add some missing references.
[dragonfly.git] / contrib / bind-9.3 / lib / dns / rdata / generic / ds_43.c
blob0206b6f06c226763d031fb459f53c231c530e0e6
1 /*
2 * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2002 Internet Software Consortium.
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.
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.
18 /* $Id: ds_43.c,v 1.6.2.4 2005/09/06 07:29:31 marka Exp $ */
20 /* draft-ietf-dnsext-delegation-signer-05.txt */
22 #ifndef RDATA_GENERIC_DS_43_C
23 #define RDATA_GENERIC_DS_43_C
25 #define RRTYPE_DS_ATTRIBUTES \
26 (DNS_RDATATYPEATTR_DNSSEC|DNS_RDATATYPEATTR_ATPARENT)
28 static inline isc_result_t
29 fromtext_ds(ARGS_FROMTEXT) {
30 isc_token_t token;
31 unsigned char c;
33 REQUIRE(type == 43);
35 UNUSED(type);
36 UNUSED(rdclass);
37 UNUSED(origin);
38 UNUSED(options);
39 UNUSED(callbacks);
42 * Key tag.
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));
51 * Algorithm.
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));
59 * Digest type.
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;
69 * Digest.
71 return (isc_hex_tobuffer(lexer, target, -1));
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;
80 REQUIRE(rdata->type == 43);
81 REQUIRE(rdata->length != 0);
83 UNUSED(tctx);
85 dns_rdata_toregion(rdata, &sr);
88 * Key tag.
90 n = uint16_fromregion(&sr);
91 isc_region_consume(&sr, 2);
92 sprintf(buf, "%u ", n);
93 RETERR(str_totext(buf, target));
96 * Algorithm.
98 n = uint8_fromregion(&sr);
99 isc_region_consume(&sr, 1);
100 sprintf(buf, "%u ", n);
101 RETERR(str_totext(buf, target));
104 * Digest type.
106 n = uint8_fromregion(&sr);
107 isc_region_consume(&sr, 1);
108 sprintf(buf, "%u", n);
109 RETERR(str_totext(buf, target));
112 * Digest.
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);
123 static inline isc_result_t
124 fromwire_ds(ARGS_FROMWIRE) {
125 isc_region_t sr;
127 REQUIRE(type == 43);
129 UNUSED(type);
130 UNUSED(rdclass);
131 UNUSED(dctx);
132 UNUSED(options);
134 isc_buffer_activeregion(source, &sr);
135 if (sr.length < 4)
136 return (ISC_R_UNEXPECTEDEND);
138 isc_buffer_forward(source, sr.length);
139 return (mem_tobuffer(target, sr.base, sr.length));
142 static inline isc_result_t
143 towire_ds(ARGS_TOWIRE) {
144 isc_region_t sr;
146 REQUIRE(rdata->type == 43);
147 REQUIRE(rdata->length != 0);
149 UNUSED(cctx);
151 dns_rdata_toregion(rdata, &sr);
152 return (mem_tobuffer(target, sr.base, sr.length));
155 static inline int
156 compare_ds(ARGS_COMPARE) {
157 isc_region_t r1;
158 isc_region_t r2;
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);
166 dns_rdata_toregion(rdata1, &r1);
167 dns_rdata_toregion(rdata2, &r2);
168 return (isc_region_compare(&r1, &r2));
171 static inline isc_result_t
172 fromstruct_ds(ARGS_FROMSTRUCT) {
173 dns_rdata_ds_t *ds = source;
175 REQUIRE(type == 43);
176 REQUIRE(source != NULL);
177 REQUIRE(ds->common.rdtype == type);
178 REQUIRE(ds->common.rdclass == rdclass);
180 UNUSED(type);
181 UNUSED(rdclass);
183 RETERR(uint16_tobuffer(ds->key_tag, target));
184 RETERR(uint8_tobuffer(ds->algorithm, target));
185 RETERR(uint8_tobuffer(ds->digest_type, target));
187 return (mem_tobuffer(target, ds->digest, ds->length));
190 static inline isc_result_t
191 tostruct_ds(ARGS_TOSTRUCT) {
192 dns_rdata_ds_t *ds = target;
193 isc_region_t region;
195 REQUIRE(rdata->type == 43);
196 REQUIRE(target != NULL);
197 REQUIRE(rdata->length != 0);
199 ds->common.rdclass = rdata->rdclass;
200 ds->common.rdtype = rdata->type;
201 ISC_LINK_INIT(&ds->common, link);
203 dns_rdata_toregion(rdata, &region);
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;
213 ds->digest = mem_maybedup(mctx, region.base, region.length);
214 if (ds->digest == NULL)
215 return (ISC_R_NOMEMORY);
217 ds->mctx = mctx;
218 return (ISC_R_SUCCESS);
221 static inline void
222 freestruct_ds(ARGS_FREESTRUCT) {
223 dns_rdata_ds_t *ds = source;
225 REQUIRE(ds != NULL);
226 REQUIRE(ds->common.rdtype == 43);
228 if (ds->mctx == NULL)
229 return;
231 if (ds->digest != NULL)
232 isc_mem_free(ds->mctx, ds->digest);
233 ds->mctx = NULL;
236 static inline isc_result_t
237 additionaldata_ds(ARGS_ADDLDATA) {
238 REQUIRE(rdata->type == 43);
240 UNUSED(rdata);
241 UNUSED(add);
242 UNUSED(arg);
244 return (ISC_R_SUCCESS);
247 static inline isc_result_t
248 digest_ds(ARGS_DIGEST) {
249 isc_region_t r;
251 REQUIRE(rdata->type == 43);
253 dns_rdata_toregion(rdata, &r);
255 return ((digest)(arg, &r));
258 static inline isc_boolean_t
259 checkowner_ds(ARGS_CHECKOWNER) {
261 REQUIRE(type == 43);
263 UNUSED(name);
264 UNUSED(type);
265 UNUSED(rdclass);
266 UNUSED(wildcard);
268 return (ISC_TRUE);
271 static inline isc_boolean_t
272 checknames_ds(ARGS_CHECKNAMES) {
274 REQUIRE(rdata->type == 43);
276 UNUSED(rdata);
277 UNUSED(owner);
278 UNUSED(bad);
280 return (ISC_TRUE);
283 #endif /* RDATA_GENERIC_DS_43_C */