]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/dns/rdata/generic/sshfp_44.c
MFC 253983, 253984:
[FreeBSD/stable/9.git] / contrib / bind9 / lib / dns / rdata / generic / sshfp_44.c
1 /*
2  * Copyright (C) 2004, 2006, 2007, 2009, 2012, 2013  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id$ */
19
20 /* RFC 4255 */
21
22 #ifndef RDATA_GENERIC_SSHFP_44_C
23 #define RDATA_GENERIC_SSHFP_44_C
24
25 #define RRTYPE_SSHFP_ATTRIBUTES (0)
26
27 static inline isc_result_t
28 fromtext_sshfp(ARGS_FROMTEXT) {
29         isc_token_t token;
30
31         REQUIRE(type == 44);
32
33         UNUSED(type);
34         UNUSED(rdclass);
35         UNUSED(origin);
36         UNUSED(options);
37         UNUSED(callbacks);
38
39         /*
40          * Algorithm.
41          */
42         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
43                                       ISC_FALSE));
44         if (token.value.as_ulong > 0xffU)
45                 RETTOK(ISC_R_RANGE);
46         RETERR(uint8_tobuffer(token.value.as_ulong, target));
47
48         /*
49          * Digest type.
50          */
51         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
52                                       ISC_FALSE));
53         if (token.value.as_ulong > 0xffU)
54                 RETTOK(ISC_R_RANGE);
55         RETERR(uint8_tobuffer(token.value.as_ulong, target));
56
57         /*
58          * Digest.
59          */
60         return (isc_hex_tobuffer(lexer, target, -1));
61 }
62
63 static inline isc_result_t
64 totext_sshfp(ARGS_TOTEXT) {
65         isc_region_t sr;
66         char buf[sizeof("64000 ")];
67         unsigned int n;
68
69         REQUIRE(rdata->type == 44);
70         REQUIRE(rdata->length != 0);
71
72         UNUSED(tctx);
73
74         dns_rdata_toregion(rdata, &sr);
75
76         /*
77          * Algorithm.
78          */
79         n = uint8_fromregion(&sr);
80         isc_region_consume(&sr, 1);
81         sprintf(buf, "%u ", n);
82         RETERR(str_totext(buf, target));
83
84         /*
85          * Digest type.
86          */
87         n = uint8_fromregion(&sr);
88         isc_region_consume(&sr, 1);
89         sprintf(buf, "%u", n);
90         RETERR(str_totext(buf, target));
91
92         /*
93          * Digest.
94          */
95         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
96                 RETERR(str_totext(" (", target));
97         RETERR(str_totext(tctx->linebreak, target));
98         RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
99         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
100                 RETERR(str_totext(" )", target));
101         return (ISC_R_SUCCESS);
102 }
103
104 static inline isc_result_t
105 fromwire_sshfp(ARGS_FROMWIRE) {
106         isc_region_t sr;
107
108         REQUIRE(type == 44);
109
110         UNUSED(type);
111         UNUSED(rdclass);
112         UNUSED(dctx);
113         UNUSED(options);
114
115         isc_buffer_activeregion(source, &sr);
116         if (sr.length < 4)
117                 return (ISC_R_UNEXPECTEDEND);
118
119         isc_buffer_forward(source, sr.length);
120         return (mem_tobuffer(target, sr.base, sr.length));
121 }
122
123 static inline isc_result_t
124 towire_sshfp(ARGS_TOWIRE) {
125         isc_region_t sr;
126
127         REQUIRE(rdata->type == 44);
128         REQUIRE(rdata->length != 0);
129
130         UNUSED(cctx);
131
132         dns_rdata_toregion(rdata, &sr);
133         return (mem_tobuffer(target, sr.base, sr.length));
134 }
135
136 static inline int
137 compare_sshfp(ARGS_COMPARE) {
138         isc_region_t r1;
139         isc_region_t r2;
140
141         REQUIRE(rdata1->type == rdata2->type);
142         REQUIRE(rdata1->rdclass == rdata2->rdclass);
143         REQUIRE(rdata1->type == 44);
144         REQUIRE(rdata1->length != 0);
145         REQUIRE(rdata2->length != 0);
146
147         dns_rdata_toregion(rdata1, &r1);
148         dns_rdata_toregion(rdata2, &r2);
149         return (isc_region_compare(&r1, &r2));
150 }
151
152 static inline isc_result_t
153 fromstruct_sshfp(ARGS_FROMSTRUCT) {
154         dns_rdata_sshfp_t *sshfp = source;
155
156         REQUIRE(type == 44);
157         REQUIRE(source != NULL);
158         REQUIRE(sshfp->common.rdtype == type);
159         REQUIRE(sshfp->common.rdclass == rdclass);
160
161         UNUSED(type);
162         UNUSED(rdclass);
163
164         RETERR(uint8_tobuffer(sshfp->algorithm, target));
165         RETERR(uint8_tobuffer(sshfp->digest_type, target));
166
167         return (mem_tobuffer(target, sshfp->digest, sshfp->length));
168 }
169
170 static inline isc_result_t
171 tostruct_sshfp(ARGS_TOSTRUCT) {
172         dns_rdata_sshfp_t *sshfp = target;
173         isc_region_t region;
174
175         REQUIRE(rdata->type == 44);
176         REQUIRE(target != NULL);
177         REQUIRE(rdata->length != 0);
178
179         sshfp->common.rdclass = rdata->rdclass;
180         sshfp->common.rdtype = rdata->type;
181         ISC_LINK_INIT(&sshfp->common, link);
182
183         dns_rdata_toregion(rdata, &region);
184
185         sshfp->algorithm = uint8_fromregion(&region);
186         isc_region_consume(&region, 1);
187         sshfp->digest_type = uint8_fromregion(&region);
188         isc_region_consume(&region, 1);
189         sshfp->length = region.length;
190
191         sshfp->digest = mem_maybedup(mctx, region.base, region.length);
192         if (sshfp->digest == NULL)
193                 return (ISC_R_NOMEMORY);
194
195         sshfp->mctx = mctx;
196         return (ISC_R_SUCCESS);
197 }
198
199 static inline void
200 freestruct_sshfp(ARGS_FREESTRUCT) {
201         dns_rdata_sshfp_t *sshfp = source;
202
203         REQUIRE(sshfp != NULL);
204         REQUIRE(sshfp->common.rdtype == 44);
205
206         if (sshfp->mctx == NULL)
207                 return;
208
209         if (sshfp->digest != NULL)
210                 isc_mem_free(sshfp->mctx, sshfp->digest);
211         sshfp->mctx = NULL;
212 }
213
214 static inline isc_result_t
215 additionaldata_sshfp(ARGS_ADDLDATA) {
216         REQUIRE(rdata->type == 44);
217
218         UNUSED(rdata);
219         UNUSED(add);
220         UNUSED(arg);
221
222         return (ISC_R_SUCCESS);
223 }
224
225 static inline isc_result_t
226 digest_sshfp(ARGS_DIGEST) {
227         isc_region_t r;
228
229         REQUIRE(rdata->type == 44);
230
231         dns_rdata_toregion(rdata, &r);
232
233         return ((digest)(arg, &r));
234 }
235
236 static inline isc_boolean_t
237 checkowner_sshfp(ARGS_CHECKOWNER) {
238
239         REQUIRE(type == 44);
240
241         UNUSED(name);
242         UNUSED(type);
243         UNUSED(rdclass);
244         UNUSED(wildcard);
245
246         return (ISC_TRUE);
247 }
248
249 static inline isc_boolean_t
250 checknames_sshfp(ARGS_CHECKNAMES) {
251
252         REQUIRE(rdata->type == 44);
253
254         UNUSED(rdata);
255         UNUSED(owner);
256         UNUSED(bad);
257
258         return (ISC_TRUE);
259 }
260
261 static inline int
262 casecompare_sshfp(ARGS_COMPARE) {
263         return (compare_sshfp(rdata1, rdata2));
264 }
265
266 #endif  /* RDATA_GENERIC_SSHFP_44_C */