sshfp_44.c 5.49 KB
Newer Older
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4 5 6
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 8 9
 *
 * See the COPYRIGHT file distributed with this work for additional
 * information regarding copyright ownership.
10 11 12
 */


13
/* RFC 4255 */
14 15 16 17 18 19 20 21 22 23

#ifndef RDATA_GENERIC_SSHFP_44_C
#define RDATA_GENERIC_SSHFP_44_C

#define RRTYPE_SSHFP_ATTRIBUTES (0)

static inline isc_result_t
fromtext_sshfp(ARGS_FROMTEXT) {
	isc_token_t token;

24
	REQUIRE(type == dns_rdatatype_sshfp);
25 26 27 28

	UNUSED(type);
	UNUSED(rdclass);
	UNUSED(origin);
29
	UNUSED(options);
30 31 32 33 34 35
	UNUSED(callbacks);

	/*
	 * Algorithm.
	 */
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
36
				      false));
37 38 39 40 41 42 43 44
	if (token.value.as_ulong > 0xffU)
		RETTOK(ISC_R_RANGE);
	RETERR(uint8_tobuffer(token.value.as_ulong, target));

	/*
	 * Digest type.
	 */
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45
				      false));
46 47 48 49 50 51 52
	if (token.value.as_ulong > 0xffU)
		RETTOK(ISC_R_RANGE);
	RETERR(uint8_tobuffer(token.value.as_ulong, target));

	/*
	 * Digest.
	 */
53
	return (isc_hex_tobuffer(lexer, target, -2));
54 55 56 57 58 59 60 61
}

static inline isc_result_t
totext_sshfp(ARGS_TOTEXT) {
	isc_region_t sr;
	char buf[sizeof("64000 ")];
	unsigned int n;

62
	REQUIRE(rdata->type == dns_rdatatype_sshfp);
63 64 65 66 67 68 69 70 71 72 73
	REQUIRE(rdata->length != 0);

	UNUSED(tctx);

	dns_rdata_toregion(rdata, &sr);

	/*
	 * Algorithm.
	 */
	n = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);
74
	snprintf(buf, sizeof(buf), "%u ", n);
75 76 77 78 79 80 81
	RETERR(str_totext(buf, target));

	/*
	 * Digest type.
	 */
	n = uint8_fromregion(&sr);
	isc_region_consume(&sr, 1);
82
	snprintf(buf, sizeof(buf), "%u", n);
83 84 85 86 87 88 89 90
	RETERR(str_totext(buf, target));

	/*
	 * Digest.
	 */
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" (", target));
	RETERR(str_totext(tctx->linebreak, target));
91 92 93 94 95
	if (tctx->width == 0) /* No splitting */
		RETERR(isc_hex_totext(&sr, 0, "", target));
	else
		RETERR(isc_hex_totext(&sr, tctx->width - 2,
				      tctx->linebreak, target));
96 97 98 99 100 101 102 103 104
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" )", target));
	return (ISC_R_SUCCESS);
}

static inline isc_result_t
fromwire_sshfp(ARGS_FROMWIRE) {
	isc_region_t sr;

105
	REQUIRE(type == dns_rdatatype_sshfp);
106 107 108 109

	UNUSED(type);
	UNUSED(rdclass);
	UNUSED(dctx);
110
	UNUSED(options);
111 112 113 114 115 116 117 118 119 120 121 122 123

	isc_buffer_activeregion(source, &sr);
	if (sr.length < 4)
		return (ISC_R_UNEXPECTEDEND);

	isc_buffer_forward(source, sr.length);
	return (mem_tobuffer(target, sr.base, sr.length));
}

static inline isc_result_t
towire_sshfp(ARGS_TOWIRE) {
	isc_region_t sr;

124
	REQUIRE(rdata->type == dns_rdatatype_sshfp);
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
	REQUIRE(rdata->length != 0);

	UNUSED(cctx);

	dns_rdata_toregion(rdata, &sr);
	return (mem_tobuffer(target, sr.base, sr.length));
}

static inline int
compare_sshfp(ARGS_COMPARE) {
	isc_region_t r1;
	isc_region_t r2;

	REQUIRE(rdata1->type == rdata2->type);
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
140
	REQUIRE(rdata1->type == dns_rdatatype_sshfp);
141 142 143 144 145 146 147 148 149 150 151 152
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);

	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	return (isc_region_compare(&r1, &r2));
}

static inline isc_result_t
fromstruct_sshfp(ARGS_FROMSTRUCT) {
	dns_rdata_sshfp_t *sshfp = source;

153
	REQUIRE(type == dns_rdatatype_sshfp);
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
	REQUIRE(source != NULL);
	REQUIRE(sshfp->common.rdtype == type);
	REQUIRE(sshfp->common.rdclass == rdclass);

	UNUSED(type);
	UNUSED(rdclass);

	RETERR(uint8_tobuffer(sshfp->algorithm, target));
	RETERR(uint8_tobuffer(sshfp->digest_type, target));

	return (mem_tobuffer(target, sshfp->digest, sshfp->length));
}

static inline isc_result_t
tostruct_sshfp(ARGS_TOSTRUCT) {
	dns_rdata_sshfp_t *sshfp = target;
	isc_region_t region;

172
	REQUIRE(rdata->type == dns_rdatatype_sshfp);
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
	REQUIRE(target != NULL);
	REQUIRE(rdata->length != 0);

	sshfp->common.rdclass = rdata->rdclass;
	sshfp->common.rdtype = rdata->type;
	ISC_LINK_INIT(&sshfp->common, link);

	dns_rdata_toregion(rdata, &region);

	sshfp->algorithm = uint8_fromregion(&region);
	isc_region_consume(&region, 1);
	sshfp->digest_type = uint8_fromregion(&region);
	isc_region_consume(&region, 1);
	sshfp->length = region.length;

	sshfp->digest = mem_maybedup(mctx, region.base, region.length);
	if (sshfp->digest == NULL)
		return (ISC_R_NOMEMORY);

	sshfp->mctx = mctx;
	return (ISC_R_SUCCESS);
}

static inline void
freestruct_sshfp(ARGS_FREESTRUCT) {
	dns_rdata_sshfp_t *sshfp = source;

	REQUIRE(sshfp != NULL);
201
	REQUIRE(sshfp->common.rdtype == dns_rdatatype_sshfp);
202 203 204 205 206 207 208 209 210 211 212

	if (sshfp->mctx == NULL)
		return;

	if (sshfp->digest != NULL)
		isc_mem_free(sshfp->mctx, sshfp->digest);
	sshfp->mctx = NULL;
}

static inline isc_result_t
additionaldata_sshfp(ARGS_ADDLDATA) {
213
	REQUIRE(rdata->type == dns_rdatatype_sshfp);
214 215 216 217 218 219 220 221 222 223 224 225

	UNUSED(rdata);
	UNUSED(add);
	UNUSED(arg);

	return (ISC_R_SUCCESS);
}

static inline isc_result_t
digest_sshfp(ARGS_DIGEST) {
	isc_region_t r;

226
	REQUIRE(rdata->type == dns_rdatatype_sshfp);
227 228 229 230 231 232

	dns_rdata_toregion(rdata, &r);

	return ((digest)(arg, &r));
}

233
static inline bool
234 235
checkowner_sshfp(ARGS_CHECKOWNER) {

236
	REQUIRE(type == dns_rdatatype_sshfp);
237 238 239 240 241 242

	UNUSED(name);
	UNUSED(type);
	UNUSED(rdclass);
	UNUSED(wildcard);

243
	return (true);
244 245
}

246
static inline bool
247 248
checknames_sshfp(ARGS_CHECKNAMES) {

249
	REQUIRE(rdata->type == dns_rdatatype_sshfp);
250 251 252 253 254

	UNUSED(rdata);
	UNUSED(owner);
	UNUSED(bad);

255
	return (true);
256 257
}

258 259 260 261 262
static inline int
casecompare_sshfp(ARGS_COMPARE) {
	return (compare_sshfp(rdata1, rdata2));
}

263
#endif	/* RDATA_GENERIC_SSHFP_44_C */