Home | History | Annotate | Line # | Download | only in generic
      1  1.10  christos /*	$NetBSD: openpgpkey_61.c,v 1.11 2026/01/29 18:37:53 christos Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*
      4   1.1  christos  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5   1.1  christos  *
      6   1.8  christos  * SPDX-License-Identifier: MPL-2.0
      7   1.8  christos  *
      8   1.1  christos  * This Source Code Form is subject to the terms of the Mozilla Public
      9   1.1  christos  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10   1.7  christos  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11   1.1  christos  *
     12   1.1  christos  * See the COPYRIGHT file distributed with this work for additional
     13   1.1  christos  * information regarding copyright ownership.
     14   1.1  christos  */
     15   1.1  christos 
     16   1.1  christos #ifndef RDATA_GENERIC_OPENPGPKEY_61_C
     17   1.1  christos #define RDATA_GENERIC_OPENPGPKEY_61_C
     18   1.1  christos 
     19   1.1  christos #define RRTYPE_OPENPGPKEY_ATTRIBUTES 0
     20   1.1  christos 
     21   1.8  christos static isc_result_t
     22   1.1  christos fromtext_openpgpkey(ARGS_FROMTEXT) {
     23   1.1  christos 	REQUIRE(type == dns_rdatatype_openpgpkey);
     24   1.1  christos 
     25   1.1  christos 	UNUSED(type);
     26   1.1  christos 	UNUSED(rdclass);
     27   1.1  christos 	UNUSED(callbacks);
     28   1.1  christos 	UNUSED(options);
     29   1.1  christos 	UNUSED(origin);
     30   1.1  christos 
     31   1.1  christos 	/*
     32   1.1  christos 	 * Keyring.
     33   1.1  christos 	 */
     34  1.10  christos 	return isc_base64_tobuffer(lexer, target, -2);
     35   1.1  christos }
     36   1.1  christos 
     37   1.8  christos static isc_result_t
     38   1.1  christos totext_openpgpkey(ARGS_TOTEXT) {
     39   1.1  christos 	isc_region_t sr;
     40   1.1  christos 
     41   1.1  christos 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
     42   1.1  christos 	REQUIRE(rdata->length != 0);
     43   1.1  christos 
     44   1.1  christos 	dns_rdata_toregion(rdata, &sr);
     45   1.1  christos 
     46   1.1  christos 	/*
     47   1.1  christos 	 * Keyring
     48   1.1  christos 	 */
     49   1.6  christos 	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
     50   1.1  christos 		RETERR(str_totext("( ", target));
     51   1.6  christos 	}
     52   1.1  christos 
     53   1.1  christos 	if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) {
     54   1.6  christos 		if (tctx->width == 0) { /* No splitting */
     55   1.1  christos 			RETERR(isc_base64_totext(&sr, 60, "", target));
     56   1.6  christos 		} else {
     57   1.1  christos 			RETERR(isc_base64_totext(&sr, tctx->width - 2,
     58   1.1  christos 						 tctx->linebreak, target));
     59   1.6  christos 		}
     60   1.6  christos 	} else {
     61   1.1  christos 		RETERR(str_totext("[omitted]", target));
     62   1.6  christos 	}
     63   1.1  christos 
     64   1.6  christos 	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
     65   1.1  christos 		RETERR(str_totext(" )", target));
     66   1.6  christos 	}
     67   1.1  christos 
     68  1.10  christos 	return ISC_R_SUCCESS;
     69   1.1  christos }
     70   1.1  christos 
     71   1.8  christos static isc_result_t
     72   1.1  christos fromwire_openpgpkey(ARGS_FROMWIRE) {
     73   1.1  christos 	isc_region_t sr;
     74   1.1  christos 
     75   1.1  christos 	REQUIRE(type == dns_rdatatype_openpgpkey);
     76   1.1  christos 
     77   1.1  christos 	UNUSED(type);
     78   1.1  christos 	UNUSED(rdclass);
     79   1.1  christos 	UNUSED(dctx);
     80   1.1  christos 
     81   1.1  christos 	/*
     82   1.1  christos 	 * Keyring.
     83   1.1  christos 	 */
     84   1.1  christos 	isc_buffer_activeregion(source, &sr);
     85   1.6  christos 	if (sr.length < 1) {
     86  1.10  christos 		return ISC_R_UNEXPECTEDEND;
     87   1.6  christos 	}
     88   1.1  christos 	isc_buffer_forward(source, sr.length);
     89  1.10  christos 	return mem_tobuffer(target, sr.base, sr.length);
     90   1.1  christos }
     91   1.1  christos 
     92   1.8  christos static isc_result_t
     93   1.1  christos towire_openpgpkey(ARGS_TOWIRE) {
     94   1.1  christos 	isc_region_t sr;
     95   1.1  christos 
     96   1.1  christos 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
     97   1.1  christos 	REQUIRE(rdata->length != 0);
     98   1.1  christos 
     99   1.1  christos 	UNUSED(cctx);
    100   1.1  christos 
    101   1.1  christos 	dns_rdata_toregion(rdata, &sr);
    102  1.10  christos 	return mem_tobuffer(target, sr.base, sr.length);
    103   1.1  christos }
    104   1.1  christos 
    105   1.8  christos static int
    106   1.1  christos compare_openpgpkey(ARGS_COMPARE) {
    107   1.1  christos 	isc_region_t r1;
    108   1.1  christos 	isc_region_t r2;
    109   1.1  christos 
    110   1.1  christos 	REQUIRE(rdata1->type == rdata2->type);
    111   1.1  christos 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
    112   1.1  christos 	REQUIRE(rdata1->type == dns_rdatatype_openpgpkey);
    113   1.1  christos 	REQUIRE(rdata1->length != 0);
    114   1.1  christos 	REQUIRE(rdata2->length != 0);
    115   1.1  christos 
    116   1.1  christos 	dns_rdata_toregion(rdata1, &r1);
    117   1.1  christos 	dns_rdata_toregion(rdata2, &r2);
    118  1.10  christos 	return isc_region_compare(&r1, &r2);
    119   1.1  christos }
    120   1.1  christos 
    121   1.8  christos static isc_result_t
    122   1.1  christos fromstruct_openpgpkey(ARGS_FROMSTRUCT) {
    123   1.1  christos 	dns_rdata_openpgpkey_t *sig = source;
    124   1.1  christos 
    125   1.1  christos 	REQUIRE(type == dns_rdatatype_openpgpkey);
    126   1.5  christos 	REQUIRE(sig != NULL);
    127   1.1  christos 	REQUIRE(sig->common.rdtype == type);
    128   1.1  christos 	REQUIRE(sig->common.rdclass == rdclass);
    129   1.1  christos 	REQUIRE(sig->keyring != NULL && sig->length != 0);
    130   1.1  christos 
    131   1.1  christos 	UNUSED(type);
    132   1.1  christos 	UNUSED(rdclass);
    133   1.1  christos 
    134   1.1  christos 	/*
    135   1.1  christos 	 * Keyring.
    136   1.1  christos 	 */
    137  1.10  christos 	return mem_tobuffer(target, sig->keyring, sig->length);
    138   1.1  christos }
    139   1.1  christos 
    140   1.8  christos static isc_result_t
    141   1.1  christos tostruct_openpgpkey(ARGS_TOSTRUCT) {
    142   1.1  christos 	isc_region_t sr;
    143   1.1  christos 	dns_rdata_openpgpkey_t *sig = target;
    144   1.1  christos 
    145   1.1  christos 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
    146   1.5  christos 	REQUIRE(sig != NULL);
    147   1.1  christos 	REQUIRE(rdata->length != 0);
    148   1.1  christos 
    149  1.11  christos 	DNS_RDATACOMMON_INIT(sig, rdata->type, rdata->rdclass);
    150   1.1  christos 
    151   1.1  christos 	dns_rdata_toregion(rdata, &sr);
    152   1.1  christos 
    153   1.1  christos 	/*
    154   1.1  christos 	 * Keyring.
    155   1.1  christos 	 */
    156   1.1  christos 	sig->length = sr.length;
    157   1.1  christos 	sig->keyring = mem_maybedup(mctx, sr.base, sig->length);
    158   1.1  christos 	sig->mctx = mctx;
    159  1.10  christos 	return ISC_R_SUCCESS;
    160   1.1  christos }
    161   1.1  christos 
    162   1.8  christos static void
    163   1.1  christos freestruct_openpgpkey(ARGS_FREESTRUCT) {
    164   1.6  christos 	dns_rdata_openpgpkey_t *sig = (dns_rdata_openpgpkey_t *)source;
    165   1.1  christos 
    166   1.5  christos 	REQUIRE(sig != NULL);
    167   1.1  christos 	REQUIRE(sig->common.rdtype == dns_rdatatype_openpgpkey);
    168   1.1  christos 
    169   1.6  christos 	if (sig->mctx == NULL) {
    170   1.1  christos 		return;
    171   1.6  christos 	}
    172   1.1  christos 
    173   1.6  christos 	if (sig->keyring != NULL) {
    174   1.1  christos 		isc_mem_free(sig->mctx, sig->keyring);
    175   1.6  christos 	}
    176   1.1  christos 	sig->mctx = NULL;
    177   1.1  christos }
    178   1.1  christos 
    179   1.8  christos static isc_result_t
    180   1.1  christos additionaldata_openpgpkey(ARGS_ADDLDATA) {
    181   1.1  christos 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
    182   1.1  christos 
    183   1.1  christos 	UNUSED(rdata);
    184   1.9  christos 	UNUSED(owner);
    185   1.1  christos 	UNUSED(add);
    186   1.1  christos 	UNUSED(arg);
    187   1.1  christos 
    188  1.10  christos 	return ISC_R_SUCCESS;
    189   1.1  christos }
    190   1.1  christos 
    191   1.8  christos static isc_result_t
    192   1.1  christos digest_openpgpkey(ARGS_DIGEST) {
    193   1.1  christos 	isc_region_t r;
    194   1.1  christos 
    195   1.1  christos 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
    196   1.1  christos 
    197   1.1  christos 	dns_rdata_toregion(rdata, &r);
    198   1.1  christos 
    199  1.10  christos 	return (digest)(arg, &r);
    200   1.1  christos }
    201   1.1  christos 
    202   1.8  christos static bool
    203   1.1  christos checkowner_openpgpkey(ARGS_CHECKOWNER) {
    204   1.1  christos 	REQUIRE(type == dns_rdatatype_openpgpkey);
    205   1.1  christos 
    206   1.1  christos 	UNUSED(name);
    207   1.1  christos 	UNUSED(type);
    208   1.1  christos 	UNUSED(rdclass);
    209   1.1  christos 	UNUSED(wildcard);
    210   1.1  christos 
    211  1.10  christos 	return true;
    212   1.1  christos }
    213   1.1  christos 
    214   1.8  christos static bool
    215   1.1  christos checknames_openpgpkey(ARGS_CHECKNAMES) {
    216   1.1  christos 	REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
    217   1.1  christos 
    218   1.1  christos 	UNUSED(rdata);
    219   1.1  christos 	UNUSED(owner);
    220   1.1  christos 	UNUSED(bad);
    221   1.1  christos 
    222  1.10  christos 	return true;
    223   1.1  christos }
    224   1.1  christos 
    225   1.8  christos static int
    226   1.1  christos casecompare_openpgpkey(ARGS_COMPARE) {
    227   1.1  christos 	isc_region_t r1;
    228   1.1  christos 	isc_region_t r2;
    229   1.1  christos 
    230   1.1  christos 	REQUIRE(rdata1->type == rdata2->type);
    231   1.1  christos 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
    232   1.1  christos 	REQUIRE(rdata1->type == dns_rdatatype_openpgpkey);
    233   1.1  christos 	REQUIRE(rdata1->length != 0);
    234   1.1  christos 	REQUIRE(rdata2->length != 0);
    235   1.1  christos 
    236   1.1  christos 	dns_rdata_toregion(rdata1, &r1);
    237   1.1  christos 	dns_rdata_toregion(rdata2, &r2);
    238   1.1  christos 
    239  1.10  christos 	return isc_region_compare(&r1, &r2);
    240   1.1  christos }
    241   1.1  christos 
    242   1.6  christos #endif /* RDATA_GENERIC_OPENPGPKEY_61_C */
    243