1 /* $NetBSD: dnskey_48.c,v 1.9 2025/01/26 16:25:30 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 /* RFC2535 */ 17 18 #ifndef RDATA_GENERIC_DNSKEY_48_C 19 #define RDATA_GENERIC_DNSKEY_48_C 20 21 #include <dst/dst.h> 22 23 #define RRTYPE_DNSKEY_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC) 24 25 static isc_result_t 26 fromtext_dnskey(ARGS_FROMTEXT) { 27 REQUIRE(type == dns_rdatatype_dnskey); 28 29 return generic_fromtext_key(CALL_FROMTEXT); 30 } 31 32 static isc_result_t 33 totext_dnskey(ARGS_TOTEXT) { 34 REQUIRE(rdata != NULL); 35 REQUIRE(rdata->type == dns_rdatatype_dnskey); 36 37 return generic_totext_key(CALL_TOTEXT); 38 } 39 40 static isc_result_t 41 fromwire_dnskey(ARGS_FROMWIRE) { 42 REQUIRE(type == dns_rdatatype_dnskey); 43 44 return generic_fromwire_key(CALL_FROMWIRE); 45 } 46 47 static isc_result_t 48 towire_dnskey(ARGS_TOWIRE) { 49 isc_region_t sr; 50 51 REQUIRE(rdata != NULL); 52 REQUIRE(rdata->type == dns_rdatatype_dnskey); 53 REQUIRE(rdata->length != 0); 54 55 UNUSED(cctx); 56 57 dns_rdata_toregion(rdata, &sr); 58 return mem_tobuffer(target, sr.base, sr.length); 59 } 60 61 static int 62 compare_dnskey(ARGS_COMPARE) { 63 isc_region_t r1; 64 isc_region_t r2; 65 66 REQUIRE(rdata1 != NULL); 67 REQUIRE(rdata2 != NULL); 68 REQUIRE(rdata1->type == rdata2->type); 69 REQUIRE(rdata1->rdclass == rdata2->rdclass); 70 REQUIRE(rdata1->type == dns_rdatatype_dnskey); 71 REQUIRE(rdata1->length != 0); 72 REQUIRE(rdata2->length != 0); 73 74 dns_rdata_toregion(rdata1, &r1); 75 dns_rdata_toregion(rdata2, &r2); 76 return isc_region_compare(&r1, &r2); 77 } 78 79 static isc_result_t 80 fromstruct_dnskey(ARGS_FROMSTRUCT) { 81 REQUIRE(type == dns_rdatatype_dnskey); 82 83 return generic_fromstruct_key(CALL_FROMSTRUCT); 84 } 85 86 static isc_result_t 87 tostruct_dnskey(ARGS_TOSTRUCT) { 88 dns_rdata_dnskey_t *dnskey = target; 89 90 REQUIRE(dnskey != NULL); 91 REQUIRE(rdata != NULL); 92 REQUIRE(rdata->type == dns_rdatatype_dnskey); 93 94 dnskey->common.rdclass = rdata->rdclass; 95 dnskey->common.rdtype = rdata->type; 96 ISC_LINK_INIT(&dnskey->common, link); 97 98 return generic_tostruct_key(CALL_TOSTRUCT); 99 } 100 101 static void 102 freestruct_dnskey(ARGS_FREESTRUCT) { 103 dns_rdata_dnskey_t *dnskey = (dns_rdata_dnskey_t *)source; 104 105 REQUIRE(dnskey != NULL); 106 REQUIRE(dnskey->common.rdtype == dns_rdatatype_dnskey); 107 108 generic_freestruct_key(source); 109 } 110 111 static isc_result_t 112 additionaldata_dnskey(ARGS_ADDLDATA) { 113 REQUIRE(rdata->type == dns_rdatatype_dnskey); 114 115 UNUSED(rdata); 116 UNUSED(owner); 117 UNUSED(add); 118 UNUSED(arg); 119 120 return ISC_R_SUCCESS; 121 } 122 123 static isc_result_t 124 digest_dnskey(ARGS_DIGEST) { 125 isc_region_t r; 126 127 REQUIRE(rdata != NULL); 128 REQUIRE(rdata->type == dns_rdatatype_dnskey); 129 130 dns_rdata_toregion(rdata, &r); 131 132 return (digest)(arg, &r); 133 } 134 135 static bool 136 checkowner_dnskey(ARGS_CHECKOWNER) { 137 REQUIRE(type == dns_rdatatype_dnskey); 138 139 UNUSED(name); 140 UNUSED(type); 141 UNUSED(rdclass); 142 UNUSED(wildcard); 143 144 return true; 145 } 146 147 static bool 148 checknames_dnskey(ARGS_CHECKNAMES) { 149 REQUIRE(rdata != NULL); 150 REQUIRE(rdata->type == dns_rdatatype_dnskey); 151 152 UNUSED(rdata); 153 UNUSED(owner); 154 UNUSED(bad); 155 156 return true; 157 } 158 159 static int 160 casecompare_dnskey(ARGS_COMPARE) { 161 /* 162 * Treat ALG 253 (private DNS) subtype name case sensitively. 163 */ 164 return compare_dnskey(rdata1, rdata2); 165 } 166 167 #endif /* RDATA_GENERIC_DNSKEY_48_C */ 168