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
) {
42 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
44 if (token
.value
.as_ulong
> 0xffU
)
46 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
51 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
53 if (token
.value
.as_ulong
> 0xffU
)
55 RETERR(uint8_tobuffer(token
.value
.as_ulong
, target
));
56 type
= (isc_uint16_t
) token
.value
.as_ulong
;
61 return (isc_hex_tobuffer(lexer
, target
, -1));
64 static inline isc_result_t
65 totext_sshfp(ARGS_TOTEXT
) {
67 char buf
[sizeof("64000 ")];
70 REQUIRE(rdata
->type
== 44);
71 REQUIRE(rdata
->length
!= 0);
75 dns_rdata_toregion(rdata
, &sr
);
80 n
= uint8_fromregion(&sr
);
81 isc_region_consume(&sr
, 1);
82 sprintf(buf
, "%u ", n
);
83 RETERR(str_totext(buf
, target
));
88 n
= uint8_fromregion(&sr
);
89 isc_region_consume(&sr
, 1);
90 sprintf(buf
, "%u", n
);
91 RETERR(str_totext(buf
, target
));
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
) {
116 isc_buffer_activeregion(source
, &sr
);
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
) {
128 REQUIRE(rdata
->type
== 44);
129 REQUIRE(rdata
->length
!= 0);
133 dns_rdata_toregion(rdata
, &sr
);
134 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
138 compare_sshfp(ARGS_COMPARE
) {
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
;
158 REQUIRE(source
!= NULL
);
159 REQUIRE(sshfp
->common
.rdtype
== type
);
160 REQUIRE(sshfp
->common
.rdclass
== 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
;
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
, ®ion
);
186 sshfp
->algorithm
= uint8_fromregion(®ion
);
187 isc_region_consume(®ion
, 1);
188 sshfp
->digest_type
= uint8_fromregion(®ion
);
189 isc_region_consume(®ion
, 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
);
197 return (ISC_R_SUCCESS
);
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
)
210 if (sshfp
->digest
!= NULL
)
211 isc_mem_free(sshfp
->mctx
, sshfp
->digest
);
215 static inline isc_result_t
216 additionaldata_sshfp(ARGS_ADDLDATA
) {
217 REQUIRE(rdata
->type
== 44);
223 return (ISC_R_SUCCESS
);
226 static inline isc_result_t
227 digest_sshfp(ARGS_DIGEST
) {
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
) {
250 static inline isc_boolean_t
251 checknames_sshfp(ARGS_CHECKNAMES
) {
253 REQUIRE(rdata
->type
== 44);
262 #endif /* RDATA_GENERIC_SSHFP_44_C */