Home | History | Annotate | Line # | Download | only in generic
      1 /*	$NetBSD: openpgpkey_61.c,v 1.11 2026/01/29 18:37:53 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 	DNS_RDATACOMMON_INIT(sig, rdata->type, rdata->rdclass);
    150 
    151 	dns_rdata_toregion(rdata, &sr);
    152 
    153 	/*
    154 	 * Keyring.
    155 	 */
    156 	sig->length = sr.length;
    157 	sig->keyring = mem_maybedup(mctx, sr.base, sig->length);
    158 	sig->mctx = mctx;
    159 	return ISC_R_SUCCESS;
    160 }
    161 
    162 static void
    163 freestruct_openpgpkey(ARGS_FREESTRUCT) {
    164 	dns_rdata_openpgpkey_t *sig = (dns_rdata_openpgpkey_t *)source;
    165 
    166 	REQUIRE(sig != NULL);
    167 	REQUIRE(sig->common.rdtype == dns_rdatatype_openpgpkey);
    168 
    169 	if (sig->mctx == NULL) {
    170 		return;
    171 	}
    172 
    173 	if (sig->keyring != NULL) {
    174 		isc_mem_free(sig->mctx, sig->keyring);
    175 	}
    176 	sig->mctx = NULL;
    177 }
    178 
    179 static isc_result_t
    180 additionaldata_openpgpkey(ARGS_ADDLDATA) {
    181 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
    182 
    183 	UNUSED(rdata);
    184 	UNUSED(owner);
    185 	UNUSED(add);
    186 	UNUSED(arg);
    187 
    188 	return ISC_R_SUCCESS;
    189 }
    190 
    191 static isc_result_t
    192 digest_openpgpkey(ARGS_DIGEST) {
    193 	isc_region_t r;
    194 
    195 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
    196 
    197 	dns_rdata_toregion(rdata, &r);
    198 
    199 	return (digest)(arg, &r);
    200 }
    201 
    202 static bool
    203 checkowner_openpgpkey(ARGS_CHECKOWNER) {
    204 	REQUIRE(type == dns_rdatatype_openpgpkey);
    205 
    206 	UNUSED(name);
    207 	UNUSED(type);
    208 	UNUSED(rdclass);
    209 	UNUSED(wildcard);
    210 
    211 	return true;
    212 }
    213 
    214 static bool
    215 checknames_openpgpkey(ARGS_CHECKNAMES) {
    216 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
    217 
    218 	UNUSED(rdata);
    219 	UNUSED(owner);
    220 	UNUSED(bad);
    221 
    222 	return true;
    223 }
    224 
    225 static int
    226 casecompare_openpgpkey(ARGS_COMPARE) {
    227 	isc_region_t r1;
    228 	isc_region_t r2;
    229 
    230 	REQUIRE(rdata1->type == rdata2->type);
    231 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
    232 	REQUIRE(rdata1->type == dns_rdatatype_openpgpkey);
    233 	REQUIRE(rdata1->length != 0);
    234 	REQUIRE(rdata2->length != 0);
    235 
    236 	dns_rdata_toregion(rdata1, &r1);
    237 	dns_rdata_toregion(rdata2, &r2);
    238 
    239 	return isc_region_compare(&r1, &r2);
    240 }
    241 
    242 #endif /* RDATA_GENERIC_OPENPGPKEY_61_C */
    243