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
) {
44 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
46 if (token
.value
.as_ulong
> 0xffffU
)
48 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
53 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
55 RETTOK(dns_secalg_fromtext(&c
, &token
.value
.as_textregion
));
56 RETERR(mem_tobuffer(target
, &c
, 1));
61 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
63 if (token
.value
.as_ulong
> 0xffU
)
65 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
66 type
= (isc_uint16_t
) token
.value
.as_ulong
;
71 return (isc_hex_tobuffer(lexer
, target
, -1));
74 static inline isc_result_t
75 totext_ds(ARGS_TOTEXT
) {
77 char buf
[sizeof("64000 ")];
80 REQUIRE(rdata
->type
== 43);
81 REQUIRE(rdata
->length
!= 0);
85 dns_rdata_toregion(rdata
, &sr
);
90 n
= uint16_fromregion(&sr
);
91 isc_region_consume(&sr
, 2);
92 sprintf(buf
, "%u ", n
);
93 RETERR(str_totext(buf
, target
));
98 n
= uint8_fromregion(&sr
);
99 isc_region_consume(&sr
, 1);
100 sprintf(buf
, "%u ", n
);
101 RETERR(str_totext(buf
, target
));
106 n
= uint8_fromregion(&sr
);
107 isc_region_consume(&sr
, 1);
108 sprintf(buf
, "%u", n
);
109 RETERR(str_totext(buf
, target
));
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
) {
134 isc_buffer_activeregion(source
, &sr
);
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
) {
146 REQUIRE(rdata
->type
== 43);
147 REQUIRE(rdata
->length
!= 0);
151 dns_rdata_toregion(rdata
, &sr
);
152 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
156 compare_ds(ARGS_COMPARE
) {
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
;
176 REQUIRE(source
!= NULL
);
177 REQUIRE(ds
->common
.rdtype
== type
);
178 REQUIRE(ds
->common
.rdclass
== 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
;
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
, ®ion
);
205 ds
->key_tag
= uint16_fromregion(®ion
);
206 isc_region_consume(®ion
, 2);
207 ds
->algorithm
= uint8_fromregion(®ion
);
208 isc_region_consume(®ion
, 1);
209 ds
->digest_type
= uint8_fromregion(®ion
);
210 isc_region_consume(®ion
, 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
);
218 return (ISC_R_SUCCESS
);
222 freestruct_ds(ARGS_FREESTRUCT
) {
223 dns_rdata_ds_t
*ds
= source
;
226 REQUIRE(ds
->common
.rdtype
== 43);
228 if (ds
->mctx
== NULL
)
231 if (ds
->digest
!= NULL
)
232 isc_mem_free(ds
->mctx
, ds
->digest
);
236 static inline isc_result_t
237 additionaldata_ds(ARGS_ADDLDATA
) {
238 REQUIRE(rdata
->type
== 43);
244 return (ISC_R_SUCCESS
);
247 static inline isc_result_t
248 digest_ds(ARGS_DIGEST
) {
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
) {
271 static inline isc_boolean_t
272 checknames_ds(ARGS_CHECKNAMES
) {
274 REQUIRE(rdata
->type
== 43);
283 #endif /* RDATA_GENERIC_DS_43_C */