Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / tlsa_52.c
blobdb91f2f9ad5beacb7f4bf6c686803dd93171c4cb
1 /* $NetBSD: tlsa_52.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
3 /*
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.
19 /* Id */
21 /* rfc6698.txt */
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) {
30 isc_token_t token;
32 REQUIRE(type == 52);
34 UNUSED(type);
35 UNUSED(rdclass);
36 UNUSED(origin);
37 UNUSED(options);
38 UNUSED(callbacks);
41 * Certificate Usage.
43 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
44 ISC_FALSE));
45 if (token.value.as_ulong > 0xffU)
46 RETTOK(ISC_R_RANGE);
47 RETERR(uint8_tobuffer(token.value.as_ulong, target));
50 * Selector.
52 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
53 ISC_FALSE));
54 if (token.value.as_ulong > 0xffU)
55 RETTOK(ISC_R_RANGE);
56 RETERR(uint8_tobuffer(token.value.as_ulong, target));
59 * Matching type.
61 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
62 ISC_FALSE));
63 if (token.value.as_ulong > 0xffU)
64 RETTOK(ISC_R_RANGE);
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) {
75 isc_region_t sr;
76 char buf[sizeof("64000 ")];
77 unsigned int n;
79 REQUIRE(rdata->type == 52);
80 REQUIRE(rdata->length != 0);
82 UNUSED(tctx);
84 dns_rdata_toregion(rdata, &sr);
87 * Certificate Usage.
89 n = uint8_fromregion(&sr);
90 isc_region_consume(&sr, 1);
91 sprintf(buf, "%u ", n);
92 RETERR(str_totext(buf, target));
95 * Selector.
97 n = uint8_fromregion(&sr);
98 isc_region_consume(&sr, 1);
99 sprintf(buf, "%u ", n);
100 RETERR(str_totext(buf, target));
103 * Matching type.
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));
118 else
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) {
128 isc_region_t sr;
130 REQUIRE(type == 52);
132 UNUSED(type);
133 UNUSED(rdclass);
134 UNUSED(dctx);
135 UNUSED(options);
137 isc_buffer_activeregion(source, &sr);
139 if (sr.length < 3)
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) {
148 isc_region_t sr;
150 REQUIRE(rdata->type == 52);
151 REQUIRE(rdata->length != 0);
153 UNUSED(cctx);
155 dns_rdata_toregion(rdata, &sr);
156 return (mem_tobuffer(target, sr.base, sr.length));
159 static inline int
160 compare_tlsa(ARGS_COMPARE) {
161 isc_region_t r1;
162 isc_region_t r2;
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;
179 REQUIRE(type == 52);
180 REQUIRE(source != NULL);
181 REQUIRE(tlsa->common.rdtype == type);
182 REQUIRE(tlsa->common.rdclass == rdclass);
184 UNUSED(type);
185 UNUSED(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;
197 isc_region_t region;
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, &region);
209 tlsa->usage = uint8_fromregion(&region);
210 isc_region_consume(&region, 1);
211 tlsa->selector = uint8_fromregion(&region);
212 isc_region_consume(&region, 1);
213 tlsa->match = uint8_fromregion(&region);
214 isc_region_consume(&region, 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);
221 tlsa->mctx = mctx;
222 return (ISC_R_SUCCESS);
225 static inline void
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)
233 return;
235 if (tlsa->data != NULL)
236 isc_mem_free(tlsa->mctx, tlsa->data);
237 tlsa->mctx = NULL;
240 static inline isc_result_t
241 additionaldata_tlsa(ARGS_ADDLDATA) {
242 REQUIRE(rdata->type == 52);
244 UNUSED(rdata);
245 UNUSED(add);
246 UNUSED(arg);
248 return (ISC_R_SUCCESS);
251 static inline isc_result_t
252 digest_tlsa(ARGS_DIGEST) {
253 isc_region_t r;
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) {
265 REQUIRE(type == 52);
267 UNUSED(name);
268 UNUSED(type);
269 UNUSED(rdclass);
270 UNUSED(wildcard);
272 return (ISC_TRUE);
275 static inline isc_boolean_t
276 checknames_tlsa(ARGS_CHECKNAMES) {
278 REQUIRE(rdata->type == 52);
280 UNUSED(rdata);
281 UNUSED(owner);
282 UNUSED(bad);
284 return (ISC_TRUE);
287 static inline int
288 casecompare_tlsa(ARGS_COMPARE) {
289 return (compare_tlsa(rdata1, rdata2));
292 #endif /* RDATA_GENERIC_TLSA_52_C */