15185a700Sflorian /*
25185a700Sflorian * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
35185a700Sflorian *
45185a700Sflorian * Permission to use, copy, modify, and/or distribute this software for any
55185a700Sflorian * purpose with or without fee is hereby granted, provided that the above
65185a700Sflorian * copyright notice and this permission notice appear in all copies.
75185a700Sflorian *
85185a700Sflorian * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
95185a700Sflorian * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
105185a700Sflorian * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
115185a700Sflorian * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
125185a700Sflorian * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
135185a700Sflorian * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
145185a700Sflorian * PERFORMANCE OF THIS SOFTWARE.
155185a700Sflorian */
165185a700Sflorian
17*873f12b9Sflorian /* $Id: sshfp_44.c,v 1.12 2020/02/26 18:47:59 florian Exp $ */
185185a700Sflorian
195185a700Sflorian /* RFC 4255 */
205185a700Sflorian
215185a700Sflorian #ifndef RDATA_GENERIC_SSHFP_44_C
225185a700Sflorian #define RDATA_GENERIC_SSHFP_44_C
235185a700Sflorian
245185a700Sflorian static inline isc_result_t
totext_sshfp(ARGS_TOTEXT)255185a700Sflorian totext_sshfp(ARGS_TOTEXT) {
265185a700Sflorian isc_region_t sr;
275185a700Sflorian char buf[sizeof("64000 ")];
285185a700Sflorian unsigned int n;
295185a700Sflorian
305185a700Sflorian REQUIRE(rdata->type == dns_rdatatype_sshfp);
315185a700Sflorian REQUIRE(rdata->length != 0);
325185a700Sflorian
335185a700Sflorian UNUSED(tctx);
345185a700Sflorian
355185a700Sflorian dns_rdata_toregion(rdata, &sr);
365185a700Sflorian
375185a700Sflorian /*
385185a700Sflorian * Algorithm.
395185a700Sflorian */
405185a700Sflorian n = uint8_fromregion(&sr);
415185a700Sflorian isc_region_consume(&sr, 1);
425185a700Sflorian snprintf(buf, sizeof(buf), "%u ", n);
43*873f12b9Sflorian RETERR(isc_str_tobuffer(buf, target));
445185a700Sflorian
455185a700Sflorian /*
465185a700Sflorian * Digest type.
475185a700Sflorian */
485185a700Sflorian n = uint8_fromregion(&sr);
495185a700Sflorian isc_region_consume(&sr, 1);
505185a700Sflorian snprintf(buf, sizeof(buf), "%u", n);
51*873f12b9Sflorian RETERR(isc_str_tobuffer(buf, target));
525185a700Sflorian
535185a700Sflorian /*
545185a700Sflorian * Digest.
555185a700Sflorian */
565185a700Sflorian if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
57*873f12b9Sflorian RETERR(isc_str_tobuffer(" (", target));
58*873f12b9Sflorian RETERR(isc_str_tobuffer(tctx->linebreak, target));
595185a700Sflorian if (tctx->width == 0) /* No splitting */
605185a700Sflorian RETERR(isc_hex_totext(&sr, 0, "", target));
615185a700Sflorian else
625185a700Sflorian RETERR(isc_hex_totext(&sr, tctx->width - 2,
635185a700Sflorian tctx->linebreak, target));
645185a700Sflorian if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
65*873f12b9Sflorian RETERR(isc_str_tobuffer(" )", target));
665185a700Sflorian return (ISC_R_SUCCESS);
675185a700Sflorian }
685185a700Sflorian
695185a700Sflorian static inline isc_result_t
fromwire_sshfp(ARGS_FROMWIRE)705185a700Sflorian fromwire_sshfp(ARGS_FROMWIRE) {
715185a700Sflorian isc_region_t sr;
725185a700Sflorian
735185a700Sflorian REQUIRE(type == dns_rdatatype_sshfp);
745185a700Sflorian
755185a700Sflorian UNUSED(type);
765185a700Sflorian UNUSED(rdclass);
775185a700Sflorian UNUSED(dctx);
785185a700Sflorian UNUSED(options);
795185a700Sflorian
805185a700Sflorian isc_buffer_activeregion(source, &sr);
815185a700Sflorian if (sr.length < 4)
825185a700Sflorian return (ISC_R_UNEXPECTEDEND);
835185a700Sflorian
845185a700Sflorian isc_buffer_forward(source, sr.length);
85637d8eb6Sflorian return (isc_mem_tobuffer(target, sr.base, sr.length));
865185a700Sflorian }
875185a700Sflorian
885185a700Sflorian static inline isc_result_t
towire_sshfp(ARGS_TOWIRE)895185a700Sflorian towire_sshfp(ARGS_TOWIRE) {
905185a700Sflorian isc_region_t sr;
915185a700Sflorian
925185a700Sflorian REQUIRE(rdata->type == dns_rdatatype_sshfp);
935185a700Sflorian REQUIRE(rdata->length != 0);
945185a700Sflorian
955185a700Sflorian UNUSED(cctx);
965185a700Sflorian
975185a700Sflorian dns_rdata_toregion(rdata, &sr);
98637d8eb6Sflorian return (isc_mem_tobuffer(target, sr.base, sr.length));
995185a700Sflorian }
1005185a700Sflorian
1015185a700Sflorian #endif /* RDATA_GENERIC_SSHFP_44_C */
102