1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /* $Id: sshfp_44.c,v 1.12 2020/02/26 18:47:59 florian Exp $ */ 18 19 /* RFC 4255 */ 20 21 #ifndef RDATA_GENERIC_SSHFP_44_C 22 #define RDATA_GENERIC_SSHFP_44_C 23 24 static inline isc_result_t 25 totext_sshfp(ARGS_TOTEXT) { 26 isc_region_t sr; 27 char buf[sizeof("64000 ")]; 28 unsigned int n; 29 30 REQUIRE(rdata->type == dns_rdatatype_sshfp); 31 REQUIRE(rdata->length != 0); 32 33 UNUSED(tctx); 34 35 dns_rdata_toregion(rdata, &sr); 36 37 /* 38 * Algorithm. 39 */ 40 n = uint8_fromregion(&sr); 41 isc_region_consume(&sr, 1); 42 snprintf(buf, sizeof(buf), "%u ", n); 43 RETERR(isc_str_tobuffer(buf, target)); 44 45 /* 46 * Digest type. 47 */ 48 n = uint8_fromregion(&sr); 49 isc_region_consume(&sr, 1); 50 snprintf(buf, sizeof(buf), "%u", n); 51 RETERR(isc_str_tobuffer(buf, target)); 52 53 /* 54 * Digest. 55 */ 56 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 57 RETERR(isc_str_tobuffer(" (", target)); 58 RETERR(isc_str_tobuffer(tctx->linebreak, target)); 59 if (tctx->width == 0) /* No splitting */ 60 RETERR(isc_hex_totext(&sr, 0, "", target)); 61 else 62 RETERR(isc_hex_totext(&sr, tctx->width - 2, 63 tctx->linebreak, target)); 64 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 65 RETERR(isc_str_tobuffer(" )", target)); 66 return (ISC_R_SUCCESS); 67 } 68 69 static inline isc_result_t 70 fromwire_sshfp(ARGS_FROMWIRE) { 71 isc_region_t sr; 72 73 REQUIRE(type == dns_rdatatype_sshfp); 74 75 UNUSED(type); 76 UNUSED(rdclass); 77 UNUSED(dctx); 78 UNUSED(options); 79 80 isc_buffer_activeregion(source, &sr); 81 if (sr.length < 4) 82 return (ISC_R_UNEXPECTEDEND); 83 84 isc_buffer_forward(source, sr.length); 85 return (isc_mem_tobuffer(target, sr.base, sr.length)); 86 } 87 88 static inline isc_result_t 89 towire_sshfp(ARGS_TOWIRE) { 90 isc_region_t sr; 91 92 REQUIRE(rdata->type == dns_rdatatype_sshfp); 93 REQUIRE(rdata->length != 0); 94 95 UNUSED(cctx); 96 97 dns_rdata_toregion(rdata, &sr); 98 return (isc_mem_tobuffer(target, sr.base, sr.length)); 99 } 100 101 #endif /* RDATA_GENERIC_SSHFP_44_C */ 102