1 /* $NetBSD: dlv_32769.c,v 1.8 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2006, 2007, 2009-2014 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.
23 #ifndef RDATA_GENERIC_DLV_32769_C
24 #define RDATA_GENERIC_DLV_32769_C
26 #define RRTYPE_DLV_ATTRIBUTES 0
35 static inline isc_result_t
36 fromtext_dlv(ARGS_FROMTEXT
) {
41 REQUIRE(type
== 32769);
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_number
,
63 if (token
.value
.as_ulong
> 0xffU
)
65 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
70 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
72 if (token
.value
.as_ulong
> 0xffU
)
74 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
75 c
= (unsigned char) token
.value
.as_ulong
;
81 case DNS_DSDIGEST_SHA1
:
82 length
= ISC_SHA1_DIGESTLENGTH
;
84 case DNS_DSDIGEST_SHA256
:
85 length
= ISC_SHA256_DIGESTLENGTH
;
87 #ifdef ISC_GOST_DIGESTLENGTH
88 case DNS_DSDIGEST_GOST
:
89 length
= ISC_GOST_DIGESTLENGTH
;
92 case DNS_DSDIGEST_SHA384
:
93 length
= ISC_SHA384_DIGESTLENGTH
;
99 return (isc_hex_tobuffer(lexer
, target
, length
));
102 static inline isc_result_t
103 totext_dlv(ARGS_TOTEXT
) {
105 char buf
[sizeof("64000 ")];
108 REQUIRE(rdata
->type
== 32769);
109 REQUIRE(rdata
->length
!= 0);
113 dns_rdata_toregion(rdata
, &sr
);
118 n
= uint16_fromregion(&sr
);
119 isc_region_consume(&sr
, 2);
120 sprintf(buf
, "%u ", n
);
121 RETERR(str_totext(buf
, target
));
126 n
= uint8_fromregion(&sr
);
127 isc_region_consume(&sr
, 1);
128 sprintf(buf
, "%u ", n
);
129 RETERR(str_totext(buf
, target
));
134 n
= uint8_fromregion(&sr
);
135 isc_region_consume(&sr
, 1);
136 sprintf(buf
, "%u", n
);
137 RETERR(str_totext(buf
, target
));
142 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
143 RETERR(str_totext(" (", target
));
144 RETERR(str_totext(tctx
->linebreak
, target
));
145 if ((tctx
->flags
& DNS_STYLEFLAG_NOCRYPTO
) == 0) {
146 if (tctx
->width
== 0) /* No splitting */
147 RETERR(isc_hex_totext(&sr
, 0, "", target
));
149 RETERR(isc_hex_totext(&sr
, tctx
->width
- 2,
150 tctx
->linebreak
, target
));
152 RETERR(str_totext("[omitted]", target
));
153 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
154 RETERR(str_totext(" )", target
));
155 return (ISC_R_SUCCESS
);
158 static inline isc_result_t
159 fromwire_dlv(ARGS_FROMWIRE
) {
162 REQUIRE(type
== 32769);
169 isc_buffer_activeregion(source
, &sr
);
172 * Check digest lengths if we know them.
175 (sr
.base
[3] == DNS_DSDIGEST_SHA1
&&
176 sr
.length
< 4 + ISC_SHA1_DIGESTLENGTH
) ||
177 (sr
.base
[3] == DNS_DSDIGEST_SHA256
&&
178 sr
.length
< 4 + ISC_SHA256_DIGESTLENGTH
) ||
179 #ifdef ISC_GOST_DIGESTLENGTH
180 (sr
.base
[3] == DNS_DSDIGEST_GOST
&&
181 sr
.length
< 4 + ISC_GOST_DIGESTLENGTH
) ||
183 (sr
.base
[3] == DNS_DSDIGEST_SHA384
&&
184 sr
.length
< 4 + ISC_SHA384_DIGESTLENGTH
))
185 return (ISC_R_UNEXPECTEDEND
);
188 * Only copy digest lengths if we know them.
189 * If there is extra data dns_rdata_fromwire() will
192 if (sr
.base
[3] == DNS_DSDIGEST_SHA1
)
193 sr
.length
= 4 + ISC_SHA1_DIGESTLENGTH
;
194 else if (sr
.base
[3] == DNS_DSDIGEST_SHA256
)
195 sr
.length
= 4 + ISC_SHA256_DIGESTLENGTH
;
196 #ifdef ISC_GOST_DIGESTLENGTH
197 else if (sr
.base
[3] == DNS_DSDIGEST_GOST
)
198 sr
.length
= 4 + ISC_GOST_DIGESTLENGTH
;
200 else if (sr
.base
[3] == DNS_DSDIGEST_SHA384
)
201 sr
.length
= 4 + ISC_SHA384_DIGESTLENGTH
;
203 isc_buffer_forward(source
, sr
.length
);
204 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
207 static inline isc_result_t
208 towire_dlv(ARGS_TOWIRE
) {
211 REQUIRE(rdata
->type
== 32769);
212 REQUIRE(rdata
->length
!= 0);
216 dns_rdata_toregion(rdata
, &sr
);
217 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
221 compare_dlv(ARGS_COMPARE
) {
225 REQUIRE(rdata1
->type
== rdata2
->type
);
226 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
227 REQUIRE(rdata1
->type
== 32769);
228 REQUIRE(rdata1
->length
!= 0);
229 REQUIRE(rdata2
->length
!= 0);
231 dns_rdata_toregion(rdata1
, &r1
);
232 dns_rdata_toregion(rdata2
, &r2
);
233 return (isc_region_compare(&r1
, &r2
));
236 static inline isc_result_t
237 fromstruct_dlv(ARGS_FROMSTRUCT
) {
238 dns_rdata_dlv_t
*dlv
= source
;
240 REQUIRE(type
== 32769);
241 REQUIRE(source
!= NULL
);
242 REQUIRE(dlv
->common
.rdtype
== type
);
243 REQUIRE(dlv
->common
.rdclass
== rdclass
);
244 switch (dlv
->digest_type
) {
245 case DNS_DSDIGEST_SHA1
:
246 REQUIRE(dlv
->length
== ISC_SHA1_DIGESTLENGTH
);
248 case DNS_DSDIGEST_SHA256
:
249 REQUIRE(dlv
->length
== ISC_SHA256_DIGESTLENGTH
);
251 #ifdef ISC_GOST_DIGESTLENGTH
252 case DNS_DSDIGEST_GOST
:
253 REQUIRE(dlv
->length
== ISC_GOST_DIGESTLENGTH
);
256 case DNS_DSDIGEST_SHA384
:
257 REQUIRE(dlv
->length
== ISC_SHA384_DIGESTLENGTH
);
264 RETERR(uint16_tobuffer(dlv
->key_tag
, target
));
265 RETERR(uint8_tobuffer(dlv
->algorithm
, target
));
266 RETERR(uint8_tobuffer(dlv
->digest_type
, target
));
268 return (mem_tobuffer(target
, dlv
->digest
, dlv
->length
));
271 static inline isc_result_t
272 tostruct_dlv(ARGS_TOSTRUCT
) {
273 dns_rdata_dlv_t
*dlv
= target
;
276 REQUIRE(rdata
->type
== 32769);
277 REQUIRE(target
!= NULL
);
278 REQUIRE(rdata
->length
!= 0);
280 dlv
->common
.rdclass
= rdata
->rdclass
;
281 dlv
->common
.rdtype
= rdata
->type
;
282 ISC_LINK_INIT(&dlv
->common
, link
);
284 dns_rdata_toregion(rdata
, ®ion
);
286 dlv
->key_tag
= uint16_fromregion(®ion
);
287 isc_region_consume(®ion
, 2);
288 dlv
->algorithm
= uint8_fromregion(®ion
);
289 isc_region_consume(®ion
, 1);
290 dlv
->digest_type
= uint8_fromregion(®ion
);
291 isc_region_consume(®ion
, 1);
292 dlv
->length
= region
.length
;
294 dlv
->digest
= mem_maybedup(mctx
, region
.base
, region
.length
);
295 if (dlv
->digest
== NULL
)
296 return (ISC_R_NOMEMORY
);
299 return (ISC_R_SUCCESS
);
303 freestruct_dlv(ARGS_FREESTRUCT
) {
304 dns_rdata_dlv_t
*dlv
= source
;
306 REQUIRE(dlv
!= NULL
);
307 REQUIRE(dlv
->common
.rdtype
== 32769);
309 if (dlv
->mctx
== NULL
)
312 if (dlv
->digest
!= NULL
)
313 isc_mem_free(dlv
->mctx
, dlv
->digest
);
317 static inline isc_result_t
318 additionaldata_dlv(ARGS_ADDLDATA
) {
319 REQUIRE(rdata
->type
== 32769);
325 return (ISC_R_SUCCESS
);
328 static inline isc_result_t
329 digest_dlv(ARGS_DIGEST
) {
332 REQUIRE(rdata
->type
== 32769);
334 dns_rdata_toregion(rdata
, &r
);
336 return ((digest
)(arg
, &r
));
339 static inline isc_boolean_t
340 checkowner_dlv(ARGS_CHECKOWNER
) {
342 REQUIRE(type
== 32769);
352 static inline isc_boolean_t
353 checknames_dlv(ARGS_CHECKNAMES
) {
355 REQUIRE(rdata
->type
== 32769);
365 casecompare_dlv(ARGS_COMPARE
) {
366 return (compare_dlv(rdata1
, rdata2
));
369 #endif /* RDATA_GENERIC_DLV_32769_C */