1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * SPDX-License-Identifier: MPL-2.0
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * See the COPYRIGHT file distributed with this work for additional
11 * information regarding copyright ownership.
12 */
13
14 /* RFC2535 */
15
16 #ifndef RDATA_GENERIC_DNSKEY_48_C
17 #define RDATA_GENERIC_DNSKEY_48_C
18
19 #include <dst/dst.h>
20
21 #define RRTYPE_DNSKEY_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
22
23 static inline isc_result_t
fromtext_dnskey(ARGS_FROMTEXT)24 fromtext_dnskey(ARGS_FROMTEXT) {
25 REQUIRE(type == dns_rdatatype_dnskey);
26
27 return (generic_fromtext_key(CALL_FROMTEXT));
28 }
29
30 static inline isc_result_t
totext_dnskey(ARGS_TOTEXT)31 totext_dnskey(ARGS_TOTEXT) {
32 REQUIRE(rdata != NULL);
33 REQUIRE(rdata->type == dns_rdatatype_dnskey);
34
35 return (generic_totext_key(CALL_TOTEXT));
36 }
37
38 static inline isc_result_t
fromwire_dnskey(ARGS_FROMWIRE)39 fromwire_dnskey(ARGS_FROMWIRE) {
40 REQUIRE(type == dns_rdatatype_dnskey);
41
42 return (generic_fromwire_key(CALL_FROMWIRE));
43 }
44
45 static inline isc_result_t
towire_dnskey(ARGS_TOWIRE)46 towire_dnskey(ARGS_TOWIRE) {
47 isc_region_t sr;
48
49 REQUIRE(rdata != NULL);
50 REQUIRE(rdata->type == dns_rdatatype_dnskey);
51 REQUIRE(rdata->length != 0);
52
53 UNUSED(cctx);
54
55 dns_rdata_toregion(rdata, &sr);
56 return (mem_tobuffer(target, sr.base, sr.length));
57 }
58
59 static inline int
compare_dnskey(ARGS_COMPARE)60 compare_dnskey(ARGS_COMPARE) {
61 isc_region_t r1;
62 isc_region_t r2;
63
64 REQUIRE(rdata1 != NULL);
65 REQUIRE(rdata2 != NULL);
66 REQUIRE(rdata1->type == rdata2->type);
67 REQUIRE(rdata1->rdclass == rdata2->rdclass);
68 REQUIRE(rdata1->type == dns_rdatatype_dnskey);
69 REQUIRE(rdata1->length != 0);
70 REQUIRE(rdata2->length != 0);
71
72 dns_rdata_toregion(rdata1, &r1);
73 dns_rdata_toregion(rdata2, &r2);
74 return (isc_region_compare(&r1, &r2));
75 }
76
77 static inline isc_result_t
fromstruct_dnskey(ARGS_FROMSTRUCT)78 fromstruct_dnskey(ARGS_FROMSTRUCT) {
79 REQUIRE(type == dns_rdatatype_dnskey);
80
81 return (generic_fromstruct_key(CALL_FROMSTRUCT));
82 }
83
84 static inline isc_result_t
tostruct_dnskey(ARGS_TOSTRUCT)85 tostruct_dnskey(ARGS_TOSTRUCT) {
86 dns_rdata_dnskey_t *dnskey = target;
87
88 REQUIRE(dnskey != NULL);
89 REQUIRE(rdata != NULL);
90 REQUIRE(rdata->type == dns_rdatatype_dnskey);
91
92 dnskey->common.rdclass = rdata->rdclass;
93 dnskey->common.rdtype = rdata->type;
94 ISC_LINK_INIT(&dnskey->common, link);
95
96 return (generic_tostruct_key(CALL_TOSTRUCT));
97 }
98
99 static inline void
freestruct_dnskey(ARGS_FREESTRUCT)100 freestruct_dnskey(ARGS_FREESTRUCT) {
101 dns_rdata_dnskey_t *dnskey = (dns_rdata_dnskey_t *)source;
102
103 REQUIRE(dnskey != NULL);
104 REQUIRE(dnskey->common.rdtype == dns_rdatatype_dnskey);
105
106 generic_freestruct_key(source);
107 }
108
109 static inline isc_result_t
additionaldata_dnskey(ARGS_ADDLDATA)110 additionaldata_dnskey(ARGS_ADDLDATA) {
111 REQUIRE(rdata->type == dns_rdatatype_dnskey);
112
113 UNUSED(rdata);
114 UNUSED(add);
115 UNUSED(arg);
116
117 return (ISC_R_SUCCESS);
118 }
119
120 static inline isc_result_t
digest_dnskey(ARGS_DIGEST)121 digest_dnskey(ARGS_DIGEST) {
122 isc_region_t r;
123
124 REQUIRE(rdata != NULL);
125 REQUIRE(rdata->type == dns_rdatatype_dnskey);
126
127 dns_rdata_toregion(rdata, &r);
128
129 return ((digest)(arg, &r));
130 }
131
132 static inline bool
checkowner_dnskey(ARGS_CHECKOWNER)133 checkowner_dnskey(ARGS_CHECKOWNER) {
134 REQUIRE(type == dns_rdatatype_dnskey);
135
136 UNUSED(name);
137 UNUSED(type);
138 UNUSED(rdclass);
139 UNUSED(wildcard);
140
141 return (true);
142 }
143
144 static inline bool
checknames_dnskey(ARGS_CHECKNAMES)145 checknames_dnskey(ARGS_CHECKNAMES) {
146 REQUIRE(rdata != NULL);
147 REQUIRE(rdata->type == dns_rdatatype_dnskey);
148
149 UNUSED(rdata);
150 UNUSED(owner);
151 UNUSED(bad);
152
153 return (true);
154 }
155
156 static inline int
casecompare_dnskey(ARGS_COMPARE)157 casecompare_dnskey(ARGS_COMPARE) {
158 /*
159 * Treat ALG 253 (private DNS) subtype name case sensitively.
160 */
161 return (compare_dnskey(rdata1, rdata2));
162 }
163
164 #endif /* RDATA_GENERIC_DNSKEY_48_C */
165