/contrib/bind9/lib/dns/rdata/generic/sshfp_44.c
C | 267 lines | 169 code | 62 blank | 36 comment | 37 complexity | 0905a25f2b9b474143a338800b0407e1 MD5 | raw file
1/* 2 * Copyright (C) 2004, 2006, 2007, 2009, 2012 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 2003 Internet Software Consortium. 4 * 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. 8 * 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. 16 */ 17 18/* $Id$ */ 19 20/* RFC 4255 */ 21 22#ifndef RDATA_GENERIC_SSHFP_44_C 23#define RDATA_GENERIC_SSHFP_44_C 24 25#define RRTYPE_SSHFP_ATTRIBUTES (0) 26 27static inline isc_result_t 28fromtext_sshfp(ARGS_FROMTEXT) { 29 isc_token_t token; 30 31 REQUIRE(type == 44); 32 33 UNUSED(type); 34 UNUSED(rdclass); 35 UNUSED(origin); 36 UNUSED(options); 37 UNUSED(callbacks); 38 39 /* 40 * Algorithm. 41 */ 42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, 43 ISC_FALSE)); 44 if (token.value.as_ulong > 0xffU) 45 RETTOK(ISC_R_RANGE); 46 RETERR(uint8_tobuffer(token.value.as_ulong, target)); 47 48 /* 49 * Digest type. 50 */ 51 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, 52 ISC_FALSE)); 53 if (token.value.as_ulong > 0xffU) 54 RETTOK(ISC_R_RANGE); 55 RETERR(uint8_tobuffer(token.value.as_ulong, target)); 56 type = (isc_uint16_t) token.value.as_ulong; 57 58 /* 59 * Digest. 60 */ 61 return (isc_hex_tobuffer(lexer, target, -1)); 62} 63 64static inline isc_result_t 65totext_sshfp(ARGS_TOTEXT) { 66 isc_region_t sr; 67 char buf[sizeof("64000 ")]; 68 unsigned int n; 69 70 REQUIRE(rdata->type == 44); 71 REQUIRE(rdata->length != 0); 72 73 UNUSED(tctx); 74 75 dns_rdata_toregion(rdata, &sr); 76 77 /* 78 * Algorithm. 79 */ 80 n = uint8_fromregion(&sr); 81 isc_region_consume(&sr, 1); 82 sprintf(buf, "%u ", n); 83 RETERR(str_totext(buf, target)); 84 85 /* 86 * Digest type. 87 */ 88 n = uint8_fromregion(&sr); 89 isc_region_consume(&sr, 1); 90 sprintf(buf, "%u", n); 91 RETERR(str_totext(buf, target)); 92 93 /* 94 * Digest. 95 */ 96 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 97 RETERR(str_totext(" (", target)); 98 RETERR(str_totext(tctx->linebreak, target)); 99 RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target)); 100 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 101 RETERR(str_totext(" )", target)); 102 return (ISC_R_SUCCESS); 103} 104 105static inline isc_result_t 106fromwire_sshfp(ARGS_FROMWIRE) { 107 isc_region_t sr; 108 109 REQUIRE(type == 44); 110 111 UNUSED(type); 112 UNUSED(rdclass); 113 UNUSED(dctx); 114 UNUSED(options); 115 116 isc_buffer_activeregion(source, &sr); 117 if (sr.length < 4) 118 return (ISC_R_UNEXPECTEDEND); 119 120 isc_buffer_forward(source, sr.length); 121 return (mem_tobuffer(target, sr.base, sr.length)); 122} 123 124static inline isc_result_t 125towire_sshfp(ARGS_TOWIRE) { 126 isc_region_t sr; 127 128 REQUIRE(rdata->type == 44); 129 REQUIRE(rdata->length != 0); 130 131 UNUSED(cctx); 132 133 dns_rdata_toregion(rdata, &sr); 134 return (mem_tobuffer(target, sr.base, sr.length)); 135} 136 137static inline int 138compare_sshfp(ARGS_COMPARE) { 139 isc_region_t r1; 140 isc_region_t r2; 141 142 REQUIRE(rdata1->type == rdata2->type); 143 REQUIRE(rdata1->rdclass == rdata2->rdclass); 144 REQUIRE(rdata1->type == 44); 145 REQUIRE(rdata1->length != 0); 146 REQUIRE(rdata2->length != 0); 147 148 dns_rdata_toregion(rdata1, &r1); 149 dns_rdata_toregion(rdata2, &r2); 150 return (isc_region_compare(&r1, &r2)); 151} 152 153static inline isc_result_t 154fromstruct_sshfp(ARGS_FROMSTRUCT) { 155 dns_rdata_sshfp_t *sshfp = source; 156 157 REQUIRE(type == 44); 158 REQUIRE(source != NULL); 159 REQUIRE(sshfp->common.rdtype == type); 160 REQUIRE(sshfp->common.rdclass == rdclass); 161 162 UNUSED(type); 163 UNUSED(rdclass); 164 165 RETERR(uint8_tobuffer(sshfp->algorithm, target)); 166 RETERR(uint8_tobuffer(sshfp->digest_type, target)); 167 168 return (mem_tobuffer(target, sshfp->digest, sshfp->length)); 169} 170 171static inline isc_result_t 172tostruct_sshfp(ARGS_TOSTRUCT) { 173 dns_rdata_sshfp_t *sshfp = target; 174 isc_region_t region; 175 176 REQUIRE(rdata->type == 44); 177 REQUIRE(target != NULL); 178 REQUIRE(rdata->length != 0); 179 180 sshfp->common.rdclass = rdata->rdclass; 181 sshfp->common.rdtype = rdata->type; 182 ISC_LINK_INIT(&sshfp->common, link); 183 184 dns_rdata_toregion(rdata, ®ion); 185 186 sshfp->algorithm = uint8_fromregion(®ion); 187 isc_region_consume(®ion, 1); 188 sshfp->digest_type = uint8_fromregion(®ion); 189 isc_region_consume(®ion, 1); 190 sshfp->length = region.length; 191 192 sshfp->digest = mem_maybedup(mctx, region.base, region.length); 193 if (sshfp->digest == NULL) 194 return (ISC_R_NOMEMORY); 195 196 sshfp->mctx = mctx; 197 return (ISC_R_SUCCESS); 198} 199 200static inline void 201freestruct_sshfp(ARGS_FREESTRUCT) { 202 dns_rdata_sshfp_t *sshfp = source; 203 204 REQUIRE(sshfp != NULL); 205 REQUIRE(sshfp->common.rdtype == 44); 206 207 if (sshfp->mctx == NULL) 208 return; 209 210 if (sshfp->digest != NULL) 211 isc_mem_free(sshfp->mctx, sshfp->digest); 212 sshfp->mctx = NULL; 213} 214 215static inline isc_result_t 216additionaldata_sshfp(ARGS_ADDLDATA) { 217 REQUIRE(rdata->type == 44); 218 219 UNUSED(rdata); 220 UNUSED(add); 221 UNUSED(arg); 222 223 return (ISC_R_SUCCESS); 224} 225 226static inline isc_result_t 227digest_sshfp(ARGS_DIGEST) { 228 isc_region_t r; 229 230 REQUIRE(rdata->type == 44); 231 232 dns_rdata_toregion(rdata, &r); 233 234 return ((digest)(arg, &r)); 235} 236 237static inline isc_boolean_t 238checkowner_sshfp(ARGS_CHECKOWNER) { 239 240 REQUIRE(type == 44); 241 242 UNUSED(name); 243 UNUSED(type); 244 UNUSED(rdclass); 245 UNUSED(wildcard); 246 247 return (ISC_TRUE); 248} 249 250static inline isc_boolean_t 251checknames_sshfp(ARGS_CHECKNAMES) { 252 253 REQUIRE(rdata->type == 44); 254 255 UNUSED(rdata); 256 UNUSED(owner); 257 UNUSED(bad); 258 259 return (ISC_TRUE); 260} 261 262static inline int 263casecompare_sshfp(ARGS_COMPARE) { 264 return (compare_sshfp(rdata1, rdata2)); 265} 266 267#endif /* RDATA_GENERIC_SSHFP_44_C */