1 /* $NetBSD: cds_59.c,v 1.1.1.4 2015/07/08 15:38:03 christos Exp $ */
4 * Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* draft-ietf-dnsop-delegation-trust-maintainance-14 */
21 #ifndef RDATA_GENERIC_CDS_59_C
22 #define RDATA_GENERIC_CDS_59_C
24 #define RRTYPE_CDS_ATTRIBUTES 0
33 static inline isc_result_t
34 fromtext_cds(ARGS_FROMTEXT
) {
50 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
52 if (token
.value
.as_ulong
> 0xffffU
)
54 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
59 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
61 RETTOK(dns_secalg_fromtext(&c
, &token
.value
.as_textregion
));
62 RETERR(mem_tobuffer(target
, &c
, 1));
67 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
69 RETTOK(dns_dsdigest_fromtext(&c
, &token
.value
.as_textregion
));
70 RETERR(mem_tobuffer(target
, &c
, 1));
76 case DNS_DSDIGEST_SHA1
:
77 length
= ISC_SHA1_DIGESTLENGTH
;
79 case DNS_DSDIGEST_SHA256
:
80 length
= ISC_SHA256_DIGESTLENGTH
;
82 #ifdef ISC_GOST_DIGESTLENGTH
83 case DNS_DSDIGEST_GOST
:
84 length
= ISC_GOST_DIGESTLENGTH
;
87 case DNS_DSDIGEST_SHA384
:
88 length
= ISC_SHA384_DIGESTLENGTH
;
94 return (isc_hex_tobuffer(lexer
, target
, length
));
97 static inline isc_result_t
98 totext_cds(ARGS_TOTEXT
) {
100 char buf
[sizeof("64000 ")];
103 REQUIRE(rdata
->type
== 59);
104 REQUIRE(rdata
->length
!= 0);
108 dns_rdata_toregion(rdata
, &sr
);
113 n
= uint16_fromregion(&sr
);
114 isc_region_consume(&sr
, 2);
115 sprintf(buf
, "%u ", n
);
116 RETERR(str_totext(buf
, target
));
121 n
= uint8_fromregion(&sr
);
122 isc_region_consume(&sr
, 1);
123 sprintf(buf
, "%u ", n
);
124 RETERR(str_totext(buf
, target
));
129 n
= uint8_fromregion(&sr
);
130 isc_region_consume(&sr
, 1);
131 sprintf(buf
, "%u", n
);
132 RETERR(str_totext(buf
, target
));
137 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
138 RETERR(str_totext(" (", target
));
139 RETERR(str_totext(tctx
->linebreak
, target
));
140 if ((tctx
->flags
& DNS_STYLEFLAG_NOCRYPTO
) == 0) {
141 if (tctx
->width
== 0) /* No splitting */
142 RETERR(isc_hex_totext(&sr
, 0, "", target
));
144 RETERR(isc_hex_totext(&sr
, tctx
->width
- 2,
145 tctx
->linebreak
, target
));
147 RETERR(str_totext("[omitted]", target
));
148 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
149 RETERR(str_totext(" )", target
));
150 return (ISC_R_SUCCESS
);
153 static inline isc_result_t
154 fromwire_cds(ARGS_FROMWIRE
) {
164 isc_buffer_activeregion(source
, &sr
);
167 * Check digest lengths if we know them.
170 (sr
.base
[3] == DNS_DSDIGEST_SHA1
&&
171 sr
.length
< 4 + ISC_SHA1_DIGESTLENGTH
) ||
172 (sr
.base
[3] == DNS_DSDIGEST_SHA256
&&
173 sr
.length
< 4 + ISC_SHA256_DIGESTLENGTH
) ||
174 #ifdef ISC_GOST_DIGESTLENGTH
175 (sr
.base
[3] == DNS_DSDIGEST_GOST
&&
176 sr
.length
< 4 + ISC_GOST_DIGESTLENGTH
) ||
178 (sr
.base
[3] == DNS_DSDIGEST_SHA384
&&
179 sr
.length
< 4 + ISC_SHA384_DIGESTLENGTH
))
180 return (ISC_R_UNEXPECTEDEND
);
183 * Only copy digest lengths if we know them.
184 * If there is extra data dns_rdata_fromwire() will
187 if (sr
.base
[3] == DNS_DSDIGEST_SHA1
)
188 sr
.length
= 4 + ISC_SHA1_DIGESTLENGTH
;
189 else if (sr
.base
[3] == DNS_DSDIGEST_SHA256
)
190 sr
.length
= 4 + ISC_SHA256_DIGESTLENGTH
;
191 #ifdef ISC_GOST_DIGESTLENGTH
192 else if (sr
.base
[3] == DNS_DSDIGEST_GOST
)
193 sr
.length
= 4 + ISC_GOST_DIGESTLENGTH
;
195 else if (sr
.base
[3] == DNS_DSDIGEST_SHA384
)
196 sr
.length
= 4 + ISC_SHA384_DIGESTLENGTH
;
198 isc_buffer_forward(source
, sr
.length
);
199 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
202 static inline isc_result_t
203 towire_cds(ARGS_TOWIRE
) {
206 REQUIRE(rdata
->type
== 59);
207 REQUIRE(rdata
->length
!= 0);
211 dns_rdata_toregion(rdata
, &sr
);
212 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
216 compare_cds(ARGS_COMPARE
) {
220 REQUIRE(rdata1
->type
== rdata2
->type
);
221 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
222 REQUIRE(rdata1
->type
== 59);
223 REQUIRE(rdata1
->length
!= 0);
224 REQUIRE(rdata2
->length
!= 0);
226 dns_rdata_toregion(rdata1
, &r1
);
227 dns_rdata_toregion(rdata2
, &r2
);
228 return (isc_region_compare(&r1
, &r2
));
231 static inline isc_result_t
232 fromstruct_cds(ARGS_FROMSTRUCT
) {
233 dns_rdata_cds_t
*ds
= source
;
236 REQUIRE(source
!= NULL
);
237 REQUIRE(ds
->common
.rdtype
== type
);
238 REQUIRE(ds
->common
.rdclass
== rdclass
);
239 switch (ds
->digest_type
) {
240 case DNS_DSDIGEST_SHA1
:
241 REQUIRE(ds
->length
== ISC_SHA1_DIGESTLENGTH
);
243 case DNS_DSDIGEST_SHA256
:
244 REQUIRE(ds
->length
== ISC_SHA256_DIGESTLENGTH
);
246 #ifdef ISC_GOST_DIGESTLENGTH
247 case DNS_DSDIGEST_GOST
:
248 REQUIRE(ds
->length
== ISC_GOST_DIGESTLENGTH
);
251 case DNS_DSDIGEST_SHA384
:
252 REQUIRE(ds
->length
== ISC_SHA384_DIGESTLENGTH
);
259 RETERR(uint16_tobuffer(ds
->key_tag
, target
));
260 RETERR(uint8_tobuffer(ds
->algorithm
, target
));
261 RETERR(uint8_tobuffer(ds
->digest_type
, target
));
263 return (mem_tobuffer(target
, ds
->digest
, ds
->length
));
266 static inline isc_result_t
267 tostruct_cds(ARGS_TOSTRUCT
) {
268 dns_rdata_cds_t
*ds
= target
;
271 REQUIRE(rdata
->type
== 59);
272 REQUIRE(target
!= NULL
);
273 REQUIRE(rdata
->length
!= 0);
275 ds
->common
.rdclass
= rdata
->rdclass
;
276 ds
->common
.rdtype
= rdata
->type
;
277 ISC_LINK_INIT(&ds
->common
, link
);
279 dns_rdata_toregion(rdata
, ®ion
);
281 ds
->key_tag
= uint16_fromregion(®ion
);
282 isc_region_consume(®ion
, 2);
283 ds
->algorithm
= uint8_fromregion(®ion
);
284 isc_region_consume(®ion
, 1);
285 ds
->digest_type
= uint8_fromregion(®ion
);
286 isc_region_consume(®ion
, 1);
287 ds
->length
= region
.length
;
289 ds
->digest
= mem_maybedup(mctx
, region
.base
, region
.length
);
290 if (ds
->digest
== NULL
)
291 return (ISC_R_NOMEMORY
);
294 return (ISC_R_SUCCESS
);
298 freestruct_cds(ARGS_FREESTRUCT
) {
299 dns_rdata_cds_t
*ds
= source
;
302 REQUIRE(ds
->common
.rdtype
== 59);
304 if (ds
->mctx
== NULL
)
307 if (ds
->digest
!= NULL
)
308 isc_mem_free(ds
->mctx
, ds
->digest
);
312 static inline isc_result_t
313 additionaldata_cds(ARGS_ADDLDATA
) {
314 REQUIRE(rdata
->type
== 59);
320 return (ISC_R_SUCCESS
);
323 static inline isc_result_t
324 digest_cds(ARGS_DIGEST
) {
327 REQUIRE(rdata
->type
== 59);
329 dns_rdata_toregion(rdata
, &r
);
331 return ((digest
)(arg
, &r
));
334 static inline isc_boolean_t
335 checkowner_cds(ARGS_CHECKOWNER
) {
347 static inline isc_boolean_t
348 checknames_cds(ARGS_CHECKNAMES
) {
350 REQUIRE(rdata
->type
== 59);
360 casecompare_cds(ARGS_COMPARE
) {
361 return (compare_cds(rdata1
, rdata2
));
364 #endif /* RDATA_GENERIC_CDS_59_C */