1 /* $NetBSD: brid_68.c,v 1.2 2026/01/29 18:37:51 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #ifndef RDATA_GENERIC_BRID_68_C 17 #define RDATA_GENERIC_BRID_68_C 18 19 #include <dst/dst.h> 20 21 #define RRTYPE_BRID_ATTRIBUTES (0) 22 23 static isc_result_t 24 fromtext_brid(ARGS_FROMTEXT) { 25 REQUIRE(type == dns_rdatatype_brid); 26 27 UNUSED(type); 28 UNUSED(rdclass); 29 UNUSED(origin); 30 UNUSED(options); 31 UNUSED(callbacks); 32 33 return isc_base64_tobuffer(lexer, target, -1); 34 } 35 36 static isc_result_t 37 totext_brid(ARGS_TOTEXT) { 38 isc_region_t sr; 39 40 REQUIRE(rdata->type == dns_rdatatype_brid); 41 REQUIRE(rdata->length > 0); 42 43 dns_rdata_toregion(rdata, &sr); 44 45 /* data */ 46 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 47 RETERR(str_totext(" (", target)); 48 } 49 50 RETERR(str_totext(tctx->linebreak, target)); 51 52 if (tctx->width == 0) { /* No splitting */ 53 RETERR(isc_base64_totext(&sr, 60, "", target)); 54 } else { 55 RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, 56 target)); 57 } 58 59 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 60 RETERR(str_totext(" )", target)); 61 } 62 63 return ISC_R_SUCCESS; 64 } 65 66 static isc_result_t 67 fromwire_brid(ARGS_FROMWIRE) { 68 isc_region_t sr; 69 70 REQUIRE(type == dns_rdatatype_brid); 71 72 UNUSED(type); 73 UNUSED(rdclass); 74 UNUSED(dctx); 75 76 isc_buffer_activeregion(source, &sr); 77 if (sr.length == 0) { 78 return ISC_R_UNEXPECTEDEND; 79 } 80 81 RETERR(mem_tobuffer(target, sr.base, sr.length)); 82 isc_buffer_forward(source, sr.length); 83 return ISC_R_SUCCESS; 84 } 85 86 static isc_result_t 87 towire_brid(ARGS_TOWIRE) { 88 REQUIRE(rdata->type == dns_rdatatype_brid); 89 REQUIRE(rdata->length > 0); 90 91 UNUSED(cctx); 92 93 return mem_tobuffer(target, rdata->data, rdata->length); 94 } 95 96 static int 97 compare_brid(ARGS_COMPARE) { 98 isc_region_t r1; 99 isc_region_t r2; 100 101 REQUIRE(rdata1->type == rdata2->type); 102 REQUIRE(rdata1->rdclass == rdata2->rdclass); 103 REQUIRE(rdata1->type == dns_rdatatype_brid); 104 REQUIRE(rdata1->length > 0); 105 REQUIRE(rdata2->length > 0); 106 107 dns_rdata_toregion(rdata1, &r1); 108 dns_rdata_toregion(rdata2, &r2); 109 return isc_region_compare(&r1, &r2); 110 } 111 112 static isc_result_t 113 fromstruct_brid(ARGS_FROMSTRUCT) { 114 dns_rdata_brid_t *brid = source; 115 116 REQUIRE(type == dns_rdatatype_brid); 117 REQUIRE(brid != NULL); 118 REQUIRE(brid->common.rdtype == type); 119 REQUIRE(brid->common.rdclass == rdclass); 120 121 UNUSED(type); 122 UNUSED(rdclass); 123 124 /* Data */ 125 return mem_tobuffer(target, brid->data, brid->datalen); 126 } 127 128 static isc_result_t 129 tostruct_brid(ARGS_TOSTRUCT) { 130 dns_rdata_brid_t *brid = target; 131 isc_region_t sr; 132 133 REQUIRE(rdata->type == dns_rdatatype_brid); 134 REQUIRE(brid != NULL); 135 REQUIRE(rdata->length > 0); 136 137 DNS_RDATACOMMON_INIT(brid, rdata->type, rdata->rdclass); 138 139 dns_rdata_toregion(rdata, &sr); 140 141 /* Data */ 142 brid->datalen = sr.length; 143 brid->data = mem_maybedup(mctx, sr.base, brid->datalen); 144 brid->mctx = mctx; 145 return ISC_R_SUCCESS; 146 } 147 148 static void 149 freestruct_brid(ARGS_FREESTRUCT) { 150 dns_rdata_brid_t *brid = (dns_rdata_brid_t *)source; 151 152 REQUIRE(brid != NULL); 153 REQUIRE(brid->common.rdtype == dns_rdatatype_brid); 154 155 if (brid->mctx == NULL) { 156 return; 157 } 158 159 if (brid->data != NULL) { 160 isc_mem_free(brid->mctx, brid->data); 161 } 162 brid->mctx = NULL; 163 } 164 165 static isc_result_t 166 additionaldata_brid(ARGS_ADDLDATA) { 167 REQUIRE(rdata->type == dns_rdatatype_brid); 168 169 UNUSED(rdata); 170 UNUSED(owner); 171 UNUSED(add); 172 UNUSED(arg); 173 174 return ISC_R_SUCCESS; 175 } 176 177 static isc_result_t 178 digest_brid(ARGS_DIGEST) { 179 isc_region_t r; 180 181 REQUIRE(rdata->type == dns_rdatatype_brid); 182 183 dns_rdata_toregion(rdata, &r); 184 185 return (digest)(arg, &r); 186 } 187 188 static bool 189 checkowner_brid(ARGS_CHECKOWNER) { 190 REQUIRE(type == dns_rdatatype_brid); 191 192 UNUSED(name); 193 UNUSED(type); 194 UNUSED(rdclass); 195 UNUSED(wildcard); 196 197 return true; 198 } 199 200 static bool 201 checknames_brid(ARGS_CHECKNAMES) { 202 REQUIRE(rdata->type == dns_rdatatype_brid); 203 204 UNUSED(rdata); 205 UNUSED(owner); 206 UNUSED(bad); 207 208 return true; 209 } 210 211 static int 212 casecompare_brid(ARGS_COMPARE) { 213 return compare_brid(rdata1, rdata2); 214 } 215 #endif /* RDATA_GENERIC_BRID_68_C */ 216