Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / bind / dist / lib / dns / rdata / generic / sshfp_44.c
blobbee3c6b99349992b4f0e51c9ae2c77bfdd83874b
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2006, 2007, 2009 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: sshfp_44.c,v 1.9 2009/12/04 22:06:37 tbox Exp */
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));
58 type = (isc_uint16_t) token.value.as_ulong;
61 * Digest.
63 return (isc_hex_tobuffer(lexer, target, -1));
66 static inline isc_result_t
67 totext_sshfp(ARGS_TOTEXT) {
68 isc_region_t sr;
69 char buf[sizeof("64000 ")];
70 unsigned int n;
72 REQUIRE(rdata->type == 44);
73 REQUIRE(rdata->length != 0);
75 UNUSED(tctx);
77 dns_rdata_toregion(rdata, &sr);
80 * Algorithm.
82 n = uint8_fromregion(&sr);
83 isc_region_consume(&sr, 1);
84 sprintf(buf, "%u ", n);
85 RETERR(str_totext(buf, target));
88 * Digest type.
90 n = uint8_fromregion(&sr);
91 isc_region_consume(&sr, 1);
92 sprintf(buf, "%u", n);
93 RETERR(str_totext(buf, target));
96 * Digest.
98 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
99 RETERR(str_totext(" (", target));
100 RETERR(str_totext(tctx->linebreak, target));
101 RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target));
102 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
103 RETERR(str_totext(" )", target));
104 return (ISC_R_SUCCESS);
107 static inline isc_result_t
108 fromwire_sshfp(ARGS_FROMWIRE) {
109 isc_region_t sr;
111 REQUIRE(type == 44);
113 UNUSED(type);
114 UNUSED(rdclass);
115 UNUSED(dctx);
116 UNUSED(options);
118 isc_buffer_activeregion(source, &sr);
119 if (sr.length < 4)
120 return (ISC_R_UNEXPECTEDEND);
122 isc_buffer_forward(source, sr.length);
123 return (mem_tobuffer(target, sr.base, sr.length));
126 static inline isc_result_t
127 towire_sshfp(ARGS_TOWIRE) {
128 isc_region_t sr;
130 REQUIRE(rdata->type == 44);
131 REQUIRE(rdata->length != 0);
133 UNUSED(cctx);
135 dns_rdata_toregion(rdata, &sr);
136 return (mem_tobuffer(target, sr.base, sr.length));
139 static inline int
140 compare_sshfp(ARGS_COMPARE) {
141 isc_region_t r1;
142 isc_region_t r2;
144 REQUIRE(rdata1->type == rdata2->type);
145 REQUIRE(rdata1->rdclass == rdata2->rdclass);
146 REQUIRE(rdata1->type == 44);
147 REQUIRE(rdata1->length != 0);
148 REQUIRE(rdata2->length != 0);
150 dns_rdata_toregion(rdata1, &r1);
151 dns_rdata_toregion(rdata2, &r2);
152 return (isc_region_compare(&r1, &r2));
155 static inline isc_result_t
156 fromstruct_sshfp(ARGS_FROMSTRUCT) {
157 dns_rdata_sshfp_t *sshfp = source;
159 REQUIRE(type == 44);
160 REQUIRE(source != NULL);
161 REQUIRE(sshfp->common.rdtype == type);
162 REQUIRE(sshfp->common.rdclass == rdclass);
164 UNUSED(type);
165 UNUSED(rdclass);
167 RETERR(uint8_tobuffer(sshfp->algorithm, target));
168 RETERR(uint8_tobuffer(sshfp->digest_type, target));
170 return (mem_tobuffer(target, sshfp->digest, sshfp->length));
173 static inline isc_result_t
174 tostruct_sshfp(ARGS_TOSTRUCT) {
175 dns_rdata_sshfp_t *sshfp = target;
176 isc_region_t region;
178 REQUIRE(rdata->type == 44);
179 REQUIRE(target != NULL);
180 REQUIRE(rdata->length != 0);
182 sshfp->common.rdclass = rdata->rdclass;
183 sshfp->common.rdtype = rdata->type;
184 ISC_LINK_INIT(&sshfp->common, link);
186 dns_rdata_toregion(rdata, &region);
188 sshfp->algorithm = uint8_fromregion(&region);
189 isc_region_consume(&region, 1);
190 sshfp->digest_type = uint8_fromregion(&region);
191 isc_region_consume(&region, 1);
192 sshfp->length = region.length;
194 sshfp->digest = mem_maybedup(mctx, region.base, region.length);
195 if (sshfp->digest == NULL)
196 return (ISC_R_NOMEMORY);
198 sshfp->mctx = mctx;
199 return (ISC_R_SUCCESS);
202 static inline void
203 freestruct_sshfp(ARGS_FREESTRUCT) {
204 dns_rdata_sshfp_t *sshfp = source;
206 REQUIRE(sshfp != NULL);
207 REQUIRE(sshfp->common.rdtype == 44);
209 if (sshfp->mctx == NULL)
210 return;
212 if (sshfp->digest != NULL)
213 isc_mem_free(sshfp->mctx, sshfp->digest);
214 sshfp->mctx = NULL;
217 static inline isc_result_t
218 additionaldata_sshfp(ARGS_ADDLDATA) {
219 REQUIRE(rdata->type == 44);
221 UNUSED(rdata);
222 UNUSED(add);
223 UNUSED(arg);
225 return (ISC_R_SUCCESS);
228 static inline isc_result_t
229 digest_sshfp(ARGS_DIGEST) {
230 isc_region_t r;
232 REQUIRE(rdata->type == 44);
234 dns_rdata_toregion(rdata, &r);
236 return ((digest)(arg, &r));
239 static inline isc_boolean_t
240 checkowner_sshfp(ARGS_CHECKOWNER) {
242 REQUIRE(type == 44);
244 UNUSED(name);
245 UNUSED(type);
246 UNUSED(rdclass);
247 UNUSED(wildcard);
249 return (ISC_TRUE);
252 static inline isc_boolean_t
253 checknames_sshfp(ARGS_CHECKNAMES) {
255 REQUIRE(rdata->type == 44);
257 UNUSED(rdata);
258 UNUSED(owner);
259 UNUSED(bad);
261 return (ISC_TRUE);
264 static inline int
265 casecompare_sshfp(ARGS_COMPARE) {
266 return (compare_sshfp(rdata1, rdata2));
269 #endif /* RDATA_GENERIC_SSHFP_44_C */