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 */
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
) {
44 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
46 if (token
.value
.as_ulong
> 0xffU
)
48 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
53 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
55 if (token
.value
.as_ulong
> 0xffU
)
57 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
58 type
= (isc_uint16_t
) token
.value
.as_ulong
;
63 return (isc_hex_tobuffer(lexer
, target
, -1));
66 static inline isc_result_t
67 totext_sshfp(ARGS_TOTEXT
) {
69 char buf
[sizeof("64000 ")];
72 REQUIRE(rdata
->type
== 44);
73 REQUIRE(rdata
->length
!= 0);
77 dns_rdata_toregion(rdata
, &sr
);
82 n
= uint8_fromregion(&sr
);
83 isc_region_consume(&sr
, 1);
84 sprintf(buf
, "%u ", n
);
85 RETERR(str_totext(buf
, target
));
90 n
= uint8_fromregion(&sr
);
91 isc_region_consume(&sr
, 1);
92 sprintf(buf
, "%u", n
);
93 RETERR(str_totext(buf
, target
));
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
) {
118 isc_buffer_activeregion(source
, &sr
);
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
) {
130 REQUIRE(rdata
->type
== 44);
131 REQUIRE(rdata
->length
!= 0);
135 dns_rdata_toregion(rdata
, &sr
);
136 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
140 compare_sshfp(ARGS_COMPARE
) {
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
;
160 REQUIRE(source
!= NULL
);
161 REQUIRE(sshfp
->common
.rdtype
== type
);
162 REQUIRE(sshfp
->common
.rdclass
== 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
;
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
, ®ion
);
188 sshfp
->algorithm
= uint8_fromregion(®ion
);
189 isc_region_consume(®ion
, 1);
190 sshfp
->digest_type
= uint8_fromregion(®ion
);
191 isc_region_consume(®ion
, 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
);
199 return (ISC_R_SUCCESS
);
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
)
212 if (sshfp
->digest
!= NULL
)
213 isc_mem_free(sshfp
->mctx
, sshfp
->digest
);
217 static inline isc_result_t
218 additionaldata_sshfp(ARGS_ADDLDATA
) {
219 REQUIRE(rdata
->type
== 44);
225 return (ISC_R_SUCCESS
);
228 static inline isc_result_t
229 digest_sshfp(ARGS_DIGEST
) {
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
) {
252 static inline isc_boolean_t
253 checknames_sshfp(ARGS_CHECKNAMES
) {
255 REQUIRE(rdata
->type
== 44);
265 casecompare_sshfp(ARGS_COMPARE
) {
266 return (compare_sshfp(rdata1
, rdata2
));
269 #endif /* RDATA_GENERIC_SSHFP_44_C */