2 * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012 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.
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 if (tctx->width == 0) /* No splitting */
113 RETERR(isc_base64_totext(&sr, 60, "", target));
115 RETERR(isc_base64_totext(&sr, tctx->width - 2,
116 tctx->linebreak, target));
117 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
118 RETERR(str_totext(" )", target));
119 return (ISC_R_SUCCESS);
122 static inline isc_result_t
123 fromwire_cert(ARGS_FROMWIRE) {
133 isc_buffer_activeregion(source, &sr);
135 return (ISC_R_UNEXPECTEDEND);
137 isc_buffer_forward(source, sr.length);
138 return (mem_tobuffer(target, sr.base, sr.length));
141 static inline isc_result_t
142 towire_cert(ARGS_TOWIRE) {
145 REQUIRE(rdata->type == 37);
146 REQUIRE(rdata->length != 0);
150 dns_rdata_toregion(rdata, &sr);
151 return (mem_tobuffer(target, sr.base, sr.length));
155 compare_cert(ARGS_COMPARE) {
159 REQUIRE(rdata1->type == rdata2->type);
160 REQUIRE(rdata1->rdclass == rdata2->rdclass);
161 REQUIRE(rdata1->type == 37);
162 REQUIRE(rdata1->length != 0);
163 REQUIRE(rdata2->length != 0);
165 dns_rdata_toregion(rdata1, &r1);
166 dns_rdata_toregion(rdata2, &r2);
167 return (isc_region_compare(&r1, &r2));
170 static inline isc_result_t
171 fromstruct_cert(ARGS_FROMSTRUCT) {
172 dns_rdata_cert_t *cert = source;
175 REQUIRE(source != NULL);
176 REQUIRE(cert->common.rdtype == type);
177 REQUIRE(cert->common.rdclass == rdclass);
182 RETERR(uint16_tobuffer(cert->type, target));
183 RETERR(uint16_tobuffer(cert->key_tag, target));
184 RETERR(uint8_tobuffer(cert->algorithm, target));
186 return (mem_tobuffer(target, cert->certificate, cert->length));
189 static inline isc_result_t
190 tostruct_cert(ARGS_TOSTRUCT) {
191 dns_rdata_cert_t *cert = target;
194 REQUIRE(rdata->type == 37);
195 REQUIRE(target != NULL);
196 REQUIRE(rdata->length != 0);
198 cert->common.rdclass = rdata->rdclass;
199 cert->common.rdtype = rdata->type;
200 ISC_LINK_INIT(&cert->common, link);
202 dns_rdata_toregion(rdata, ®ion);
204 cert->type = uint16_fromregion(®ion);
205 isc_region_consume(®ion, 2);
206 cert->key_tag = uint16_fromregion(®ion);
207 isc_region_consume(®ion, 2);
208 cert->algorithm = uint8_fromregion(®ion);
209 isc_region_consume(®ion, 1);
210 cert->length = region.length;
212 cert->certificate = mem_maybedup(mctx, region.base, region.length);
213 if (cert->certificate == NULL)
214 return (ISC_R_NOMEMORY);
217 return (ISC_R_SUCCESS);
221 freestruct_cert(ARGS_FREESTRUCT) {
222 dns_rdata_cert_t *cert = source;
224 REQUIRE(cert != NULL);
225 REQUIRE(cert->common.rdtype == 37);
227 if (cert->mctx == NULL)
230 if (cert->certificate != NULL)
231 isc_mem_free(cert->mctx, cert->certificate);
235 static inline isc_result_t
236 additionaldata_cert(ARGS_ADDLDATA) {
237 REQUIRE(rdata->type == 37);
243 return (ISC_R_SUCCESS);
246 static inline isc_result_t
247 digest_cert(ARGS_DIGEST) {
250 REQUIRE(rdata->type == 37);
252 dns_rdata_toregion(rdata, &r);
254 return ((digest)(arg, &r));
257 static inline isc_boolean_t
258 checkowner_cert(ARGS_CHECKOWNER) {
270 static inline isc_boolean_t
271 checknames_cert(ARGS_CHECKNAMES) {
273 REQUIRE(rdata->type == 37);
284 casecompare_cert(ARGS_COMPARE) {
285 return (compare_cert(rdata1, rdata2));
287 #endif /* RDATA_GENERIC_CERT_37_C */