Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / dns / rdata / generic / cert_37.c
blob2c45230ae2e56841fca848015437d5dc151ab67e
1 /*
2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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: cert_37.c,v 1.50 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
22 /* RFC2538 */
24 #ifndef RDATA_GENERIC_CERT_37_C
25 #define RDATA_GENERIC_CERT_37_C
27 #define RRTYPE_CERT_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_cert(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_secalg_t secalg;
33 dns_cert_t cert;
35 REQUIRE(type == 37);
37 UNUSED(type);
38 UNUSED(rdclass);
39 UNUSED(origin);
40 UNUSED(options);
41 UNUSED(callbacks);
44 * Cert type.
46 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
47 ISC_FALSE));
48 RETTOK(dns_cert_fromtext(&cert, &token.value.as_textregion));
49 RETERR(uint16_tobuffer(cert, target));
52 * Key tag.
54 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
55 ISC_FALSE));
56 if (token.value.as_ulong > 0xffffU)
57 RETTOK(ISC_R_RANGE);
58 RETERR(uint16_tobuffer(token.value.as_ulong, target));
61 * Algorithm.
63 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
64 ISC_FALSE));
65 RETTOK(dns_secalg_fromtext(&secalg, &token.value.as_textregion));
66 RETERR(mem_tobuffer(target, &secalg, 1));
68 return (isc_base64_tobuffer(lexer, target, -1));
71 static inline isc_result_t
72 totext_cert(ARGS_TOTEXT) {
73 isc_region_t sr;
74 char buf[sizeof("64000 ")];
75 unsigned int n;
77 REQUIRE(rdata->type == 37);
78 REQUIRE(rdata->length != 0);
80 UNUSED(tctx);
82 dns_rdata_toregion(rdata, &sr);
85 * Type.
87 n = uint16_fromregion(&sr);
88 isc_region_consume(&sr, 2);
89 RETERR(dns_cert_totext((dns_cert_t)n, target));
90 RETERR(str_totext(" ", target));
93 * Key tag.
95 n = uint16_fromregion(&sr);
96 isc_region_consume(&sr, 2);
97 sprintf(buf, "%u ", n);
98 RETERR(str_totext(buf, target));
101 * Algorithm.
103 RETERR(dns_secalg_totext(sr.base[0], target));
104 isc_region_consume(&sr, 1);
107 * Cert.
109 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
110 RETERR(str_totext(" (", target));
111 RETERR(str_totext(tctx->linebreak, target));
112 RETERR(isc_base64_totext(&sr, tctx->width - 2,
113 tctx->linebreak, target));
114 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
115 RETERR(str_totext(" )", target));
116 return (ISC_R_SUCCESS);
119 static inline isc_result_t
120 fromwire_cert(ARGS_FROMWIRE) {
121 isc_region_t sr;
123 REQUIRE(type == 37);
125 UNUSED(type);
126 UNUSED(rdclass);
127 UNUSED(dctx);
128 UNUSED(options);
130 isc_buffer_activeregion(source, &sr);
131 if (sr.length < 5)
132 return (ISC_R_UNEXPECTEDEND);
134 isc_buffer_forward(source, sr.length);
135 return (mem_tobuffer(target, sr.base, sr.length));
138 static inline isc_result_t
139 towire_cert(ARGS_TOWIRE) {
140 isc_region_t sr;
142 REQUIRE(rdata->type == 37);
143 REQUIRE(rdata->length != 0);
145 UNUSED(cctx);
147 dns_rdata_toregion(rdata, &sr);
148 return (mem_tobuffer(target, sr.base, sr.length));
151 static inline int
152 compare_cert(ARGS_COMPARE) {
153 isc_region_t r1;
154 isc_region_t r2;
156 REQUIRE(rdata1->type == rdata2->type);
157 REQUIRE(rdata1->rdclass == rdata2->rdclass);
158 REQUIRE(rdata1->type == 37);
159 REQUIRE(rdata1->length != 0);
160 REQUIRE(rdata2->length != 0);
162 dns_rdata_toregion(rdata1, &r1);
163 dns_rdata_toregion(rdata2, &r2);
164 return (isc_region_compare(&r1, &r2));
167 static inline isc_result_t
168 fromstruct_cert(ARGS_FROMSTRUCT) {
169 dns_rdata_cert_t *cert = source;
171 REQUIRE(type == 37);
172 REQUIRE(source != NULL);
173 REQUIRE(cert->common.rdtype == type);
174 REQUIRE(cert->common.rdclass == rdclass);
176 UNUSED(type);
177 UNUSED(rdclass);
179 RETERR(uint16_tobuffer(cert->type, target));
180 RETERR(uint16_tobuffer(cert->key_tag, target));
181 RETERR(uint8_tobuffer(cert->algorithm, target));
183 return (mem_tobuffer(target, cert->certificate, cert->length));
186 static inline isc_result_t
187 tostruct_cert(ARGS_TOSTRUCT) {
188 dns_rdata_cert_t *cert = target;
189 isc_region_t region;
191 REQUIRE(rdata->type == 37);
192 REQUIRE(target != NULL);
193 REQUIRE(rdata->length != 0);
195 cert->common.rdclass = rdata->rdclass;
196 cert->common.rdtype = rdata->type;
197 ISC_LINK_INIT(&cert->common, link);
199 dns_rdata_toregion(rdata, &region);
201 cert->type = uint16_fromregion(&region);
202 isc_region_consume(&region, 2);
203 cert->key_tag = uint16_fromregion(&region);
204 isc_region_consume(&region, 2);
205 cert->algorithm = uint8_fromregion(&region);
206 isc_region_consume(&region, 1);
207 cert->length = region.length;
209 cert->certificate = mem_maybedup(mctx, region.base, region.length);
210 if (cert->certificate == NULL)
211 return (ISC_R_NOMEMORY);
213 cert->mctx = mctx;
214 return (ISC_R_SUCCESS);
217 static inline void
218 freestruct_cert(ARGS_FREESTRUCT) {
219 dns_rdata_cert_t *cert = source;
221 REQUIRE(cert != NULL);
222 REQUIRE(cert->common.rdtype == 37);
224 if (cert->mctx == NULL)
225 return;
227 if (cert->certificate != NULL)
228 isc_mem_free(cert->mctx, cert->certificate);
229 cert->mctx = NULL;
232 static inline isc_result_t
233 additionaldata_cert(ARGS_ADDLDATA) {
234 REQUIRE(rdata->type == 37);
236 UNUSED(rdata);
237 UNUSED(add);
238 UNUSED(arg);
240 return (ISC_R_SUCCESS);
243 static inline isc_result_t
244 digest_cert(ARGS_DIGEST) {
245 isc_region_t r;
247 REQUIRE(rdata->type == 37);
249 dns_rdata_toregion(rdata, &r);
251 return ((digest)(arg, &r));
254 static inline isc_boolean_t
255 checkowner_cert(ARGS_CHECKOWNER) {
257 REQUIRE(type == 37);
259 UNUSED(name);
260 UNUSED(type);
261 UNUSED(rdclass);
262 UNUSED(wildcard);
264 return (ISC_TRUE);
267 static inline isc_boolean_t
268 checknames_cert(ARGS_CHECKNAMES) {
270 REQUIRE(rdata->type == 37);
272 UNUSED(rdata);
273 UNUSED(owner);
274 UNUSED(bad);
276 return (ISC_TRUE);
279 #endif /* RDATA_GENERIC_CERT_37_C */