1 /* $NetBSD: sshfp_44.c,v 1.6 2014/12/10 04:37:59 christos Exp $ */
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.
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
));
62 return (isc_hex_tobuffer(lexer
, target
, -1));
65 static inline isc_result_t
66 totext_sshfp(ARGS_TOTEXT
) {
68 char buf
[sizeof("64000 ")];
71 REQUIRE(rdata
->type
== 44);
72 REQUIRE(rdata
->length
!= 0);
76 dns_rdata_toregion(rdata
, &sr
);
81 n
= uint8_fromregion(&sr
);
82 isc_region_consume(&sr
, 1);
83 sprintf(buf
, "%u ", n
);
84 RETERR(str_totext(buf
, target
));
89 n
= uint8_fromregion(&sr
);
90 isc_region_consume(&sr
, 1);
91 sprintf(buf
, "%u", n
);
92 RETERR(str_totext(buf
, target
));
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
));
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
) {
121 isc_buffer_activeregion(source
, &sr
);
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
) {
133 REQUIRE(rdata
->type
== 44);
134 REQUIRE(rdata
->length
!= 0);
138 dns_rdata_toregion(rdata
, &sr
);
139 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
143 compare_sshfp(ARGS_COMPARE
) {
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
;
163 REQUIRE(source
!= NULL
);
164 REQUIRE(sshfp
->common
.rdtype
== type
);
165 REQUIRE(sshfp
->common
.rdclass
== 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
;
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
, ®ion
);
191 sshfp
->algorithm
= uint8_fromregion(®ion
);
192 isc_region_consume(®ion
, 1);
193 sshfp
->digest_type
= uint8_fromregion(®ion
);
194 isc_region_consume(®ion
, 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
);
202 return (ISC_R_SUCCESS
);
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
)
215 if (sshfp
->digest
!= NULL
)
216 isc_mem_free(sshfp
->mctx
, sshfp
->digest
);
220 static inline isc_result_t
221 additionaldata_sshfp(ARGS_ADDLDATA
) {
222 REQUIRE(rdata
->type
== 44);
228 return (ISC_R_SUCCESS
);
231 static inline isc_result_t
232 digest_sshfp(ARGS_DIGEST
) {
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
) {
255 static inline isc_boolean_t
256 checknames_sshfp(ARGS_CHECKNAMES
) {
258 REQUIRE(rdata
->type
== 44);
268 casecompare_sshfp(ARGS_COMPARE
) {
269 return (compare_sshfp(rdata1
, rdata2
));
272 #endif /* RDATA_GENERIC_SSHFP_44_C */