Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / sshfp_44.c
blobff7cfd632f1d3bdeac2472cbee821c1032bfe216
1 /* $NetBSD: sshfp_44.c,v 1.6 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2006, 2007, 2009, 2011-2013 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id */
22 /* RFC 4255 */
24 #ifndef RDATA_GENERIC_SSHFP_44_C
25 #define RDATA_GENERIC_SSHFP_44_C
27 #define RRTYPE_SSHFP_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_sshfp(ARGS_FROMTEXT) {
31 isc_token_t token;
33 REQUIRE(type == 44);
35 UNUSED(type);
36 UNUSED(rdclass);
37 UNUSED(origin);
38 UNUSED(options);
39 UNUSED(callbacks);
42 * Algorithm.
44 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45 ISC_FALSE));
46 if (token.value.as_ulong > 0xffU)
47 RETTOK(ISC_R_RANGE);
48 RETERR(uint8_tobuffer(token.value.as_ulong, target));
51 * Digest type.
53 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
54 ISC_FALSE));
55 if (token.value.as_ulong > 0xffU)
56 RETTOK(ISC_R_RANGE);
57 RETERR(uint8_tobuffer(token.value.as_ulong, target));
60 * Digest.
62 return (isc_hex_tobuffer(lexer, target, -1));
65 static inline isc_result_t
66 totext_sshfp(ARGS_TOTEXT) {
67 isc_region_t sr;
68 char buf[sizeof("64000 ")];
69 unsigned int n;
71 REQUIRE(rdata->type == 44);
72 REQUIRE(rdata->length != 0);
74 UNUSED(tctx);
76 dns_rdata_toregion(rdata, &sr);
79 * Algorithm.
81 n = uint8_fromregion(&sr);
82 isc_region_consume(&sr, 1);
83 sprintf(buf, "%u ", n);
84 RETERR(str_totext(buf, target));
87 * Digest type.
89 n = uint8_fromregion(&sr);
90 isc_region_consume(&sr, 1);
91 sprintf(buf, "%u", n);
92 RETERR(str_totext(buf, target));
95 * Digest.
97 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
98 RETERR(str_totext(" (", target));
99 RETERR(str_totext(tctx->linebreak, target));
100 if (tctx->width == 0) /* No splitting */
101 RETERR(isc_hex_totext(&sr, 0, "", target));
102 else
103 RETERR(isc_hex_totext(&sr, tctx->width - 2,
104 tctx->linebreak, target));
105 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
106 RETERR(str_totext(" )", target));
107 return (ISC_R_SUCCESS);
110 static inline isc_result_t
111 fromwire_sshfp(ARGS_FROMWIRE) {
112 isc_region_t sr;
114 REQUIRE(type == 44);
116 UNUSED(type);
117 UNUSED(rdclass);
118 UNUSED(dctx);
119 UNUSED(options);
121 isc_buffer_activeregion(source, &sr);
122 if (sr.length < 4)
123 return (ISC_R_UNEXPECTEDEND);
125 isc_buffer_forward(source, sr.length);
126 return (mem_tobuffer(target, sr.base, sr.length));
129 static inline isc_result_t
130 towire_sshfp(ARGS_TOWIRE) {
131 isc_region_t sr;
133 REQUIRE(rdata->type == 44);
134 REQUIRE(rdata->length != 0);
136 UNUSED(cctx);
138 dns_rdata_toregion(rdata, &sr);
139 return (mem_tobuffer(target, sr.base, sr.length));
142 static inline int
143 compare_sshfp(ARGS_COMPARE) {
144 isc_region_t r1;
145 isc_region_t r2;
147 REQUIRE(rdata1->type == rdata2->type);
148 REQUIRE(rdata1->rdclass == rdata2->rdclass);
149 REQUIRE(rdata1->type == 44);
150 REQUIRE(rdata1->length != 0);
151 REQUIRE(rdata2->length != 0);
153 dns_rdata_toregion(rdata1, &r1);
154 dns_rdata_toregion(rdata2, &r2);
155 return (isc_region_compare(&r1, &r2));
158 static inline isc_result_t
159 fromstruct_sshfp(ARGS_FROMSTRUCT) {
160 dns_rdata_sshfp_t *sshfp = source;
162 REQUIRE(type == 44);
163 REQUIRE(source != NULL);
164 REQUIRE(sshfp->common.rdtype == type);
165 REQUIRE(sshfp->common.rdclass == rdclass);
167 UNUSED(type);
168 UNUSED(rdclass);
170 RETERR(uint8_tobuffer(sshfp->algorithm, target));
171 RETERR(uint8_tobuffer(sshfp->digest_type, target));
173 return (mem_tobuffer(target, sshfp->digest, sshfp->length));
176 static inline isc_result_t
177 tostruct_sshfp(ARGS_TOSTRUCT) {
178 dns_rdata_sshfp_t *sshfp = target;
179 isc_region_t region;
181 REQUIRE(rdata->type == 44);
182 REQUIRE(target != NULL);
183 REQUIRE(rdata->length != 0);
185 sshfp->common.rdclass = rdata->rdclass;
186 sshfp->common.rdtype = rdata->type;
187 ISC_LINK_INIT(&sshfp->common, link);
189 dns_rdata_toregion(rdata, &region);
191 sshfp->algorithm = uint8_fromregion(&region);
192 isc_region_consume(&region, 1);
193 sshfp->digest_type = uint8_fromregion(&region);
194 isc_region_consume(&region, 1);
195 sshfp->length = region.length;
197 sshfp->digest = mem_maybedup(mctx, region.base, region.length);
198 if (sshfp->digest == NULL)
199 return (ISC_R_NOMEMORY);
201 sshfp->mctx = mctx;
202 return (ISC_R_SUCCESS);
205 static inline void
206 freestruct_sshfp(ARGS_FREESTRUCT) {
207 dns_rdata_sshfp_t *sshfp = source;
209 REQUIRE(sshfp != NULL);
210 REQUIRE(sshfp->common.rdtype == 44);
212 if (sshfp->mctx == NULL)
213 return;
215 if (sshfp->digest != NULL)
216 isc_mem_free(sshfp->mctx, sshfp->digest);
217 sshfp->mctx = NULL;
220 static inline isc_result_t
221 additionaldata_sshfp(ARGS_ADDLDATA) {
222 REQUIRE(rdata->type == 44);
224 UNUSED(rdata);
225 UNUSED(add);
226 UNUSED(arg);
228 return (ISC_R_SUCCESS);
231 static inline isc_result_t
232 digest_sshfp(ARGS_DIGEST) {
233 isc_region_t r;
235 REQUIRE(rdata->type == 44);
237 dns_rdata_toregion(rdata, &r);
239 return ((digest)(arg, &r));
242 static inline isc_boolean_t
243 checkowner_sshfp(ARGS_CHECKOWNER) {
245 REQUIRE(type == 44);
247 UNUSED(name);
248 UNUSED(type);
249 UNUSED(rdclass);
250 UNUSED(wildcard);
252 return (ISC_TRUE);
255 static inline isc_boolean_t
256 checknames_sshfp(ARGS_CHECKNAMES) {
258 REQUIRE(rdata->type == 44);
260 UNUSED(rdata);
261 UNUSED(owner);
262 UNUSED(bad);
264 return (ISC_TRUE);
267 static inline int
268 casecompare_sshfp(ARGS_COMPARE) {
269 return (compare_sshfp(rdata1, rdata2));
272 #endif /* RDATA_GENERIC_SSHFP_44_C */