]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/dns/rdata/generic/openpgpkey_61.c
Update BIND to 9.9.7.
[FreeBSD/stable/9.git] / contrib / bind9 / lib / dns / rdata / generic / openpgpkey_61.c
1 /*
2  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14  * PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef RDATA_GENERIC_OPENPGPKEY_61_C
18 #define RDATA_GENERIC_OPENPGPKEY_61_C
19
20 #define RRTYPE_OPENPGPKEY_ATTRIBUTES 0
21
22 static inline isc_result_t
23 fromtext_openpgpkey(ARGS_FROMTEXT) {
24
25         REQUIRE(type == 61);
26
27         UNUSED(type);
28         UNUSED(rdclass);
29         UNUSED(callbacks);
30         UNUSED(options);
31         UNUSED(origin);
32
33         /*
34          * Keyring.
35          */
36         return (isc_base64_tobuffer(lexer, target, -1));
37 }
38
39 static inline isc_result_t
40 totext_openpgpkey(ARGS_TOTEXT) {
41         isc_region_t sr;
42
43         REQUIRE(rdata->type == 61);
44         REQUIRE(rdata->length != 0);
45
46         dns_rdata_toregion(rdata, &sr);
47
48         /*
49          * Keyring
50          */
51         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
52                 RETERR(str_totext("( ", target));
53         if (tctx->width == 0)   /* No splitting */
54                 RETERR(isc_base64_totext(&sr, 60, "", target));
55         else
56                 RETERR(isc_base64_totext(&sr, tctx->width - 2,
57                                          tctx->linebreak, target));
58         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
59                 RETERR(str_totext(" )", target));
60
61         return (ISC_R_SUCCESS);
62 }
63
64 static inline isc_result_t
65 fromwire_openpgpkey(ARGS_FROMWIRE) {
66         isc_region_t sr;
67
68         REQUIRE(type == 61);
69
70         UNUSED(type);
71         UNUSED(rdclass);
72         UNUSED(dctx);
73         UNUSED(options);
74
75         /*
76          * Keyring.
77          */
78         isc_buffer_activeregion(source, &sr);
79         isc_buffer_forward(source, sr.length);
80         return (mem_tobuffer(target, sr.base, sr.length));
81 }
82
83 static inline isc_result_t
84 towire_openpgpkey(ARGS_TOWIRE) {
85         isc_region_t sr;
86
87         REQUIRE(rdata->type == 61);
88         REQUIRE(rdata->length != 0);
89
90         UNUSED(cctx);
91
92         dns_rdata_toregion(rdata, &sr);
93         return (mem_tobuffer(target, sr.base, sr.length));
94 }
95
96 static inline int
97 compare_openpgpkey(ARGS_COMPARE) {
98         isc_region_t r1;
99         isc_region_t r2;
100
101         REQUIRE(rdata1->type == rdata2->type);
102         REQUIRE(rdata1->rdclass == rdata2->rdclass);
103         REQUIRE(rdata1->type == 61);
104         REQUIRE(rdata1->length != 0);
105         REQUIRE(rdata2->length != 0);
106
107         dns_rdata_toregion(rdata1, &r1);
108         dns_rdata_toregion(rdata2, &r2);
109         return (isc_region_compare(&r1, &r2));
110 }
111
112 static inline isc_result_t
113 fromstruct_openpgpkey(ARGS_FROMSTRUCT) {
114         dns_rdata_openpgpkey_t *sig = source;
115
116         REQUIRE(type == 61);
117         REQUIRE(source != NULL);
118         REQUIRE(sig->common.rdtype == type);
119         REQUIRE(sig->common.rdclass == rdclass);
120         REQUIRE(sig->keyring != NULL && sig->length != 0);
121
122         UNUSED(type);
123         UNUSED(rdclass);
124
125         /*
126          * Keyring.
127          */
128         return (mem_tobuffer(target, sig->keyring, sig->length));
129 }
130
131 static inline isc_result_t
132 tostruct_openpgpkey(ARGS_TOSTRUCT) {
133         isc_region_t sr;
134         dns_rdata_openpgpkey_t *sig = target;
135
136         REQUIRE(rdata->type == 61);
137         REQUIRE(target != NULL);
138         REQUIRE(rdata->length != 0);
139
140         sig->common.rdclass = rdata->rdclass;
141         sig->common.rdtype = rdata->type;
142         ISC_LINK_INIT(&sig->common, link);
143
144         dns_rdata_toregion(rdata, &sr);
145
146         /*
147          * Keyring.
148          */
149         sig->length = sr.length;
150         sig->keyring = mem_maybedup(mctx, sr.base, sig->length);
151         if (sig->keyring == NULL)
152                 goto cleanup;
153
154         sig->mctx = mctx;
155         return (ISC_R_SUCCESS);
156
157  cleanup:
158         return (ISC_R_NOMEMORY);
159 }
160
161 static inline void
162 freestruct_openpgpkey(ARGS_FREESTRUCT) {
163         dns_rdata_openpgpkey_t *sig = (dns_rdata_openpgpkey_t *) source;
164
165         REQUIRE(source != NULL);
166         REQUIRE(sig->common.rdtype == 61);
167
168         if (sig->mctx == NULL)
169                 return;
170
171         if (sig->keyring != NULL)
172                 isc_mem_free(sig->mctx, sig->keyring);
173         sig->mctx = NULL;
174 }
175
176 static inline isc_result_t
177 additionaldata_openpgpkey(ARGS_ADDLDATA) {
178         REQUIRE(rdata->type == 61);
179
180         UNUSED(rdata);
181         UNUSED(add);
182         UNUSED(arg);
183
184         return (ISC_R_SUCCESS);
185 }
186
187 static inline isc_result_t
188 digest_openpgpkey(ARGS_DIGEST) {
189         isc_region_t r;
190
191         REQUIRE(rdata->type == 61);
192
193         dns_rdata_toregion(rdata, &r);
194
195         return ((digest)(arg, &r));
196 }
197
198 static inline isc_boolean_t
199 checkowner_openpgpkey(ARGS_CHECKOWNER) {
200
201         REQUIRE(type == 61);
202
203         UNUSED(name);
204         UNUSED(type);
205         UNUSED(rdclass);
206         UNUSED(wildcard);
207
208         return (ISC_TRUE);
209 }
210
211 static inline isc_boolean_t
212 checknames_openpgpkey(ARGS_CHECKNAMES) {
213
214         REQUIRE(rdata->type == 61);
215
216         UNUSED(rdata);
217         UNUSED(owner);
218         UNUSED(bad);
219
220         return (ISC_TRUE);
221 }
222
223 static inline int
224 casecompare_openpgpkey(ARGS_COMPARE) {
225         isc_region_t r1;
226         isc_region_t r2;
227
228         REQUIRE(rdata1->type == rdata2->type);
229         REQUIRE(rdata1->rdclass == rdata2->rdclass);
230         REQUIRE(rdata1->type == 61);
231         REQUIRE(rdata1->length != 0);
232         REQUIRE(rdata2->length != 0);
233
234         dns_rdata_toregion(rdata1, &r1);
235         dns_rdata_toregion(rdata2, &r2);
236
237         return (isc_region_compare(&r1, &r2));
238 }
239
240 #endif  /* RDATA_GENERIC_OPENPGPKEY_61_C */