2 * Copyright (C) 2004, 2006, 2007, 2009, 2010, 2012 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, -1));
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 RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
141 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
142 RETERR(str_totext(" )", target));
143 return (ISC_R_SUCCESS);
146 static inline isc_result_t
147 fromwire_dlv(ARGS_FROMWIRE) {
150 REQUIRE(type == 32769);
157 isc_buffer_activeregion(source, &sr);
160 * Check digest lengths if we know them.
163 (sr.base[3] == DNS_DSDIGEST_SHA1 &&
164 sr.length < 4 + ISC_SHA1_DIGESTLENGTH) ||
165 (sr.base[3] == DNS_DSDIGEST_SHA256 &&
166 sr.length < 4 + ISC_SHA256_DIGESTLENGTH) ||
167 (sr.base[3] == DNS_DSDIGEST_GOST &&
168 sr.length < 4 + ISC_GOST_DIGESTLENGTH) ||
169 (sr.base[3] == DNS_DSDIGEST_SHA384 &&
170 sr.length < 4 + ISC_SHA384_DIGESTLENGTH))
171 return (ISC_R_UNEXPECTEDEND);
174 * Only copy digest lengths if we know them.
175 * If there is extra data dns_rdata_fromwire() will
178 if (sr.base[3] == DNS_DSDIGEST_SHA1)
179 sr.length = 4 + ISC_SHA1_DIGESTLENGTH;
180 else if (sr.base[3] == DNS_DSDIGEST_SHA256)
181 sr.length = 4 + ISC_SHA256_DIGESTLENGTH;
182 else if (sr.base[3] == DNS_DSDIGEST_GOST)
183 sr.length = 4 + ISC_GOST_DIGESTLENGTH;
184 else if (sr.base[3] == DNS_DSDIGEST_SHA384)
185 sr.length = 4 + ISC_SHA384_DIGESTLENGTH;
187 isc_buffer_forward(source, sr.length);
188 return (mem_tobuffer(target, sr.base, sr.length));
191 static inline isc_result_t
192 towire_dlv(ARGS_TOWIRE) {
195 REQUIRE(rdata->type == 32769);
196 REQUIRE(rdata->length != 0);
200 dns_rdata_toregion(rdata, &sr);
201 return (mem_tobuffer(target, sr.base, sr.length));
205 compare_dlv(ARGS_COMPARE) {
209 REQUIRE(rdata1->type == rdata2->type);
210 REQUIRE(rdata1->rdclass == rdata2->rdclass);
211 REQUIRE(rdata1->type == 32769);
212 REQUIRE(rdata1->length != 0);
213 REQUIRE(rdata2->length != 0);
215 dns_rdata_toregion(rdata1, &r1);
216 dns_rdata_toregion(rdata2, &r2);
217 return (isc_region_compare(&r1, &r2));
220 static inline isc_result_t
221 fromstruct_dlv(ARGS_FROMSTRUCT) {
222 dns_rdata_dlv_t *dlv = source;
224 REQUIRE(type == 32769);
225 REQUIRE(source != NULL);
226 REQUIRE(dlv->common.rdtype == type);
227 REQUIRE(dlv->common.rdclass == rdclass);
228 switch (dlv->digest_type) {
229 case DNS_DSDIGEST_SHA1:
230 REQUIRE(dlv->length == ISC_SHA1_DIGESTLENGTH);
232 case DNS_DSDIGEST_SHA256:
233 REQUIRE(dlv->length == ISC_SHA256_DIGESTLENGTH);
235 case DNS_DSDIGEST_GOST:
236 REQUIRE(dlv->length == ISC_GOST_DIGESTLENGTH);
238 case DNS_DSDIGEST_SHA384:
239 REQUIRE(dlv->length == ISC_SHA384_DIGESTLENGTH);
246 RETERR(uint16_tobuffer(dlv->key_tag, target));
247 RETERR(uint8_tobuffer(dlv->algorithm, target));
248 RETERR(uint8_tobuffer(dlv->digest_type, target));
250 return (mem_tobuffer(target, dlv->digest, dlv->length));
253 static inline isc_result_t
254 tostruct_dlv(ARGS_TOSTRUCT) {
255 dns_rdata_dlv_t *dlv = target;
258 REQUIRE(rdata->type == 32769);
259 REQUIRE(target != NULL);
260 REQUIRE(rdata->length != 0);
262 dlv->common.rdclass = rdata->rdclass;
263 dlv->common.rdtype = rdata->type;
264 ISC_LINK_INIT(&dlv->common, link);
266 dns_rdata_toregion(rdata, ®ion);
268 dlv->key_tag = uint16_fromregion(®ion);
269 isc_region_consume(®ion, 2);
270 dlv->algorithm = uint8_fromregion(®ion);
271 isc_region_consume(®ion, 1);
272 dlv->digest_type = uint8_fromregion(®ion);
273 isc_region_consume(®ion, 1);
274 dlv->length = region.length;
276 dlv->digest = mem_maybedup(mctx, region.base, region.length);
277 if (dlv->digest == NULL)
278 return (ISC_R_NOMEMORY);
281 return (ISC_R_SUCCESS);
285 freestruct_dlv(ARGS_FREESTRUCT) {
286 dns_rdata_dlv_t *dlv = source;
288 REQUIRE(dlv != NULL);
289 REQUIRE(dlv->common.rdtype == 32769);
291 if (dlv->mctx == NULL)
294 if (dlv->digest != NULL)
295 isc_mem_free(dlv->mctx, dlv->digest);
299 static inline isc_result_t
300 additionaldata_dlv(ARGS_ADDLDATA) {
301 REQUIRE(rdata->type == 32769);
307 return (ISC_R_SUCCESS);
310 static inline isc_result_t
311 digest_dlv(ARGS_DIGEST) {
314 REQUIRE(rdata->type == 32769);
316 dns_rdata_toregion(rdata, &r);
318 return ((digest)(arg, &r));
321 static inline isc_boolean_t
322 checkowner_dlv(ARGS_CHECKOWNER) {
324 REQUIRE(type == 32769);
334 static inline isc_boolean_t
335 checknames_dlv(ARGS_CHECKNAMES) {
337 REQUIRE(rdata->type == 32769);
347 casecompare_dlv(ARGS_COMPARE) {
348 return (compare_dlv(rdata1, rdata2));
351 #endif /* RDATA_GENERIC_DLV_32769_C */