/src/bind9/lib/dns/rdata/generic/openpgpkey_61.c
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef RDATA_GENERIC_OPENPGPKEY_61_C |
15 | | #define RDATA_GENERIC_OPENPGPKEY_61_C |
16 | | |
17 | 58.1k | #define RRTYPE_OPENPGPKEY_ATTRIBUTES 0 |
18 | | |
19 | | static isc_result_t |
20 | 777 | fromtext_openpgpkey(ARGS_FROMTEXT) { |
21 | 777 | REQUIRE(type == dns_rdatatype_openpgpkey); |
22 | | |
23 | 777 | UNUSED(type); |
24 | 777 | UNUSED(rdclass); |
25 | 777 | UNUSED(callbacks); |
26 | 777 | UNUSED(options); |
27 | 777 | UNUSED(origin); |
28 | | |
29 | | /* |
30 | | * Keyring. |
31 | | */ |
32 | 777 | return isc_base64_tobuffer(lexer, target, -2); |
33 | 777 | } |
34 | | |
35 | | static isc_result_t |
36 | 1.20k | totext_openpgpkey(ARGS_TOTEXT) { |
37 | 1.20k | isc_region_t sr; |
38 | | |
39 | 1.20k | REQUIRE(rdata->type == dns_rdatatype_openpgpkey); |
40 | 1.20k | REQUIRE(rdata->length != 0); |
41 | | |
42 | 1.20k | dns_rdata_toregion(rdata, &sr); |
43 | | |
44 | | /* |
45 | | * Keyring |
46 | | */ |
47 | 1.20k | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
48 | 39 | RETERR(str_totext("( ", target)); |
49 | 39 | } |
50 | | |
51 | 1.20k | if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) { |
52 | 1.20k | if (tctx->width == 0) { /* No splitting */ |
53 | 0 | RETERR(isc_base64_totext(&sr, 60, "", target)); |
54 | 1.20k | } else { |
55 | 1.20k | RETERR(isc_base64_totext(&sr, tctx->width - 2, |
56 | 1.20k | tctx->linebreak, target)); |
57 | 1.20k | } |
58 | 1.20k | } else { |
59 | 0 | RETERR(str_totext("[omitted]", target)); |
60 | 0 | } |
61 | | |
62 | 1.20k | if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { |
63 | 39 | RETERR(str_totext(" )", target)); |
64 | 39 | } |
65 | | |
66 | 1.20k | return ISC_R_SUCCESS; |
67 | 1.20k | } |
68 | | |
69 | | static isc_result_t |
70 | 13.4k | fromwire_openpgpkey(ARGS_FROMWIRE) { |
71 | 13.4k | isc_region_t sr; |
72 | | |
73 | 13.4k | REQUIRE(type == dns_rdatatype_openpgpkey); |
74 | | |
75 | 13.4k | UNUSED(type); |
76 | 13.4k | UNUSED(rdclass); |
77 | 13.4k | UNUSED(dctx); |
78 | | |
79 | | /* |
80 | | * Keyring. |
81 | | */ |
82 | 13.4k | isc_buffer_activeregion(source, &sr); |
83 | 13.4k | if (sr.length < 1) { |
84 | 5 | return ISC_R_UNEXPECTEDEND; |
85 | 5 | } |
86 | 13.4k | isc_buffer_forward(source, sr.length); |
87 | 13.4k | return mem_tobuffer(target, sr.base, sr.length); |
88 | 13.4k | } |
89 | | |
90 | | static isc_result_t |
91 | 608 | towire_openpgpkey(ARGS_TOWIRE) { |
92 | 608 | isc_region_t sr; |
93 | | |
94 | 608 | REQUIRE(rdata->type == dns_rdatatype_openpgpkey); |
95 | 608 | REQUIRE(rdata->length != 0); |
96 | | |
97 | 608 | UNUSED(cctx); |
98 | | |
99 | 608 | dns_rdata_toregion(rdata, &sr); |
100 | 608 | return mem_tobuffer(target, sr.base, sr.length); |
101 | 608 | } |
102 | | |
103 | | static int |
104 | 24.6k | compare_openpgpkey(ARGS_COMPARE) { |
105 | 24.6k | isc_region_t r1; |
106 | 24.6k | isc_region_t r2; |
107 | | |
108 | 24.6k | REQUIRE(rdata1->type == rdata2->type); |
109 | 24.6k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
110 | 24.6k | REQUIRE(rdata1->type == dns_rdatatype_openpgpkey); |
111 | 24.6k | REQUIRE(rdata1->length != 0); |
112 | 24.6k | REQUIRE(rdata2->length != 0); |
113 | | |
114 | 24.6k | dns_rdata_toregion(rdata1, &r1); |
115 | 24.6k | dns_rdata_toregion(rdata2, &r2); |
116 | 24.6k | return isc_region_compare(&r1, &r2); |
117 | 24.6k | } |
118 | | |
119 | | static isc_result_t |
120 | 0 | fromstruct_openpgpkey(ARGS_FROMSTRUCT) { |
121 | 0 | dns_rdata_openpgpkey_t *sig = source; |
122 | |
|
123 | 0 | REQUIRE(type == dns_rdatatype_openpgpkey); |
124 | 0 | REQUIRE(sig != NULL); |
125 | 0 | REQUIRE(sig->common.rdtype == type); |
126 | 0 | REQUIRE(sig->common.rdclass == rdclass); |
127 | 0 | REQUIRE(sig->keyring != NULL && sig->length != 0); |
128 | |
|
129 | 0 | UNUSED(type); |
130 | 0 | UNUSED(rdclass); |
131 | | |
132 | | /* |
133 | | * Keyring. |
134 | | */ |
135 | 0 | return mem_tobuffer(target, sig->keyring, sig->length); |
136 | 0 | } |
137 | | |
138 | | static isc_result_t |
139 | 0 | tostruct_openpgpkey(ARGS_TOSTRUCT) { |
140 | 0 | isc_region_t sr; |
141 | 0 | dns_rdata_openpgpkey_t *sig = target; |
142 | |
|
143 | 0 | REQUIRE(rdata->type == dns_rdatatype_openpgpkey); |
144 | 0 | REQUIRE(sig != NULL); |
145 | 0 | REQUIRE(rdata->length != 0); |
146 | |
|
147 | 0 | sig->common.rdclass = rdata->rdclass; |
148 | 0 | sig->common.rdtype = rdata->type; |
149 | |
|
150 | 0 | dns_rdata_toregion(rdata, &sr); |
151 | | |
152 | | /* |
153 | | * Keyring. |
154 | | */ |
155 | 0 | sig->length = sr.length; |
156 | 0 | sig->keyring = mem_maybedup(mctx, sr.base, sig->length); |
157 | 0 | sig->mctx = mctx; |
158 | 0 | return ISC_R_SUCCESS; |
159 | 0 | } |
160 | | |
161 | | static void |
162 | 0 | freestruct_openpgpkey(ARGS_FREESTRUCT) { |
163 | 0 | dns_rdata_openpgpkey_t *sig = (dns_rdata_openpgpkey_t *)source; |
164 | |
|
165 | 0 | REQUIRE(sig != NULL); |
166 | 0 | REQUIRE(sig->common.rdtype == dns_rdatatype_openpgpkey); |
167 | |
|
168 | 0 | if (sig->mctx == NULL) { |
169 | 0 | return; |
170 | 0 | } |
171 | | |
172 | 0 | if (sig->keyring != NULL) { |
173 | 0 | isc_mem_free(sig->mctx, sig->keyring); |
174 | 0 | } |
175 | 0 | sig->mctx = NULL; |
176 | 0 | } |
177 | | |
178 | | static isc_result_t |
179 | 0 | additionaldata_openpgpkey(ARGS_ADDLDATA) { |
180 | 0 | REQUIRE(rdata->type == dns_rdatatype_openpgpkey); |
181 | |
|
182 | 0 | UNUSED(rdata); |
183 | 0 | UNUSED(owner); |
184 | 0 | UNUSED(add); |
185 | 0 | UNUSED(arg); |
186 | |
|
187 | 0 | return ISC_R_SUCCESS; |
188 | 0 | } |
189 | | |
190 | | static isc_result_t |
191 | 0 | digest_openpgpkey(ARGS_DIGEST) { |
192 | 0 | isc_region_t r; |
193 | |
|
194 | 0 | REQUIRE(rdata->type == dns_rdatatype_openpgpkey); |
195 | |
|
196 | 0 | dns_rdata_toregion(rdata, &r); |
197 | |
|
198 | 0 | return (digest)(arg, &r); |
199 | 0 | } |
200 | | |
201 | | static bool |
202 | 0 | checkowner_openpgpkey(ARGS_CHECKOWNER) { |
203 | 0 | REQUIRE(type == dns_rdatatype_openpgpkey); |
204 | |
|
205 | 0 | UNUSED(name); |
206 | 0 | UNUSED(type); |
207 | 0 | UNUSED(rdclass); |
208 | 0 | UNUSED(wildcard); |
209 | |
|
210 | 0 | return true; |
211 | 0 | } |
212 | | |
213 | | static bool |
214 | 0 | checknames_openpgpkey(ARGS_CHECKNAMES) { |
215 | 0 | REQUIRE(rdata->type == dns_rdatatype_openpgpkey); |
216 | |
|
217 | 0 | UNUSED(rdata); |
218 | 0 | UNUSED(owner); |
219 | 0 | UNUSED(bad); |
220 | |
|
221 | 0 | return true; |
222 | 0 | } |
223 | | |
224 | | static int |
225 | 0 | casecompare_openpgpkey(ARGS_COMPARE) { |
226 | 0 | isc_region_t r1; |
227 | 0 | isc_region_t r2; |
228 | |
|
229 | 0 | REQUIRE(rdata1->type == rdata2->type); |
230 | 0 | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
231 | 0 | REQUIRE(rdata1->type == dns_rdatatype_openpgpkey); |
232 | 0 | REQUIRE(rdata1->length != 0); |
233 | 0 | REQUIRE(rdata2->length != 0); |
234 | |
|
235 | 0 | dns_rdata_toregion(rdata1, &r1); |
236 | 0 | dns_rdata_toregion(rdata2, &r2); |
237 | |
|
238 | 0 | return isc_region_compare(&r1, &r2); |
239 | 0 | } |
240 | | |
241 | | #endif /* RDATA_GENERIC_OPENPGPKEY_61_C */ |