1 /* $NetBSD: cert_37.c,v 1.5 2014/12/10 04:37:58 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012 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.
22 /* Reviewed: Wed Mar 15 21:14:32 EST 2000 by tale */
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
) {
48 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
50 RETTOK(dns_cert_fromtext(&cert
, &token
.value
.as_textregion
));
51 RETERR(uint16_tobuffer(cert
, target
));
56 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
58 if (token
.value
.as_ulong
> 0xffffU
)
60 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
65 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
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
) {
76 char buf
[sizeof("64000 ")];
79 REQUIRE(rdata
->type
== 37);
80 REQUIRE(rdata
->length
!= 0);
84 dns_rdata_toregion(rdata
, &sr
);
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
));
97 n
= uint16_fromregion(&sr
);
98 isc_region_consume(&sr
, 2);
99 sprintf(buf
, "%u ", n
);
100 RETERR(str_totext(buf
, target
));
105 RETERR(dns_secalg_totext(sr
.base
[0], target
));
106 isc_region_consume(&sr
, 1);
111 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
112 RETERR(str_totext(" (", target
));
113 RETERR(str_totext(tctx
->linebreak
, target
));
114 if (tctx
->width
== 0) /* No splitting */
115 RETERR(isc_base64_totext(&sr
, 60, "", target
));
117 RETERR(isc_base64_totext(&sr
, tctx
->width
- 2,
118 tctx
->linebreak
, target
));
119 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
120 RETERR(str_totext(" )", target
));
121 return (ISC_R_SUCCESS
);
124 static inline isc_result_t
125 fromwire_cert(ARGS_FROMWIRE
) {
135 isc_buffer_activeregion(source
, &sr
);
137 return (ISC_R_UNEXPECTEDEND
);
139 isc_buffer_forward(source
, sr
.length
);
140 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
143 static inline isc_result_t
144 towire_cert(ARGS_TOWIRE
) {
147 REQUIRE(rdata
->type
== 37);
148 REQUIRE(rdata
->length
!= 0);
152 dns_rdata_toregion(rdata
, &sr
);
153 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
157 compare_cert(ARGS_COMPARE
) {
161 REQUIRE(rdata1
->type
== rdata2
->type
);
162 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
163 REQUIRE(rdata1
->type
== 37);
164 REQUIRE(rdata1
->length
!= 0);
165 REQUIRE(rdata2
->length
!= 0);
167 dns_rdata_toregion(rdata1
, &r1
);
168 dns_rdata_toregion(rdata2
, &r2
);
169 return (isc_region_compare(&r1
, &r2
));
172 static inline isc_result_t
173 fromstruct_cert(ARGS_FROMSTRUCT
) {
174 dns_rdata_cert_t
*cert
= source
;
177 REQUIRE(source
!= NULL
);
178 REQUIRE(cert
->common
.rdtype
== type
);
179 REQUIRE(cert
->common
.rdclass
== rdclass
);
184 RETERR(uint16_tobuffer(cert
->type
, target
));
185 RETERR(uint16_tobuffer(cert
->key_tag
, target
));
186 RETERR(uint8_tobuffer(cert
->algorithm
, target
));
188 return (mem_tobuffer(target
, cert
->certificate
, cert
->length
));
191 static inline isc_result_t
192 tostruct_cert(ARGS_TOSTRUCT
) {
193 dns_rdata_cert_t
*cert
= target
;
196 REQUIRE(rdata
->type
== 37);
197 REQUIRE(target
!= NULL
);
198 REQUIRE(rdata
->length
!= 0);
200 cert
->common
.rdclass
= rdata
->rdclass
;
201 cert
->common
.rdtype
= rdata
->type
;
202 ISC_LINK_INIT(&cert
->common
, link
);
204 dns_rdata_toregion(rdata
, ®ion
);
206 cert
->type
= uint16_fromregion(®ion
);
207 isc_region_consume(®ion
, 2);
208 cert
->key_tag
= uint16_fromregion(®ion
);
209 isc_region_consume(®ion
, 2);
210 cert
->algorithm
= uint8_fromregion(®ion
);
211 isc_region_consume(®ion
, 1);
212 cert
->length
= region
.length
;
214 cert
->certificate
= mem_maybedup(mctx
, region
.base
, region
.length
);
215 if (cert
->certificate
== NULL
)
216 return (ISC_R_NOMEMORY
);
219 return (ISC_R_SUCCESS
);
223 freestruct_cert(ARGS_FREESTRUCT
) {
224 dns_rdata_cert_t
*cert
= source
;
226 REQUIRE(cert
!= NULL
);
227 REQUIRE(cert
->common
.rdtype
== 37);
229 if (cert
->mctx
== NULL
)
232 if (cert
->certificate
!= NULL
)
233 isc_mem_free(cert
->mctx
, cert
->certificate
);
237 static inline isc_result_t
238 additionaldata_cert(ARGS_ADDLDATA
) {
239 REQUIRE(rdata
->type
== 37);
245 return (ISC_R_SUCCESS
);
248 static inline isc_result_t
249 digest_cert(ARGS_DIGEST
) {
252 REQUIRE(rdata
->type
== 37);
254 dns_rdata_toregion(rdata
, &r
);
256 return ((digest
)(arg
, &r
));
259 static inline isc_boolean_t
260 checkowner_cert(ARGS_CHECKOWNER
) {
272 static inline isc_boolean_t
273 checknames_cert(ARGS_CHECKNAMES
) {
275 REQUIRE(rdata
->type
== 37);
286 casecompare_cert(ARGS_COMPARE
) {
287 return (compare_cert(rdata1
, rdata2
));
289 #endif /* RDATA_GENERIC_CERT_37_C */