4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: ds_43.c,v 1.14 2009/12/04 22:06:37 tbox Exp */
22 /* draft-ietf-dnsext-delegation-signer-05.txt */
24 #ifndef RDATA_GENERIC_DS_43_C
25 #define RDATA_GENERIC_DS_43_C
27 #define RRTYPE_DS_ATTRIBUTES \
28 (DNS_RDATATYPEATTR_DNSSEC|DNS_RDATATYPEATTR_ATPARENT)
35 static inline isc_result_t
36 fromtext_ds(ARGS_FROMTEXT
) {
52 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
54 if (token
.value
.as_ulong
> 0xffffU
)
56 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
61 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
63 RETTOK(dns_secalg_fromtext(&c
, &token
.value
.as_textregion
));
64 RETERR(mem_tobuffer(target
, &c
, 1));
69 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
71 if (token
.value
.as_ulong
> 0xffU
)
73 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
74 c
= (unsigned char) token
.value
.as_ulong
;
79 if (c
== DNS_DSDIGEST_SHA1
)
80 length
= ISC_SHA1_DIGESTLENGTH
;
81 else if (c
== DNS_DSDIGEST_SHA256
)
82 length
= ISC_SHA256_DIGESTLENGTH
;
85 return (isc_hex_tobuffer(lexer
, target
, length
));
88 static inline isc_result_t
89 totext_ds(ARGS_TOTEXT
) {
91 char buf
[sizeof("64000 ")];
94 REQUIRE(rdata
->type
== 43);
95 REQUIRE(rdata
->length
!= 0);
99 dns_rdata_toregion(rdata
, &sr
);
104 n
= uint16_fromregion(&sr
);
105 isc_region_consume(&sr
, 2);
106 sprintf(buf
, "%u ", n
);
107 RETERR(str_totext(buf
, target
));
112 n
= uint8_fromregion(&sr
);
113 isc_region_consume(&sr
, 1);
114 sprintf(buf
, "%u ", n
);
115 RETERR(str_totext(buf
, target
));
120 n
= uint8_fromregion(&sr
);
121 isc_region_consume(&sr
, 1);
122 sprintf(buf
, "%u", n
);
123 RETERR(str_totext(buf
, target
));
128 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
129 RETERR(str_totext(" (", target
));
130 RETERR(str_totext(tctx
->linebreak
, target
));
131 RETERR(isc_hex_totext(&sr
, tctx
->width
- 2, tctx
->linebreak
, target
));
132 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
133 RETERR(str_totext(" )", target
));
134 return (ISC_R_SUCCESS
);
137 static inline isc_result_t
138 fromwire_ds(ARGS_FROMWIRE
) {
148 isc_buffer_activeregion(source
, &sr
);
151 * Check digest lengths if we know them.
154 (sr
.base
[3] == DNS_DSDIGEST_SHA1
&&
155 sr
.length
< 4 + ISC_SHA1_DIGESTLENGTH
) ||
156 (sr
.base
[3] == DNS_DSDIGEST_SHA256
&&
157 sr
.length
< 4 + ISC_SHA256_DIGESTLENGTH
))
158 return (ISC_R_UNEXPECTEDEND
);
161 * Only copy digest lengths if we know them.
162 * If there is extra data dns_rdata_fromwire() will
165 if (sr
.base
[3] == DNS_DSDIGEST_SHA1
)
166 sr
.length
= 4 + ISC_SHA1_DIGESTLENGTH
;
167 else if (sr
.base
[3] == DNS_DSDIGEST_SHA256
)
168 sr
.length
= 4 + ISC_SHA256_DIGESTLENGTH
;
170 isc_buffer_forward(source
, sr
.length
);
171 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
174 static inline isc_result_t
175 towire_ds(ARGS_TOWIRE
) {
178 REQUIRE(rdata
->type
== 43);
179 REQUIRE(rdata
->length
!= 0);
183 dns_rdata_toregion(rdata
, &sr
);
184 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
188 compare_ds(ARGS_COMPARE
) {
192 REQUIRE(rdata1
->type
== rdata2
->type
);
193 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
194 REQUIRE(rdata1
->type
== 43);
195 REQUIRE(rdata1
->length
!= 0);
196 REQUIRE(rdata2
->length
!= 0);
198 dns_rdata_toregion(rdata1
, &r1
);
199 dns_rdata_toregion(rdata2
, &r2
);
200 return (isc_region_compare(&r1
, &r2
));
203 static inline isc_result_t
204 fromstruct_ds(ARGS_FROMSTRUCT
) {
205 dns_rdata_ds_t
*ds
= source
;
208 REQUIRE(source
!= NULL
);
209 REQUIRE(ds
->common
.rdtype
== type
);
210 REQUIRE(ds
->common
.rdclass
== rdclass
);
211 switch (ds
->digest_type
) {
212 case DNS_DSDIGEST_SHA1
:
213 REQUIRE(ds
->length
== ISC_SHA1_DIGESTLENGTH
);
215 case DNS_DSDIGEST_SHA256
:
216 REQUIRE(ds
->length
== ISC_SHA256_DIGESTLENGTH
);
223 RETERR(uint16_tobuffer(ds
->key_tag
, target
));
224 RETERR(uint8_tobuffer(ds
->algorithm
, target
));
225 RETERR(uint8_tobuffer(ds
->digest_type
, target
));
227 return (mem_tobuffer(target
, ds
->digest
, ds
->length
));
230 static inline isc_result_t
231 tostruct_ds(ARGS_TOSTRUCT
) {
232 dns_rdata_ds_t
*ds
= target
;
235 REQUIRE(rdata
->type
== 43);
236 REQUIRE(target
!= NULL
);
237 REQUIRE(rdata
->length
!= 0);
239 ds
->common
.rdclass
= rdata
->rdclass
;
240 ds
->common
.rdtype
= rdata
->type
;
241 ISC_LINK_INIT(&ds
->common
, link
);
243 dns_rdata_toregion(rdata
, ®ion
);
245 ds
->key_tag
= uint16_fromregion(®ion
);
246 isc_region_consume(®ion
, 2);
247 ds
->algorithm
= uint8_fromregion(®ion
);
248 isc_region_consume(®ion
, 1);
249 ds
->digest_type
= uint8_fromregion(®ion
);
250 isc_region_consume(®ion
, 1);
251 ds
->length
= region
.length
;
253 ds
->digest
= mem_maybedup(mctx
, region
.base
, region
.length
);
254 if (ds
->digest
== NULL
)
255 return (ISC_R_NOMEMORY
);
258 return (ISC_R_SUCCESS
);
262 freestruct_ds(ARGS_FREESTRUCT
) {
263 dns_rdata_ds_t
*ds
= source
;
266 REQUIRE(ds
->common
.rdtype
== 43);
268 if (ds
->mctx
== NULL
)
271 if (ds
->digest
!= NULL
)
272 isc_mem_free(ds
->mctx
, ds
->digest
);
276 static inline isc_result_t
277 additionaldata_ds(ARGS_ADDLDATA
) {
278 REQUIRE(rdata
->type
== 43);
284 return (ISC_R_SUCCESS
);
287 static inline isc_result_t
288 digest_ds(ARGS_DIGEST
) {
291 REQUIRE(rdata
->type
== 43);
293 dns_rdata_toregion(rdata
, &r
);
295 return ((digest
)(arg
, &r
));
298 static inline isc_boolean_t
299 checkowner_ds(ARGS_CHECKOWNER
) {
311 static inline isc_boolean_t
312 checknames_ds(ARGS_CHECKNAMES
) {
314 REQUIRE(rdata
->type
== 43);
324 casecompare_ds(ARGS_COMPARE
) {
325 return (compare_ds(rdata1
, rdata2
));
328 #endif /* RDATA_GENERIC_DS_43_C */