1 /* $NetBSD: openpgpkey_61.c,v 1.1 2024/02/18 20:57:44 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
fromtext_openpgpkey(ARGS_FROMTEXT)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
totext_openpgpkey(ARGS_TOTEXT)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
fromwire_openpgpkey(ARGS_FROMWIRE)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 UNUSED(options);
81
82 /*
83 * Keyring.
84 */
85 isc_buffer_activeregion(source, &sr);
86 if (sr.length < 1) {
87 return (ISC_R_UNEXPECTEDEND);
88 }
89 isc_buffer_forward(source, sr.length);
90 return (mem_tobuffer(target, sr.base, sr.length));
91 }
92
93 static isc_result_t
towire_openpgpkey(ARGS_TOWIRE)94 towire_openpgpkey(ARGS_TOWIRE) {
95 isc_region_t sr;
96
97 REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
98 REQUIRE(rdata->length != 0);
99
100 UNUSED(cctx);
101
102 dns_rdata_toregion(rdata, &sr);
103 return (mem_tobuffer(target, sr.base, sr.length));
104 }
105
106 static int
compare_openpgpkey(ARGS_COMPARE)107 compare_openpgpkey(ARGS_COMPARE) {
108 isc_region_t r1;
109 isc_region_t r2;
110
111 REQUIRE(rdata1->type == rdata2->type);
112 REQUIRE(rdata1->rdclass == rdata2->rdclass);
113 REQUIRE(rdata1->type == dns_rdatatype_openpgpkey);
114 REQUIRE(rdata1->length != 0);
115 REQUIRE(rdata2->length != 0);
116
117 dns_rdata_toregion(rdata1, &r1);
118 dns_rdata_toregion(rdata2, &r2);
119 return (isc_region_compare(&r1, &r2));
120 }
121
122 static isc_result_t
fromstruct_openpgpkey(ARGS_FROMSTRUCT)123 fromstruct_openpgpkey(ARGS_FROMSTRUCT) {
124 dns_rdata_openpgpkey_t *sig = source;
125
126 REQUIRE(type == dns_rdatatype_openpgpkey);
127 REQUIRE(sig != NULL);
128 REQUIRE(sig->common.rdtype == type);
129 REQUIRE(sig->common.rdclass == rdclass);
130 REQUIRE(sig->keyring != NULL && sig->length != 0);
131
132 UNUSED(type);
133 UNUSED(rdclass);
134
135 /*
136 * Keyring.
137 */
138 return (mem_tobuffer(target, sig->keyring, sig->length));
139 }
140
141 static isc_result_t
tostruct_openpgpkey(ARGS_TOSTRUCT)142 tostruct_openpgpkey(ARGS_TOSTRUCT) {
143 isc_region_t sr;
144 dns_rdata_openpgpkey_t *sig = target;
145
146 REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
147 REQUIRE(sig != NULL);
148 REQUIRE(rdata->length != 0);
149
150 sig->common.rdclass = rdata->rdclass;
151 sig->common.rdtype = rdata->type;
152 ISC_LINK_INIT(&sig->common, link);
153
154 dns_rdata_toregion(rdata, &sr);
155
156 /*
157 * Keyring.
158 */
159 sig->length = sr.length;
160 sig->keyring = mem_maybedup(mctx, sr.base, sig->length);
161 if (sig->keyring == NULL) {
162 goto cleanup;
163 }
164
165 sig->mctx = mctx;
166 return (ISC_R_SUCCESS);
167
168 cleanup:
169 return (ISC_R_NOMEMORY);
170 }
171
172 static void
freestruct_openpgpkey(ARGS_FREESTRUCT)173 freestruct_openpgpkey(ARGS_FREESTRUCT) {
174 dns_rdata_openpgpkey_t *sig = (dns_rdata_openpgpkey_t *)source;
175
176 REQUIRE(sig != NULL);
177 REQUIRE(sig->common.rdtype == dns_rdatatype_openpgpkey);
178
179 if (sig->mctx == NULL) {
180 return;
181 }
182
183 if (sig->keyring != NULL) {
184 isc_mem_free(sig->mctx, sig->keyring);
185 }
186 sig->mctx = NULL;
187 }
188
189 static isc_result_t
additionaldata_openpgpkey(ARGS_ADDLDATA)190 additionaldata_openpgpkey(ARGS_ADDLDATA) {
191 REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
192
193 UNUSED(rdata);
194 UNUSED(add);
195 UNUSED(arg);
196
197 return (ISC_R_SUCCESS);
198 }
199
200 static isc_result_t
digest_openpgpkey(ARGS_DIGEST)201 digest_openpgpkey(ARGS_DIGEST) {
202 isc_region_t r;
203
204 REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
205
206 dns_rdata_toregion(rdata, &r);
207
208 return ((digest)(arg, &r));
209 }
210
211 static bool
checkowner_openpgpkey(ARGS_CHECKOWNER)212 checkowner_openpgpkey(ARGS_CHECKOWNER) {
213 REQUIRE(type == dns_rdatatype_openpgpkey);
214
215 UNUSED(name);
216 UNUSED(type);
217 UNUSED(rdclass);
218 UNUSED(wildcard);
219
220 return (true);
221 }
222
223 static bool
checknames_openpgpkey(ARGS_CHECKNAMES)224 checknames_openpgpkey(ARGS_CHECKNAMES) {
225 REQUIRE(rdata->type == dns_rdatatype_openpgpkey);
226
227 UNUSED(rdata);
228 UNUSED(owner);
229 UNUSED(bad);
230
231 return (true);
232 }
233
234 static int
casecompare_openpgpkey(ARGS_COMPARE)235 casecompare_openpgpkey(ARGS_COMPARE) {
236 isc_region_t r1;
237 isc_region_t r2;
238
239 REQUIRE(rdata1->type == rdata2->type);
240 REQUIRE(rdata1->rdclass == rdata2->rdclass);
241 REQUIRE(rdata1->type == dns_rdatatype_openpgpkey);
242 REQUIRE(rdata1->length != 0);
243 REQUIRE(rdata2->length != 0);
244
245 dns_rdata_toregion(rdata1, &r1);
246 dns_rdata_toregion(rdata2, &r2);
247
248 return (isc_region_compare(&r1, &r2));
249 }
250
251 #endif /* RDATA_GENERIC_OPENPGPKEY_61_C */
252