1 /* $NetBSD: tlsa_52.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
4 * Copyright (C) 2012, 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_TLSA_52_C
24 #define RDATA_GENERIC_TLSA_52_C
26 #define RRTYPE_TLSA_ATTRIBUTES 0
28 static inline isc_result_t
29 fromtext_tlsa(ARGS_FROMTEXT
) {
43 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
45 if (token
.value
.as_ulong
> 0xffU
)
47 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
52 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
54 if (token
.value
.as_ulong
> 0xffU
)
56 RETERR(uint8_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
));
68 * Certificate Association Data.
70 return (isc_hex_tobuffer(lexer
, target
, -1));
73 static inline isc_result_t
74 totext_tlsa(ARGS_TOTEXT
) {
76 char buf
[sizeof("64000 ")];
79 REQUIRE(rdata
->type
== 52);
80 REQUIRE(rdata
->length
!= 0);
84 dns_rdata_toregion(rdata
, &sr
);
89 n
= uint8_fromregion(&sr
);
90 isc_region_consume(&sr
, 1);
91 sprintf(buf
, "%u ", n
);
92 RETERR(str_totext(buf
, target
));
97 n
= uint8_fromregion(&sr
);
98 isc_region_consume(&sr
, 1);
99 sprintf(buf
, "%u ", n
);
100 RETERR(str_totext(buf
, target
));
105 n
= uint8_fromregion(&sr
);
106 isc_region_consume(&sr
, 1);
107 sprintf(buf
, "%u", n
);
108 RETERR(str_totext(buf
, target
));
111 * Certificate Association Data.
113 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
114 RETERR(str_totext(" (", target
));
115 RETERR(str_totext(tctx
->linebreak
, target
));
116 if (tctx
->width
== 0) /* No splitting */
117 RETERR(isc_hex_totext(&sr
, 0, "", target
));
119 RETERR(isc_hex_totext(&sr
, tctx
->width
- 2,
120 tctx
->linebreak
, target
));
121 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
122 RETERR(str_totext(" )", target
));
123 return (ISC_R_SUCCESS
);
126 static inline isc_result_t
127 fromwire_tlsa(ARGS_FROMWIRE
) {
137 isc_buffer_activeregion(source
, &sr
);
140 return (ISC_R_UNEXPECTEDEND
);
142 isc_buffer_forward(source
, sr
.length
);
143 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
146 static inline isc_result_t
147 towire_tlsa(ARGS_TOWIRE
) {
150 REQUIRE(rdata
->type
== 52);
151 REQUIRE(rdata
->length
!= 0);
155 dns_rdata_toregion(rdata
, &sr
);
156 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
160 compare_tlsa(ARGS_COMPARE
) {
164 REQUIRE(rdata1
->type
== rdata2
->type
);
165 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
166 REQUIRE(rdata1
->type
== 52);
167 REQUIRE(rdata1
->length
!= 0);
168 REQUIRE(rdata2
->length
!= 0);
170 dns_rdata_toregion(rdata1
, &r1
);
171 dns_rdata_toregion(rdata2
, &r2
);
172 return (isc_region_compare(&r1
, &r2
));
175 static inline isc_result_t
176 fromstruct_tlsa(ARGS_FROMSTRUCT
) {
177 dns_rdata_tlsa_t
*tlsa
= source
;
180 REQUIRE(source
!= NULL
);
181 REQUIRE(tlsa
->common
.rdtype
== type
);
182 REQUIRE(tlsa
->common
.rdclass
== rdclass
);
187 RETERR(uint8_tobuffer(tlsa
->usage
, target
));
188 RETERR(uint8_tobuffer(tlsa
->selector
, target
));
189 RETERR(uint8_tobuffer(tlsa
->match
, target
));
191 return (mem_tobuffer(target
, tlsa
->data
, tlsa
->length
));
194 static inline isc_result_t
195 tostruct_tlsa(ARGS_TOSTRUCT
) {
196 dns_rdata_tlsa_t
*tlsa
= target
;
199 REQUIRE(rdata
->type
== 52);
200 REQUIRE(target
!= NULL
);
201 REQUIRE(rdata
->length
!= 0);
203 tlsa
->common
.rdclass
= rdata
->rdclass
;
204 tlsa
->common
.rdtype
= rdata
->type
;
205 ISC_LINK_INIT(&tlsa
->common
, link
);
207 dns_rdata_toregion(rdata
, ®ion
);
209 tlsa
->usage
= uint8_fromregion(®ion
);
210 isc_region_consume(®ion
, 1);
211 tlsa
->selector
= uint8_fromregion(®ion
);
212 isc_region_consume(®ion
, 1);
213 tlsa
->match
= uint8_fromregion(®ion
);
214 isc_region_consume(®ion
, 1);
215 tlsa
->length
= region
.length
;
217 tlsa
->data
= mem_maybedup(mctx
, region
.base
, region
.length
);
218 if (tlsa
->data
== NULL
)
219 return (ISC_R_NOMEMORY
);
222 return (ISC_R_SUCCESS
);
226 freestruct_tlsa(ARGS_FREESTRUCT
) {
227 dns_rdata_tlsa_t
*tlsa
= source
;
229 REQUIRE(tlsa
!= NULL
);
230 REQUIRE(tlsa
->common
.rdtype
== 52);
232 if (tlsa
->mctx
== NULL
)
235 if (tlsa
->data
!= NULL
)
236 isc_mem_free(tlsa
->mctx
, tlsa
->data
);
240 static inline isc_result_t
241 additionaldata_tlsa(ARGS_ADDLDATA
) {
242 REQUIRE(rdata
->type
== 52);
248 return (ISC_R_SUCCESS
);
251 static inline isc_result_t
252 digest_tlsa(ARGS_DIGEST
) {
255 REQUIRE(rdata
->type
== 52);
257 dns_rdata_toregion(rdata
, &r
);
259 return ((digest
)(arg
, &r
));
262 static inline isc_boolean_t
263 checkowner_tlsa(ARGS_CHECKOWNER
) {
275 static inline isc_boolean_t
276 checknames_tlsa(ARGS_CHECKNAMES
) {
278 REQUIRE(rdata
->type
== 52);
288 casecompare_tlsa(ARGS_COMPARE
) {
289 return (compare_tlsa(rdata1
, rdata2
));
292 #endif /* RDATA_GENERIC_TLSA_52_C */