sshfp_44.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2006, 2007, 2009, 2011-2013  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 /* RFC 4255 */
00021 
00022 #ifndef RDATA_GENERIC_SSHFP_44_C
00023 #define RDATA_GENERIC_SSHFP_44_C
00024 
00025 #define RRTYPE_SSHFP_ATTRIBUTES (0)
00026 
00027 static inline isc_result_t
00028 fromtext_sshfp(ARGS_FROMTEXT) {
00029         isc_token_t token;
00030 
00031         REQUIRE(type == 44);
00032 
00033         UNUSED(type);
00034         UNUSED(rdclass);
00035         UNUSED(origin);
00036         UNUSED(options);
00037         UNUSED(callbacks);
00038 
00039         /*
00040          * Algorithm.
00041          */
00042         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00043                                       ISC_FALSE));
00044         if (token.value.as_ulong > 0xffU)
00045                 RETTOK(ISC_R_RANGE);
00046         RETERR(uint8_tobuffer(token.value.as_ulong, target));
00047 
00048         /*
00049          * Digest type.
00050          */
00051         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00052                                       ISC_FALSE));
00053         if (token.value.as_ulong > 0xffU)
00054                 RETTOK(ISC_R_RANGE);
00055         RETERR(uint8_tobuffer(token.value.as_ulong, target));
00056 
00057         /*
00058          * Digest.
00059          */
00060         return (isc_hex_tobuffer(lexer, target, -1));
00061 }
00062 
00063 static inline isc_result_t
00064 totext_sshfp(ARGS_TOTEXT) {
00065         isc_region_t sr;
00066         char buf[sizeof("64000 ")];
00067         unsigned int n;
00068 
00069         REQUIRE(rdata->type == 44);
00070         REQUIRE(rdata->length != 0);
00071 
00072         UNUSED(tctx);
00073 
00074         dns_rdata_toregion(rdata, &sr);
00075 
00076         /*
00077          * Algorithm.
00078          */
00079         n = uint8_fromregion(&sr);
00080         isc_region_consume(&sr, 1);
00081         sprintf(buf, "%u ", n);
00082         RETERR(str_totext(buf, target));
00083 
00084         /*
00085          * Digest type.
00086          */
00087         n = uint8_fromregion(&sr);
00088         isc_region_consume(&sr, 1);
00089         sprintf(buf, "%u", n);
00090         RETERR(str_totext(buf, target));
00091 
00092         /*
00093          * Digest.
00094          */
00095         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00096                 RETERR(str_totext(" (", target));
00097         RETERR(str_totext(tctx->linebreak, target));
00098         if (tctx->width == 0) /* No splitting */
00099                 RETERR(isc_hex_totext(&sr, 0, "", target));
00100         else
00101                 RETERR(isc_hex_totext(&sr, tctx->width - 2,
00102                                       tctx->linebreak, target));
00103         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00104                 RETERR(str_totext(" )", target));
00105         return (ISC_R_SUCCESS);
00106 }
00107 
00108 static inline isc_result_t
00109 fromwire_sshfp(ARGS_FROMWIRE) {
00110         isc_region_t sr;
00111 
00112         REQUIRE(type == 44);
00113 
00114         UNUSED(type);
00115         UNUSED(rdclass);
00116         UNUSED(dctx);
00117         UNUSED(options);
00118 
00119         isc_buffer_activeregion(source, &sr);
00120         if (sr.length < 4)
00121                 return (ISC_R_UNEXPECTEDEND);
00122 
00123         isc_buffer_forward(source, sr.length);
00124         return (mem_tobuffer(target, sr.base, sr.length));
00125 }
00126 
00127 static inline isc_result_t
00128 towire_sshfp(ARGS_TOWIRE) {
00129         isc_region_t sr;
00130 
00131         REQUIRE(rdata->type == 44);
00132         REQUIRE(rdata->length != 0);
00133 
00134         UNUSED(cctx);
00135 
00136         dns_rdata_toregion(rdata, &sr);
00137         return (mem_tobuffer(target, sr.base, sr.length));
00138 }
00139 
00140 static inline int
00141 compare_sshfp(ARGS_COMPARE) {
00142         isc_region_t r1;
00143         isc_region_t r2;
00144 
00145         REQUIRE(rdata1->type == rdata2->type);
00146         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00147         REQUIRE(rdata1->type == 44);
00148         REQUIRE(rdata1->length != 0);
00149         REQUIRE(rdata2->length != 0);
00150 
00151         dns_rdata_toregion(rdata1, &r1);
00152         dns_rdata_toregion(rdata2, &r2);
00153         return (isc_region_compare(&r1, &r2));
00154 }
00155 
00156 static inline isc_result_t
00157 fromstruct_sshfp(ARGS_FROMSTRUCT) {
00158         dns_rdata_sshfp_t *sshfp = source;
00159 
00160         REQUIRE(type == 44);
00161         REQUIRE(source != NULL);
00162         REQUIRE(sshfp->common.rdtype == type);
00163         REQUIRE(sshfp->common.rdclass == rdclass);
00164 
00165         UNUSED(type);
00166         UNUSED(rdclass);
00167 
00168         RETERR(uint8_tobuffer(sshfp->algorithm, target));
00169         RETERR(uint8_tobuffer(sshfp->digest_type, target));
00170 
00171         return (mem_tobuffer(target, sshfp->digest, sshfp->length));
00172 }
00173 
00174 static inline isc_result_t
00175 tostruct_sshfp(ARGS_TOSTRUCT) {
00176         dns_rdata_sshfp_t *sshfp = target;
00177         isc_region_t region;
00178 
00179         REQUIRE(rdata->type == 44);
00180         REQUIRE(target != NULL);
00181         REQUIRE(rdata->length != 0);
00182 
00183         sshfp->common.rdclass = rdata->rdclass;
00184         sshfp->common.rdtype = rdata->type;
00185         ISC_LINK_INIT(&sshfp->common, link);
00186 
00187         dns_rdata_toregion(rdata, &region);
00188 
00189         sshfp->algorithm = uint8_fromregion(&region);
00190         isc_region_consume(&region, 1);
00191         sshfp->digest_type = uint8_fromregion(&region);
00192         isc_region_consume(&region, 1);
00193         sshfp->length = region.length;
00194 
00195         sshfp->digest = mem_maybedup(mctx, region.base, region.length);
00196         if (sshfp->digest == NULL)
00197                 return (ISC_R_NOMEMORY);
00198 
00199         sshfp->mctx = mctx;
00200         return (ISC_R_SUCCESS);
00201 }
00202 
00203 static inline void
00204 freestruct_sshfp(ARGS_FREESTRUCT) {
00205         dns_rdata_sshfp_t *sshfp = source;
00206 
00207         REQUIRE(sshfp != NULL);
00208         REQUIRE(sshfp->common.rdtype == 44);
00209 
00210         if (sshfp->mctx == NULL)
00211                 return;
00212 
00213         if (sshfp->digest != NULL)
00214                 isc_mem_free(sshfp->mctx, sshfp->digest);
00215         sshfp->mctx = NULL;
00216 }
00217 
00218 static inline isc_result_t
00219 additionaldata_sshfp(ARGS_ADDLDATA) {
00220         REQUIRE(rdata->type == 44);
00221 
00222         UNUSED(rdata);
00223         UNUSED(add);
00224         UNUSED(arg);
00225 
00226         return (ISC_R_SUCCESS);
00227 }
00228 
00229 static inline isc_result_t
00230 digest_sshfp(ARGS_DIGEST) {
00231         isc_region_t r;
00232 
00233         REQUIRE(rdata->type == 44);
00234 
00235         dns_rdata_toregion(rdata, &r);
00236 
00237         return ((digest)(arg, &r));
00238 }
00239 
00240 static inline isc_boolean_t
00241 checkowner_sshfp(ARGS_CHECKOWNER) {
00242 
00243         REQUIRE(type == 44);
00244 
00245         UNUSED(name);
00246         UNUSED(type);
00247         UNUSED(rdclass);
00248         UNUSED(wildcard);
00249 
00250         return (ISC_TRUE);
00251 }
00252 
00253 static inline isc_boolean_t
00254 checknames_sshfp(ARGS_CHECKNAMES) {
00255 
00256         REQUIRE(rdata->type == 44);
00257 
00258         UNUSED(rdata);
00259         UNUSED(owner);
00260         UNUSED(bad);
00261 
00262         return (ISC_TRUE);
00263 }
00264 
00265 static inline int
00266 casecompare_sshfp(ARGS_COMPARE) {
00267         return (compare_sshfp(rdata1, rdata2));
00268 }
00269 
00270 #endif  /* RDATA_GENERIC_SSHFP_44_C */

Generated on Tue Apr 28 17:41:00 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha