Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / bind / dist / lib / dns / rdata / generic / cert_37.c
blob66771d1ef3b03e96f4eaf2d9d2c7973f8a8ae510
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: cert_37.c,v 1.52 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
24 /* RFC2538 */
26 #ifndef RDATA_GENERIC_CERT_37_C
27 #define RDATA_GENERIC_CERT_37_C
29 #define RRTYPE_CERT_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_cert(ARGS_FROMTEXT) {
33 isc_token_t token;
34 dns_secalg_t secalg;
35 dns_cert_t cert;
37 REQUIRE(type == 37);
39 UNUSED(type);
40 UNUSED(rdclass);
41 UNUSED(origin);
42 UNUSED(options);
43 UNUSED(callbacks);
46 * Cert type.
48 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
49 ISC_FALSE));
50 RETTOK(dns_cert_fromtext(&cert, &token.value.as_textregion));
51 RETERR(uint16_tobuffer(cert, target));
54 * Key tag.
56 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
57 ISC_FALSE));
58 if (token.value.as_ulong > 0xffffU)
59 RETTOK(ISC_R_RANGE);
60 RETERR(uint16_tobuffer(token.value.as_ulong, target));
63 * Algorithm.
65 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
66 ISC_FALSE));
67 RETTOK(dns_secalg_fromtext(&secalg, &token.value.as_textregion));
68 RETERR(mem_tobuffer(target, &secalg, 1));
70 return (isc_base64_tobuffer(lexer, target, -1));
73 static inline isc_result_t
74 totext_cert(ARGS_TOTEXT) {
75 isc_region_t sr;
76 char buf[sizeof("64000 ")];
77 unsigned int n;
79 REQUIRE(rdata->type == 37);
80 REQUIRE(rdata->length != 0);
82 UNUSED(tctx);
84 dns_rdata_toregion(rdata, &sr);
87 * Type.
89 n = uint16_fromregion(&sr);
90 isc_region_consume(&sr, 2);
91 RETERR(dns_cert_totext((dns_cert_t)n, target));
92 RETERR(str_totext(" ", target));
95 * Key tag.
97 n = uint16_fromregion(&sr);
98 isc_region_consume(&sr, 2);
99 sprintf(buf, "%u ", n);
100 RETERR(str_totext(buf, target));
103 * Algorithm.
105 RETERR(dns_secalg_totext(sr.base[0], target));
106 isc_region_consume(&sr, 1);
109 * Cert.
111 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
112 RETERR(str_totext(" (", target));
113 RETERR(str_totext(tctx->linebreak, target));
114 RETERR(isc_base64_totext(&sr, tctx->width - 2,
115 tctx->linebreak, target));
116 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
117 RETERR(str_totext(" )", target));
118 return (ISC_R_SUCCESS);
121 static inline isc_result_t
122 fromwire_cert(ARGS_FROMWIRE) {
123 isc_region_t sr;
125 REQUIRE(type == 37);
127 UNUSED(type);
128 UNUSED(rdclass);
129 UNUSED(dctx);
130 UNUSED(options);
132 isc_buffer_activeregion(source, &sr);
133 if (sr.length < 5)
134 return (ISC_R_UNEXPECTEDEND);
136 isc_buffer_forward(source, sr.length);
137 return (mem_tobuffer(target, sr.base, sr.length));
140 static inline isc_result_t
141 towire_cert(ARGS_TOWIRE) {
142 isc_region_t sr;
144 REQUIRE(rdata->type == 37);
145 REQUIRE(rdata->length != 0);
147 UNUSED(cctx);
149 dns_rdata_toregion(rdata, &sr);
150 return (mem_tobuffer(target, sr.base, sr.length));
153 static inline int
154 compare_cert(ARGS_COMPARE) {
155 isc_region_t r1;
156 isc_region_t r2;
158 REQUIRE(rdata1->type == rdata2->type);
159 REQUIRE(rdata1->rdclass == rdata2->rdclass);
160 REQUIRE(rdata1->type == 37);
161 REQUIRE(rdata1->length != 0);
162 REQUIRE(rdata2->length != 0);
164 dns_rdata_toregion(rdata1, &r1);
165 dns_rdata_toregion(rdata2, &r2);
166 return (isc_region_compare(&r1, &r2));
169 static inline isc_result_t
170 fromstruct_cert(ARGS_FROMSTRUCT) {
171 dns_rdata_cert_t *cert = source;
173 REQUIRE(type == 37);
174 REQUIRE(source != NULL);
175 REQUIRE(cert->common.rdtype == type);
176 REQUIRE(cert->common.rdclass == rdclass);
178 UNUSED(type);
179 UNUSED(rdclass);
181 RETERR(uint16_tobuffer(cert->type, target));
182 RETERR(uint16_tobuffer(cert->key_tag, target));
183 RETERR(uint8_tobuffer(cert->algorithm, target));
185 return (mem_tobuffer(target, cert->certificate, cert->length));
188 static inline isc_result_t
189 tostruct_cert(ARGS_TOSTRUCT) {
190 dns_rdata_cert_t *cert = target;
191 isc_region_t region;
193 REQUIRE(rdata->type == 37);
194 REQUIRE(target != NULL);
195 REQUIRE(rdata->length != 0);
197 cert->common.rdclass = rdata->rdclass;
198 cert->common.rdtype = rdata->type;
199 ISC_LINK_INIT(&cert->common, link);
201 dns_rdata_toregion(rdata, &region);
203 cert->type = uint16_fromregion(&region);
204 isc_region_consume(&region, 2);
205 cert->key_tag = uint16_fromregion(&region);
206 isc_region_consume(&region, 2);
207 cert->algorithm = uint8_fromregion(&region);
208 isc_region_consume(&region, 1);
209 cert->length = region.length;
211 cert->certificate = mem_maybedup(mctx, region.base, region.length);
212 if (cert->certificate == NULL)
213 return (ISC_R_NOMEMORY);
215 cert->mctx = mctx;
216 return (ISC_R_SUCCESS);
219 static inline void
220 freestruct_cert(ARGS_FREESTRUCT) {
221 dns_rdata_cert_t *cert = source;
223 REQUIRE(cert != NULL);
224 REQUIRE(cert->common.rdtype == 37);
226 if (cert->mctx == NULL)
227 return;
229 if (cert->certificate != NULL)
230 isc_mem_free(cert->mctx, cert->certificate);
231 cert->mctx = NULL;
234 static inline isc_result_t
235 additionaldata_cert(ARGS_ADDLDATA) {
236 REQUIRE(rdata->type == 37);
238 UNUSED(rdata);
239 UNUSED(add);
240 UNUSED(arg);
242 return (ISC_R_SUCCESS);
245 static inline isc_result_t
246 digest_cert(ARGS_DIGEST) {
247 isc_region_t r;
249 REQUIRE(rdata->type == 37);
251 dns_rdata_toregion(rdata, &r);
253 return ((digest)(arg, &r));
256 static inline isc_boolean_t
257 checkowner_cert(ARGS_CHECKOWNER) {
259 REQUIRE(type == 37);
261 UNUSED(name);
262 UNUSED(type);
263 UNUSED(rdclass);
264 UNUSED(wildcard);
266 return (ISC_TRUE);
269 static inline isc_boolean_t
270 checknames_cert(ARGS_CHECKNAMES) {
272 REQUIRE(rdata->type == 37);
274 UNUSED(rdata);
275 UNUSED(owner);
276 UNUSED(bad);
278 return (ISC_TRUE);
282 static inline int
283 casecompare_cert(ARGS_COMPARE) {
284 return (compare_cert(rdata1, rdata2));
286 #endif /* RDATA_GENERIC_CERT_37_C */