acpi.4: Add some missing references.
[dragonfly.git] / contrib / bind-9.3 / lib / dns / rdata / generic / sshfp_44.c
blobeabf056d6f7d84c882a99310bfad6dbf4658d945
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.
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.
18 /* $Id: sshfp_44.c,v 1.1.8.3 2004/03/06 08:14:13 marka Exp $ */
20 /* draft-ietf-secsh-dns-05.txt */
22 #ifndef RDATA_GENERIC_SSHFP_44_C
23 #define RDATA_GENERIC_SSHFP_44_C
25 #define RRTYPE_SSHFP_ATTRIBUTES (0)
27 static inline isc_result_t
28 fromtext_sshfp(ARGS_FROMTEXT) {
29 isc_token_t token;
31 REQUIRE(type == 44);
33 UNUSED(type);
34 UNUSED(rdclass);
35 UNUSED(origin);
36 UNUSED(options);
37 UNUSED(callbacks);
40 * Algorithm.
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));
49 * Digest type.
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 type = (isc_uint16_t) token.value.as_ulong;
59 * Digest.
61 return (isc_hex_tobuffer(lexer, target, -1));
64 static inline isc_result_t
65 totext_sshfp(ARGS_TOTEXT) {
66 isc_region_t sr;
67 char buf[sizeof("64000 ")];
68 unsigned int n;
70 REQUIRE(rdata->type == 44);
71 REQUIRE(rdata->length != 0);
73 UNUSED(tctx);
75 dns_rdata_toregion(rdata, &sr);
78 * Algorithm.
80 n = uint8_fromregion(&sr);
81 isc_region_consume(&sr, 1);
82 sprintf(buf, "%u ", n);
83 RETERR(str_totext(buf, target));
86 * Digest type.
88 n = uint8_fromregion(&sr);
89 isc_region_consume(&sr, 1);
90 sprintf(buf, "%u", n);
91 RETERR(str_totext(buf, target));
94 * Digest.
96 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
97 RETERR(str_totext(" (", target));
98 RETERR(str_totext(tctx->linebreak, target));
99 RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
100 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
101 RETERR(str_totext(" )", target));
102 return (ISC_R_SUCCESS);
105 static inline isc_result_t
106 fromwire_sshfp(ARGS_FROMWIRE) {
107 isc_region_t sr;
109 REQUIRE(type == 44);
111 UNUSED(type);
112 UNUSED(rdclass);
113 UNUSED(dctx);
114 UNUSED(options);
116 isc_buffer_activeregion(source, &sr);
117 if (sr.length < 4)
118 return (ISC_R_UNEXPECTEDEND);
120 isc_buffer_forward(source, sr.length);
121 return (mem_tobuffer(target, sr.base, sr.length));
124 static inline isc_result_t
125 towire_sshfp(ARGS_TOWIRE) {
126 isc_region_t sr;
128 REQUIRE(rdata->type == 44);
129 REQUIRE(rdata->length != 0);
131 UNUSED(cctx);
133 dns_rdata_toregion(rdata, &sr);
134 return (mem_tobuffer(target, sr.base, sr.length));
137 static inline int
138 compare_sshfp(ARGS_COMPARE) {
139 isc_region_t r1;
140 isc_region_t r2;
142 REQUIRE(rdata1->type == rdata2->type);
143 REQUIRE(rdata1->rdclass == rdata2->rdclass);
144 REQUIRE(rdata1->type == 44);
145 REQUIRE(rdata1->length != 0);
146 REQUIRE(rdata2->length != 0);
148 dns_rdata_toregion(rdata1, &r1);
149 dns_rdata_toregion(rdata2, &r2);
150 return (isc_region_compare(&r1, &r2));
153 static inline isc_result_t
154 fromstruct_sshfp(ARGS_FROMSTRUCT) {
155 dns_rdata_sshfp_t *sshfp = source;
157 REQUIRE(type == 44);
158 REQUIRE(source != NULL);
159 REQUIRE(sshfp->common.rdtype == type);
160 REQUIRE(sshfp->common.rdclass == rdclass);
162 UNUSED(type);
163 UNUSED(rdclass);
165 RETERR(uint8_tobuffer(sshfp->algorithm, target));
166 RETERR(uint8_tobuffer(sshfp->digest_type, target));
168 return (mem_tobuffer(target, sshfp->digest, sshfp->length));
171 static inline isc_result_t
172 tostruct_sshfp(ARGS_TOSTRUCT) {
173 dns_rdata_sshfp_t *sshfp = target;
174 isc_region_t region;
176 REQUIRE(rdata->type == 44);
177 REQUIRE(target != NULL);
178 REQUIRE(rdata->length != 0);
180 sshfp->common.rdclass = rdata->rdclass;
181 sshfp->common.rdtype = rdata->type;
182 ISC_LINK_INIT(&sshfp->common, link);
184 dns_rdata_toregion(rdata, &region);
186 sshfp->algorithm = uint8_fromregion(&region);
187 isc_region_consume(&region, 1);
188 sshfp->digest_type = uint8_fromregion(&region);
189 isc_region_consume(&region, 1);
190 sshfp->length = region.length;
192 sshfp->digest = mem_maybedup(mctx, region.base, region.length);
193 if (sshfp->digest == NULL)
194 return (ISC_R_NOMEMORY);
196 sshfp->mctx = mctx;
197 return (ISC_R_SUCCESS);
200 static inline void
201 freestruct_sshfp(ARGS_FREESTRUCT) {
202 dns_rdata_sshfp_t *sshfp = source;
204 REQUIRE(sshfp != NULL);
205 REQUIRE(sshfp->common.rdtype == 44);
207 if (sshfp->mctx == NULL)
208 return;
210 if (sshfp->digest != NULL)
211 isc_mem_free(sshfp->mctx, sshfp->digest);
212 sshfp->mctx = NULL;
215 static inline isc_result_t
216 additionaldata_sshfp(ARGS_ADDLDATA) {
217 REQUIRE(rdata->type == 44);
219 UNUSED(rdata);
220 UNUSED(add);
221 UNUSED(arg);
223 return (ISC_R_SUCCESS);
226 static inline isc_result_t
227 digest_sshfp(ARGS_DIGEST) {
228 isc_region_t r;
230 REQUIRE(rdata->type == 44);
232 dns_rdata_toregion(rdata, &r);
234 return ((digest)(arg, &r));
237 static inline isc_boolean_t
238 checkowner_sshfp(ARGS_CHECKOWNER) {
240 REQUIRE(type == 44);
242 UNUSED(name);
243 UNUSED(type);
244 UNUSED(rdclass);
245 UNUSED(wildcard);
247 return (ISC_TRUE);
250 static inline isc_boolean_t
251 checknames_sshfp(ARGS_CHECKNAMES) {
253 REQUIRE(rdata->type == 44);
255 UNUSED(rdata);
256 UNUSED(owner);
257 UNUSED(bad);
259 return (ISC_TRUE);
262 #endif /* RDATA_GENERIC_SSHFP_44_C */