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 /* rfc6698.txt */ 18 19 #ifndef RDATA_GENERIC_TLSA_52_C 20 #define RDATA_GENERIC_TLSA_52_C 21 22 static inline isc_result_t 23 generic_totext_tlsa(ARGS_TOTEXT) { 24 isc_region_t sr; 25 char buf[sizeof("64000 ")]; 26 unsigned int n; 27 28 REQUIRE(rdata->length != 0); 29 30 UNUSED(tctx); 31 32 dns_rdata_toregion(rdata, &sr); 33 34 /* 35 * Certificate Usage. 36 */ 37 n = uint8_fromregion(&sr); 38 isc_region_consume(&sr, 1); 39 snprintf(buf, sizeof(buf), "%u ", n); 40 RETERR(isc_str_tobuffer(buf, target)); 41 42 /* 43 * Selector. 44 */ 45 n = uint8_fromregion(&sr); 46 isc_region_consume(&sr, 1); 47 snprintf(buf, sizeof(buf), "%u ", n); 48 RETERR(isc_str_tobuffer(buf, target)); 49 50 /* 51 * Matching type. 52 */ 53 n = uint8_fromregion(&sr); 54 isc_region_consume(&sr, 1); 55 snprintf(buf, sizeof(buf), "%u", n); 56 RETERR(isc_str_tobuffer(buf, target)); 57 58 /* 59 * Certificate Association Data. 60 */ 61 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 62 RETERR(isc_str_tobuffer(" (", target)); 63 RETERR(isc_str_tobuffer(tctx->linebreak, target)); 64 if (tctx->width == 0) /* No splitting */ 65 RETERR(isc_hex_totext(&sr, 0, "", target)); 66 else 67 RETERR(isc_hex_totext(&sr, tctx->width - 2, 68 tctx->linebreak, target)); 69 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) 70 RETERR(isc_str_tobuffer(" )", target)); 71 return (ISC_R_SUCCESS); 72 } 73 74 static inline isc_result_t 75 generic_fromwire_tlsa(ARGS_FROMWIRE) { 76 isc_region_t sr; 77 78 UNUSED(type); 79 UNUSED(rdclass); 80 UNUSED(dctx); 81 UNUSED(options); 82 83 isc_buffer_activeregion(source, &sr); 84 85 if (sr.length < 3) 86 return (ISC_R_UNEXPECTEDEND); 87 88 isc_buffer_forward(source, sr.length); 89 return (isc_mem_tobuffer(target, sr.base, sr.length)); 90 } 91 92 static inline isc_result_t 93 totext_tlsa(ARGS_TOTEXT) { 94 95 REQUIRE(rdata->type == dns_rdatatype_tlsa); 96 97 return (generic_totext_tlsa(rdata, tctx, target)); 98 } 99 100 static inline isc_result_t 101 fromwire_tlsa(ARGS_FROMWIRE) { 102 103 REQUIRE(type == dns_rdatatype_tlsa); 104 105 return (generic_fromwire_tlsa(rdclass, type, source, dctx, options, 106 target)); 107 } 108 109 static inline isc_result_t 110 towire_tlsa(ARGS_TOWIRE) { 111 isc_region_t sr; 112 113 REQUIRE(rdata->type == dns_rdatatype_tlsa); 114 REQUIRE(rdata->length != 0); 115 116 UNUSED(cctx); 117 118 dns_rdata_toregion(rdata, &sr); 119 return (isc_mem_tobuffer(target, sr.base, sr.length)); 120 } 121 122 #endif /* RDATA_GENERIC_TLSA_52_C */ 123