00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef RDATA_GENERIC_CERT_37_C
00025 #define RDATA_GENERIC_CERT_37_C
00026
00027 #define RRTYPE_CERT_ATTRIBUTES (0)
00028
00029 static inline isc_result_t
00030 fromtext_cert(ARGS_FROMTEXT) {
00031 isc_token_t token;
00032 dns_secalg_t secalg;
00033 dns_cert_t cert;
00034
00035 REQUIRE(type == 37);
00036
00037 UNUSED(type);
00038 UNUSED(rdclass);
00039 UNUSED(origin);
00040 UNUSED(options);
00041 UNUSED(callbacks);
00042
00043
00044
00045
00046 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00047 ISC_FALSE));
00048 RETTOK(dns_cert_fromtext(&cert, &token.value.as_textregion));
00049 RETERR(uint16_tobuffer(cert, target));
00050
00051
00052
00053
00054 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00055 ISC_FALSE));
00056 if (token.value.as_ulong > 0xffffU)
00057 RETTOK(ISC_R_RANGE);
00058 RETERR(uint16_tobuffer(token.value.as_ulong, target));
00059
00060
00061
00062
00063 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00064 ISC_FALSE));
00065 RETTOK(dns_secalg_fromtext(&secalg, &token.value.as_textregion));
00066 RETERR(mem_tobuffer(target, &secalg, 1));
00067
00068 return (isc_base64_tobuffer(lexer, target, -1));
00069 }
00070
00071 static inline isc_result_t
00072 totext_cert(ARGS_TOTEXT) {
00073 isc_region_t sr;
00074 char buf[sizeof("64000 ")];
00075 unsigned int n;
00076
00077 REQUIRE(rdata->type == 37);
00078 REQUIRE(rdata->length != 0);
00079
00080 UNUSED(tctx);
00081
00082 dns_rdata_toregion(rdata, &sr);
00083
00084
00085
00086
00087 n = uint16_fromregion(&sr);
00088 isc_region_consume(&sr, 2);
00089 RETERR(dns_cert_totext((dns_cert_t)n, target));
00090 RETERR(str_totext(" ", target));
00091
00092
00093
00094
00095 n = uint16_fromregion(&sr);
00096 isc_region_consume(&sr, 2);
00097 sprintf(buf, "%u ", n);
00098 RETERR(str_totext(buf, target));
00099
00100
00101
00102
00103 RETERR(dns_secalg_totext(sr.base[0], target));
00104 isc_region_consume(&sr, 1);
00105
00106
00107
00108
00109 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00110 RETERR(str_totext(" (", target));
00111 RETERR(str_totext(tctx->linebreak, target));
00112 if (tctx->width == 0)
00113 RETERR(isc_base64_totext(&sr, 60, "", target));
00114 else
00115 RETERR(isc_base64_totext(&sr, tctx->width - 2,
00116 tctx->linebreak, target));
00117 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00118 RETERR(str_totext(" )", target));
00119 return (ISC_R_SUCCESS);
00120 }
00121
00122 static inline isc_result_t
00123 fromwire_cert(ARGS_FROMWIRE) {
00124 isc_region_t sr;
00125
00126 REQUIRE(type == 37);
00127
00128 UNUSED(type);
00129 UNUSED(rdclass);
00130 UNUSED(dctx);
00131 UNUSED(options);
00132
00133 isc_buffer_activeregion(source, &sr);
00134 if (sr.length < 5)
00135 return (ISC_R_UNEXPECTEDEND);
00136
00137 isc_buffer_forward(source, sr.length);
00138 return (mem_tobuffer(target, sr.base, sr.length));
00139 }
00140
00141 static inline isc_result_t
00142 towire_cert(ARGS_TOWIRE) {
00143 isc_region_t sr;
00144
00145 REQUIRE(rdata->type == 37);
00146 REQUIRE(rdata->length != 0);
00147
00148 UNUSED(cctx);
00149
00150 dns_rdata_toregion(rdata, &sr);
00151 return (mem_tobuffer(target, sr.base, sr.length));
00152 }
00153
00154 static inline int
00155 compare_cert(ARGS_COMPARE) {
00156 isc_region_t r1;
00157 isc_region_t r2;
00158
00159 REQUIRE(rdata1->type == rdata2->type);
00160 REQUIRE(rdata1->rdclass == rdata2->rdclass);
00161 REQUIRE(rdata1->type == 37);
00162 REQUIRE(rdata1->length != 0);
00163 REQUIRE(rdata2->length != 0);
00164
00165 dns_rdata_toregion(rdata1, &r1);
00166 dns_rdata_toregion(rdata2, &r2);
00167 return (isc_region_compare(&r1, &r2));
00168 }
00169
00170 static inline isc_result_t
00171 fromstruct_cert(ARGS_FROMSTRUCT) {
00172 dns_rdata_cert_t *cert = source;
00173
00174 REQUIRE(type == 37);
00175 REQUIRE(source != NULL);
00176 REQUIRE(cert->common.rdtype == type);
00177 REQUIRE(cert->common.rdclass == rdclass);
00178
00179 UNUSED(type);
00180 UNUSED(rdclass);
00181
00182 RETERR(uint16_tobuffer(cert->type, target));
00183 RETERR(uint16_tobuffer(cert->key_tag, target));
00184 RETERR(uint8_tobuffer(cert->algorithm, target));
00185
00186 return (mem_tobuffer(target, cert->certificate, cert->length));
00187 }
00188
00189 static inline isc_result_t
00190 tostruct_cert(ARGS_TOSTRUCT) {
00191 dns_rdata_cert_t *cert = target;
00192 isc_region_t region;
00193
00194 REQUIRE(rdata->type == 37);
00195 REQUIRE(target != NULL);
00196 REQUIRE(rdata->length != 0);
00197
00198 cert->common.rdclass = rdata->rdclass;
00199 cert->common.rdtype = rdata->type;
00200 ISC_LINK_INIT(&cert->common, link);
00201
00202 dns_rdata_toregion(rdata, ®ion);
00203
00204 cert->type = uint16_fromregion(®ion);
00205 isc_region_consume(®ion, 2);
00206 cert->key_tag = uint16_fromregion(®ion);
00207 isc_region_consume(®ion, 2);
00208 cert->algorithm = uint8_fromregion(®ion);
00209 isc_region_consume(®ion, 1);
00210 cert->length = region.length;
00211
00212 cert->certificate = mem_maybedup(mctx, region.base, region.length);
00213 if (cert->certificate == NULL)
00214 return (ISC_R_NOMEMORY);
00215
00216 cert->mctx = mctx;
00217 return (ISC_R_SUCCESS);
00218 }
00219
00220 static inline void
00221 freestruct_cert(ARGS_FREESTRUCT) {
00222 dns_rdata_cert_t *cert = source;
00223
00224 REQUIRE(cert != NULL);
00225 REQUIRE(cert->common.rdtype == 37);
00226
00227 if (cert->mctx == NULL)
00228 return;
00229
00230 if (cert->certificate != NULL)
00231 isc_mem_free(cert->mctx, cert->certificate);
00232 cert->mctx = NULL;
00233 }
00234
00235 static inline isc_result_t
00236 additionaldata_cert(ARGS_ADDLDATA) {
00237 REQUIRE(rdata->type == 37);
00238
00239 UNUSED(rdata);
00240 UNUSED(add);
00241 UNUSED(arg);
00242
00243 return (ISC_R_SUCCESS);
00244 }
00245
00246 static inline isc_result_t
00247 digest_cert(ARGS_DIGEST) {
00248 isc_region_t r;
00249
00250 REQUIRE(rdata->type == 37);
00251
00252 dns_rdata_toregion(rdata, &r);
00253
00254 return ((digest)(arg, &r));
00255 }
00256
00257 static inline isc_boolean_t
00258 checkowner_cert(ARGS_CHECKOWNER) {
00259
00260 REQUIRE(type == 37);
00261
00262 UNUSED(name);
00263 UNUSED(type);
00264 UNUSED(rdclass);
00265 UNUSED(wildcard);
00266
00267 return (ISC_TRUE);
00268 }
00269
00270 static inline isc_boolean_t
00271 checknames_cert(ARGS_CHECKNAMES) {
00272
00273 REQUIRE(rdata->type == 37);
00274
00275 UNUSED(rdata);
00276 UNUSED(owner);
00277 UNUSED(bad);
00278
00279 return (ISC_TRUE);
00280 }
00281
00282
00283 static inline int
00284 casecompare_cert(ARGS_COMPARE) {
00285 return (compare_cert(rdata1, rdata2));
00286 }
00287 #endif