2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.40.2.1.2.5 2004/03/08 09:04:40 marka Exp $ */
20 /* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
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) {
46 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
48 RETTOK(dns_cert_fromtext(&cert, &token.value.as_textregion));
49 RETERR(uint16_tobuffer(cert, target));
54 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
56 if (token.value.as_ulong > 0xffffU)
58 RETERR(uint16_tobuffer(token.value.as_ulong, target));
63 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
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) {
74 char buf[sizeof("64000 ")];
77 REQUIRE(rdata->type == 37);
78 REQUIRE(rdata->length != 0);
82 dns_rdata_toregion(rdata, &sr);
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));
95 n = uint16_fromregion(&sr);
96 isc_region_consume(&sr, 2);
97 sprintf(buf, "%u ", n);
98 RETERR(str_totext(buf, target));
103 RETERR(dns_secalg_totext(sr.base[0], target));
104 isc_region_consume(&sr, 1);
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) {
130 isc_buffer_activeregion(source, &sr);
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) {
142 REQUIRE(rdata->type == 37);
143 REQUIRE(rdata->length != 0);
147 dns_rdata_toregion(rdata, &sr);
148 return (mem_tobuffer(target, sr.base, sr.length));
152 compare_cert(ARGS_COMPARE) {
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;
172 REQUIRE(source != NULL);
173 REQUIRE(cert->common.rdtype == type);
174 REQUIRE(cert->common.rdclass == 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;
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, ®ion);
201 cert->type = uint16_fromregion(®ion);
202 isc_region_consume(®ion, 2);
203 cert->key_tag = uint16_fromregion(®ion);
204 isc_region_consume(®ion, 2);
205 cert->algorithm = uint8_fromregion(®ion);
206 isc_region_consume(®ion, 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);
214 return (ISC_R_SUCCESS);
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)
227 if (cert->certificate != NULL)
228 isc_mem_free(cert->mctx, cert->certificate);
232 static inline isc_result_t
233 additionaldata_cert(ARGS_ADDLDATA) {
234 REQUIRE(rdata->type == 37);
240 return (ISC_R_SUCCESS);
243 static inline isc_result_t
244 digest_cert(ARGS_DIGEST) {
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) {
267 static inline isc_boolean_t
268 checknames_cert(ARGS_CHECKNAMES) {
270 REQUIRE(rdata->type == 37);
279 #endif /* RDATA_GENERIC_CERT_37_C */