1 /* $NetBSD: openpgpkey_61.c,v 1.10 2025/01/26 16:25:32 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_OPENPGPKEY_61_C 17 #define RDATA_GENERIC_OPENPGPKEY_61_C 18 19 #define RRTYPE_OPENPGPKEY_ATTRIBUTES 0 20 21 static isc_result_t 22 fromtext_openpgpkey(ARGS_FROMTEXT) { 23 REQUIRE(type == dns_rdatatype_openpgpkey); 24 25 UNUSED(type); 26 UNUSED(rdclass); 27 UNUSED(callbacks); 28 UNUSED(options); 29 UNUSED(origin); 30 31 /* 32 * Keyring. 33 */ 34 return isc_base64_tobuffer(lexer, target, -2); 35 } 36 37 static isc_result_t 38 totext_openpgpkey(ARGS_TOTEXT) { 39 isc_region_t sr; 40 41 REQUIRE(rdata->type == dns_rdatatype_openpgpkey); 42 REQUIRE(rdata->length != 0); 43 44 dns_rdata_toregion(rdata, &sr); 45 46 /* 47 * Keyring 48 */ 49 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 50 RETERR(str_totext("( ", target)); 51 } 52 53 if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) { 54 if (tctx->width == 0) { /* No splitting */ 55 RETERR(isc_base64_totext(&sr, 60, "", target)); 56 } else { 57 RETERR(isc_base64_totext(&sr, tctx->width - 2, 58 tctx->linebreak, target)); 59 } 60 } else { 61 RETERR(str_totext("[omitted]", target)); 62 } 63 64 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 65 RETERR(str_totext(" )", target)); 66 } 67 68 return ISC_R_SUCCESS; 69 } 70 71 static isc_result_t 72 fromwire_openpgpkey(ARGS_FROMWIRE) { 73 isc_region_t sr; 74 75 REQUIRE(type == dns_rdatatype_openpgpkey); 76 77 UNUSED(type); 78 UNUSED(rdclass); 79 UNUSED(dctx); 80 81 /* 82 * Keyring. 83 */ 84 isc_buffer_activeregion(source, &sr); 85 if (sr.length < 1) { 86 return ISC_R_UNEXPECTEDEND; 87 } 88 isc_buffer_forward(source, sr.length); 89 return mem_tobuffer(target, sr.base, sr.length); 90 } 91 92 static isc_result_t 93 towire_openpgpkey(ARGS_TOWIRE) { 94 isc_region_t sr; 95 96 REQUIRE(rdata->type == dns_rdatatype_openpgpkey); 97 REQUIRE(rdata->length != 0); 98 99 UNUSED(cctx); 100 101 dns_rdata_toregion(rdata, &sr); 102 return mem_tobuffer(target, sr.base, sr.length); 103 } 104 105 static int 106 compare_openpgpkey(ARGS_COMPARE) { 107 isc_region_t r1; 108 isc_region_t r2; 109 110 REQUIRE(rdata1->type == rdata2->type); 111 REQUIRE(rdata1->rdclass == rdata2->rdclass); 112 REQUIRE(rdata1->type == dns_rdatatype_openpgpkey); 113 REQUIRE(rdata1->length != 0); 114 REQUIRE(rdata2->length != 0); 115 116 dns_rdata_toregion(rdata1, &r1); 117 dns_rdata_toregion(rdata2, &r2); 118 return isc_region_compare(&r1, &r2); 119 } 120 121 static isc_result_t 122 fromstruct_openpgpkey(ARGS_FROMSTRUCT) { 123 dns_rdata_openpgpkey_t *sig = source; 124 125 REQUIRE(type == dns_rdatatype_openpgpkey); 126 REQUIRE(sig != NULL); 127 REQUIRE(sig->common.rdtype == type); 128 REQUIRE(sig->common.rdclass == rdclass); 129 REQUIRE(sig->keyring != NULL && sig->length != 0); 130 131 UNUSED(type); 132 UNUSED(rdclass); 133 134 /* 135 * Keyring. 136 */ 137 return mem_tobuffer(target, sig->keyring, sig->length); 138 } 139 140 static isc_result_t 141 tostruct_openpgpkey(ARGS_TOSTRUCT) { 142 isc_region_t sr; 143 dns_rdata_openpgpkey_t *sig = target; 144 145 REQUIRE(rdata->type == dns_rdatatype_openpgpkey); 146 REQUIRE(sig != NULL); 147 REQUIRE(rdata->length != 0); 148 149 sig->common.rdclass = rdata->rdclass; 150 sig->common.rdtype = rdata->type; 151 ISC_LINK_INIT(&sig->common, link); 152 153 dns_rdata_toregion(rdata, &sr); 154 155 /* 156 * Keyring. 157 */ 158 sig->length = sr.length; 159 sig->keyring = mem_maybedup(mctx, sr.base, sig->length); 160 sig->mctx = mctx; 161 return ISC_R_SUCCESS; 162 } 163 164 static void 165 freestruct_openpgpkey(ARGS_FREESTRUCT) { 166 dns_rdata_openpgpkey_t *sig = (dns_rdata_openpgpkey_t *)source; 167 168 REQUIRE(sig != NULL); 169 REQUIRE(sig->common.rdtype == dns_rdatatype_openpgpkey); 170 171 if (sig->mctx == NULL) { 172 return; 173 } 174 175 if (sig->keyring != NULL) { 176 isc_mem_free(sig->mctx, sig->keyring); 177 } 178 sig->mctx = NULL; 179 } 180 181 static isc_result_t 182 additionaldata_openpgpkey(ARGS_ADDLDATA) { 183 REQUIRE(rdata->type == dns_rdatatype_openpgpkey); 184 185 UNUSED(rdata); 186 UNUSED(owner); 187 UNUSED(add); 188 UNUSED(arg); 189 190 return ISC_R_SUCCESS; 191 } 192 193 static isc_result_t 194 digest_openpgpkey(ARGS_DIGEST) { 195 isc_region_t r; 196 197 REQUIRE(rdata->type == dns_rdatatype_openpgpkey); 198 199 dns_rdata_toregion(rdata, &r); 200 201 return (digest)(arg, &r); 202 } 203 204 static bool 205 checkowner_openpgpkey(ARGS_CHECKOWNER) { 206 REQUIRE(type == dns_rdatatype_openpgpkey); 207 208 UNUSED(name); 209 UNUSED(type); 210 UNUSED(rdclass); 211 UNUSED(wildcard); 212 213 return true; 214 } 215 216 static bool 217 checknames_openpgpkey(ARGS_CHECKNAMES) { 218 REQUIRE(rdata->type == dns_rdatatype_openpgpkey); 219 220 UNUSED(rdata); 221 UNUSED(owner); 222 UNUSED(bad); 223 224 return true; 225 } 226 227 static int 228 casecompare_openpgpkey(ARGS_COMPARE) { 229 isc_region_t r1; 230 isc_region_t r2; 231 232 REQUIRE(rdata1->type == rdata2->type); 233 REQUIRE(rdata1->rdclass == rdata2->rdclass); 234 REQUIRE(rdata1->type == dns_rdatatype_openpgpkey); 235 REQUIRE(rdata1->length != 0); 236 REQUIRE(rdata2->length != 0); 237 238 dns_rdata_toregion(rdata1, &r1); 239 dns_rdata_toregion(rdata2, &r2); 240 241 return isc_region_compare(&r1, &r2); 242 } 243 244 #endif /* RDATA_GENERIC_OPENPGPKEY_61_C */ 245