4 * Copyright (C) 2004, 2006, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id: dlv_32769.c,v 1.8 2009/12/04 22:06:37 tbox Exp */
21 /* draft-ietf-dnsext-delegation-signer-05.txt */
23 #ifndef RDATA_GENERIC_DLV_32769_C
24 #define RDATA_GENERIC_DLV_32769_C
26 #define RRTYPE_DLV_ATTRIBUTES 0
34 static inline isc_result_t
35 fromtext_dlv(ARGS_FROMTEXT
) {
40 REQUIRE(type
== 32769);
51 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
53 if (token
.value
.as_ulong
> 0xffffU
)
55 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
60 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
62 if (token
.value
.as_ulong
> 0xffU
)
64 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
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
, -1));
88 static inline isc_result_t
89 totext_dlv(ARGS_TOTEXT
) {
91 char buf
[sizeof("64000 ")];
94 REQUIRE(rdata
->type
== 32769);
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_dlv(ARGS_FROMWIRE
) {
141 REQUIRE(type
== 32769);
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_dlv(ARGS_TOWIRE
) {
178 REQUIRE(rdata
->type
== 32769);
179 REQUIRE(rdata
->length
!= 0);
183 dns_rdata_toregion(rdata
, &sr
);
184 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
188 compare_dlv(ARGS_COMPARE
) {
192 REQUIRE(rdata1
->type
== rdata2
->type
);
193 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
194 REQUIRE(rdata1
->type
== 32769);
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_dlv(ARGS_FROMSTRUCT
) {
205 dns_rdata_dlv_t
*dlv
= source
;
207 REQUIRE(type
== 32769);
208 REQUIRE(source
!= NULL
);
209 REQUIRE(dlv
->common
.rdtype
== type
);
210 REQUIRE(dlv
->common
.rdclass
== rdclass
);
211 switch (dlv
->digest_type
) {
212 case DNS_DSDIGEST_SHA1
:
213 REQUIRE(dlv
->length
== ISC_SHA1_DIGESTLENGTH
);
215 case DNS_DSDIGEST_SHA256
:
216 REQUIRE(dlv
->length
== ISC_SHA256_DIGESTLENGTH
);
223 RETERR(uint16_tobuffer(dlv
->key_tag
, target
));
224 RETERR(uint8_tobuffer(dlv
->algorithm
, target
));
225 RETERR(uint8_tobuffer(dlv
->digest_type
, target
));
227 return (mem_tobuffer(target
, dlv
->digest
, dlv
->length
));
230 static inline isc_result_t
231 tostruct_dlv(ARGS_TOSTRUCT
) {
232 dns_rdata_dlv_t
*dlv
= target
;
235 REQUIRE(rdata
->type
== 32769);
236 REQUIRE(target
!= NULL
);
237 REQUIRE(rdata
->length
!= 0);
239 dlv
->common
.rdclass
= rdata
->rdclass
;
240 dlv
->common
.rdtype
= rdata
->type
;
241 ISC_LINK_INIT(&dlv
->common
, link
);
243 dns_rdata_toregion(rdata
, ®ion
);
245 dlv
->key_tag
= uint16_fromregion(®ion
);
246 isc_region_consume(®ion
, 2);
247 dlv
->algorithm
= uint8_fromregion(®ion
);
248 isc_region_consume(®ion
, 1);
249 dlv
->digest_type
= uint8_fromregion(®ion
);
250 isc_region_consume(®ion
, 1);
251 dlv
->length
= region
.length
;
253 dlv
->digest
= mem_maybedup(mctx
, region
.base
, region
.length
);
254 if (dlv
->digest
== NULL
)
255 return (ISC_R_NOMEMORY
);
258 return (ISC_R_SUCCESS
);
262 freestruct_dlv(ARGS_FREESTRUCT
) {
263 dns_rdata_dlv_t
*dlv
= source
;
265 REQUIRE(dlv
!= NULL
);
266 REQUIRE(dlv
->common
.rdtype
== 32769);
268 if (dlv
->mctx
== NULL
)
271 if (dlv
->digest
!= NULL
)
272 isc_mem_free(dlv
->mctx
, dlv
->digest
);
276 static inline isc_result_t
277 additionaldata_dlv(ARGS_ADDLDATA
) {
278 REQUIRE(rdata
->type
== 32769);
284 return (ISC_R_SUCCESS
);
287 static inline isc_result_t
288 digest_dlv(ARGS_DIGEST
) {
291 REQUIRE(rdata
->type
== 32769);
293 dns_rdata_toregion(rdata
, &r
);
295 return ((digest
)(arg
, &r
));
298 static inline isc_boolean_t
299 checkowner_dlv(ARGS_CHECKOWNER
) {
301 REQUIRE(type
== 32769);
311 static inline isc_boolean_t
312 checknames_dlv(ARGS_CHECKNAMES
) {
314 REQUIRE(rdata
->type
== 32769);
324 casecompare_dlv(ARGS_COMPARE
) {
325 return (compare_dlv(rdata1
, rdata2
));
328 #endif /* RDATA_GENERIC_DLV_32769_C */