2 * Copyright (C) 2004, 2006, 2007, 2009-2013 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
19 /* draft-ietf-dnsext-delegation-signer-05.txt */
21 #ifndef RDATA_GENERIC_DLV_32769_C
22 #define RDATA_GENERIC_DLV_32769_C
24 #define RRTYPE_DLV_ATTRIBUTES 0
32 static inline isc_result_t
33 fromtext_dlv(ARGS_FROMTEXT) {
38 REQUIRE(type == 32769);
49 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
51 if (token.value.as_ulong > 0xffffU)
53 RETERR(uint16_tobuffer(token.value.as_ulong, target));
58 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
60 if (token.value.as_ulong > 0xffU)
62 RETERR(uint8_tobuffer(token.value.as_ulong, target));
67 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
69 if (token.value.as_ulong > 0xffU)
71 RETERR(uint8_tobuffer(token.value.as_ulong, target));
72 c = (unsigned char) token.value.as_ulong;
78 case DNS_DSDIGEST_SHA1:
79 length = ISC_SHA1_DIGESTLENGTH;
81 case DNS_DSDIGEST_SHA256:
82 length = ISC_SHA256_DIGESTLENGTH;
84 case DNS_DSDIGEST_GOST:
85 length = ISC_GOST_DIGESTLENGTH;
87 case DNS_DSDIGEST_SHA384:
88 length = ISC_SHA384_DIGESTLENGTH;
94 return (isc_hex_tobuffer(lexer, target, length));
97 static inline isc_result_t
98 totext_dlv(ARGS_TOTEXT) {
100 char buf[sizeof("64000 ")];
103 REQUIRE(rdata->type == 32769);
104 REQUIRE(rdata->length != 0);
108 dns_rdata_toregion(rdata, &sr);
113 n = uint16_fromregion(&sr);
114 isc_region_consume(&sr, 2);
115 sprintf(buf, "%u ", n);
116 RETERR(str_totext(buf, target));
121 n = uint8_fromregion(&sr);
122 isc_region_consume(&sr, 1);
123 sprintf(buf, "%u ", n);
124 RETERR(str_totext(buf, target));
129 n = uint8_fromregion(&sr);
130 isc_region_consume(&sr, 1);
131 sprintf(buf, "%u", n);
132 RETERR(str_totext(buf, target));
137 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
138 RETERR(str_totext(" (", target));
139 RETERR(str_totext(tctx->linebreak, target));
140 if (tctx->width == 0) /* No splitting */
141 RETERR(isc_hex_totext(&sr, 0, "", target));
143 RETERR(isc_hex_totext(&sr, tctx->width - 2,
144 tctx->linebreak, target));
145 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
146 RETERR(str_totext(" )", target));
147 return (ISC_R_SUCCESS);
150 static inline isc_result_t
151 fromwire_dlv(ARGS_FROMWIRE) {
154 REQUIRE(type == 32769);
161 isc_buffer_activeregion(source, &sr);
164 * Check digest lengths if we know them.
167 (sr.base[3] == DNS_DSDIGEST_SHA1 &&
168 sr.length < 4 + ISC_SHA1_DIGESTLENGTH) ||
169 (sr.base[3] == DNS_DSDIGEST_SHA256 &&
170 sr.length < 4 + ISC_SHA256_DIGESTLENGTH) ||
171 (sr.base[3] == DNS_DSDIGEST_GOST &&
172 sr.length < 4 + ISC_GOST_DIGESTLENGTH) ||
173 (sr.base[3] == DNS_DSDIGEST_SHA384 &&
174 sr.length < 4 + ISC_SHA384_DIGESTLENGTH))
175 return (ISC_R_UNEXPECTEDEND);
178 * Only copy digest lengths if we know them.
179 * If there is extra data dns_rdata_fromwire() will
182 if (sr.base[3] == DNS_DSDIGEST_SHA1)
183 sr.length = 4 + ISC_SHA1_DIGESTLENGTH;
184 else if (sr.base[3] == DNS_DSDIGEST_SHA256)
185 sr.length = 4 + ISC_SHA256_DIGESTLENGTH;
186 else if (sr.base[3] == DNS_DSDIGEST_GOST)
187 sr.length = 4 + ISC_GOST_DIGESTLENGTH;
188 else if (sr.base[3] == DNS_DSDIGEST_SHA384)
189 sr.length = 4 + ISC_SHA384_DIGESTLENGTH;
191 isc_buffer_forward(source, sr.length);
192 return (mem_tobuffer(target, sr.base, sr.length));
195 static inline isc_result_t
196 towire_dlv(ARGS_TOWIRE) {
199 REQUIRE(rdata->type == 32769);
200 REQUIRE(rdata->length != 0);
204 dns_rdata_toregion(rdata, &sr);
205 return (mem_tobuffer(target, sr.base, sr.length));
209 compare_dlv(ARGS_COMPARE) {
213 REQUIRE(rdata1->type == rdata2->type);
214 REQUIRE(rdata1->rdclass == rdata2->rdclass);
215 REQUIRE(rdata1->type == 32769);
216 REQUIRE(rdata1->length != 0);
217 REQUIRE(rdata2->length != 0);
219 dns_rdata_toregion(rdata1, &r1);
220 dns_rdata_toregion(rdata2, &r2);
221 return (isc_region_compare(&r1, &r2));
224 static inline isc_result_t
225 fromstruct_dlv(ARGS_FROMSTRUCT) {
226 dns_rdata_dlv_t *dlv = source;
228 REQUIRE(type == 32769);
229 REQUIRE(source != NULL);
230 REQUIRE(dlv->common.rdtype == type);
231 REQUIRE(dlv->common.rdclass == rdclass);
232 switch (dlv->digest_type) {
233 case DNS_DSDIGEST_SHA1:
234 REQUIRE(dlv->length == ISC_SHA1_DIGESTLENGTH);
236 case DNS_DSDIGEST_SHA256:
237 REQUIRE(dlv->length == ISC_SHA256_DIGESTLENGTH);
239 case DNS_DSDIGEST_GOST:
240 REQUIRE(dlv->length == ISC_GOST_DIGESTLENGTH);
242 case DNS_DSDIGEST_SHA384:
243 REQUIRE(dlv->length == ISC_SHA384_DIGESTLENGTH);
250 RETERR(uint16_tobuffer(dlv->key_tag, target));
251 RETERR(uint8_tobuffer(dlv->algorithm, target));
252 RETERR(uint8_tobuffer(dlv->digest_type, target));
254 return (mem_tobuffer(target, dlv->digest, dlv->length));
257 static inline isc_result_t
258 tostruct_dlv(ARGS_TOSTRUCT) {
259 dns_rdata_dlv_t *dlv = target;
262 REQUIRE(rdata->type == 32769);
263 REQUIRE(target != NULL);
264 REQUIRE(rdata->length != 0);
266 dlv->common.rdclass = rdata->rdclass;
267 dlv->common.rdtype = rdata->type;
268 ISC_LINK_INIT(&dlv->common, link);
270 dns_rdata_toregion(rdata, ®ion);
272 dlv->key_tag = uint16_fromregion(®ion);
273 isc_region_consume(®ion, 2);
274 dlv->algorithm = uint8_fromregion(®ion);
275 isc_region_consume(®ion, 1);
276 dlv->digest_type = uint8_fromregion(®ion);
277 isc_region_consume(®ion, 1);
278 dlv->length = region.length;
280 dlv->digest = mem_maybedup(mctx, region.base, region.length);
281 if (dlv->digest == NULL)
282 return (ISC_R_NOMEMORY);
285 return (ISC_R_SUCCESS);
289 freestruct_dlv(ARGS_FREESTRUCT) {
290 dns_rdata_dlv_t *dlv = source;
292 REQUIRE(dlv != NULL);
293 REQUIRE(dlv->common.rdtype == 32769);
295 if (dlv->mctx == NULL)
298 if (dlv->digest != NULL)
299 isc_mem_free(dlv->mctx, dlv->digest);
303 static inline isc_result_t
304 additionaldata_dlv(ARGS_ADDLDATA) {
305 REQUIRE(rdata->type == 32769);
311 return (ISC_R_SUCCESS);
314 static inline isc_result_t
315 digest_dlv(ARGS_DIGEST) {
318 REQUIRE(rdata->type == 32769);
320 dns_rdata_toregion(rdata, &r);
322 return ((digest)(arg, &r));
325 static inline isc_boolean_t
326 checkowner_dlv(ARGS_CHECKOWNER) {
328 REQUIRE(type == 32769);
338 static inline isc_boolean_t
339 checknames_dlv(ARGS_CHECKNAMES) {
341 REQUIRE(rdata->type == 32769);
351 casecompare_dlv(ARGS_COMPARE) {
352 return (compare_dlv(rdata1, rdata2));
355 #endif /* RDATA_GENERIC_DLV_32769_C */