4 * Copyright (C) 2009 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 /* Id: keydata_65533.c,v 1.3 2009/12/04 21:09:33 marka Exp */
21 #ifndef GENERIC_KEYDATA_65533_C
22 #define GENERIC_KEYDATA_65533_C 1
26 #define RRTYPE_KEYDATA_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
28 static inline isc_result_t
29 fromtext_keydata(ARGS_FROMTEXT
) {
34 isc_uint32_t refresh
, addhd
, removehd
;
36 REQUIRE(type
== 65533);
45 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
47 RETTOK(dns_time32_fromtext(DNS_AS_STR(token
), &refresh
));
48 RETERR(uint32_tobuffer(refresh
, target
));
51 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
53 RETTOK(dns_time32_fromtext(DNS_AS_STR(token
), &addhd
));
54 RETERR(uint32_tobuffer(addhd
, target
));
56 /* remove hold-down */
57 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
59 RETTOK(dns_time32_fromtext(DNS_AS_STR(token
), &removehd
));
60 RETERR(uint32_tobuffer(removehd
, target
));
63 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
65 RETTOK(dns_keyflags_fromtext(&flags
, &token
.value
.as_textregion
));
66 RETERR(uint16_tobuffer(flags
, target
));
69 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
71 RETTOK(dns_secproto_fromtext(&proto
, &token
.value
.as_textregion
));
72 RETERR(mem_tobuffer(target
, &proto
, 1));
75 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
77 RETTOK(dns_secalg_fromtext(&alg
, &token
.value
.as_textregion
));
78 RETERR(mem_tobuffer(target
, &alg
, 1));
81 if ((flags
& 0xc000) == 0xc000)
82 return (ISC_R_SUCCESS
);
84 return (isc_base64_tobuffer(lexer
, target
, -1));
87 static inline isc_result_t
88 totext_keydata(ARGS_TOTEXT
) {
90 char buf
[sizeof("64000")];
92 unsigned char algorithm
;
95 REQUIRE(rdata
->type
== 65533);
96 REQUIRE(rdata
->length
!= 0);
98 dns_rdata_toregion(rdata
, &sr
);
101 when
= uint32_fromregion(&sr
);
102 isc_region_consume(&sr
, 4);
103 RETERR(dns_time32_totext(when
, target
));
104 RETERR(str_totext(" ", target
));
107 when
= uint32_fromregion(&sr
);
108 isc_region_consume(&sr
, 4);
109 RETERR(dns_time32_totext(when
, target
));
110 RETERR(str_totext(" ", target
));
112 /* remove hold-down */
113 when
= uint32_fromregion(&sr
);
114 isc_region_consume(&sr
, 4);
115 RETERR(dns_time32_totext(when
, target
));
116 RETERR(str_totext(" ", target
));
119 flags
= uint16_fromregion(&sr
);
120 isc_region_consume(&sr
, 2);
121 sprintf(buf
, "%u", flags
);
122 RETERR(str_totext(buf
, target
));
123 RETERR(str_totext(" ", target
));
126 sprintf(buf
, "%u", sr
.base
[0]);
127 isc_region_consume(&sr
, 1);
128 RETERR(str_totext(buf
, target
));
129 RETERR(str_totext(" ", target
));
132 algorithm
= sr
.base
[0];
133 sprintf(buf
, "%u", algorithm
);
134 isc_region_consume(&sr
, 1);
135 RETERR(str_totext(buf
, target
));
138 if ((flags
& 0xc000) == 0xc000)
139 return (ISC_R_SUCCESS
);
142 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
143 RETERR(str_totext(" (", target
));
144 RETERR(str_totext(tctx
->linebreak
, target
));
145 RETERR(isc_base64_totext(&sr
, tctx
->width
- 2,
146 tctx
->linebreak
, target
));
148 if ((tctx
->flags
& DNS_STYLEFLAG_COMMENT
) != 0)
149 RETERR(str_totext(tctx
->linebreak
, target
));
150 else if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
151 RETERR(str_totext(" ", target
));
153 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
154 RETERR(str_totext(")", target
));
156 if ((tctx
->flags
& DNS_STYLEFLAG_COMMENT
) != 0) {
159 RETERR(str_totext(" ; key id = ", target
));
160 dns_rdata_toregion(rdata
, &tmpr
);
161 /* Skip over refresh, addhd, and removehd */
162 isc_region_consume(&tmpr
, 12);
163 sprintf(buf
, "%u", dst_region_computeid(&tmpr
, algorithm
));
164 RETERR(str_totext(buf
, target
));
166 return (ISC_R_SUCCESS
);
169 static inline isc_result_t
170 fromwire_keydata(ARGS_FROMWIRE
) {
173 REQUIRE(type
== 65533);
180 isc_buffer_activeregion(source
, &sr
);
182 return (ISC_R_UNEXPECTEDEND
);
184 isc_buffer_forward(source
, sr
.length
);
185 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
188 static inline isc_result_t
189 towire_keydata(ARGS_TOWIRE
) {
192 REQUIRE(rdata
->type
== 65533);
193 REQUIRE(rdata
->length
!= 0);
197 dns_rdata_toregion(rdata
, &sr
);
198 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
202 compare_keydata(ARGS_COMPARE
) {
206 REQUIRE(rdata1
->type
== rdata2
->type
);
207 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
208 REQUIRE(rdata1
->type
== 65533);
209 REQUIRE(rdata1
->length
!= 0);
210 REQUIRE(rdata2
->length
!= 0);
212 dns_rdata_toregion(rdata1
, &r1
);
213 dns_rdata_toregion(rdata2
, &r2
);
214 return (isc_region_compare(&r1
, &r2
));
217 static inline isc_result_t
218 fromstruct_keydata(ARGS_FROMSTRUCT
) {
219 dns_rdata_keydata_t
*keydata
= source
;
221 REQUIRE(type
== 65533);
222 REQUIRE(source
!= NULL
);
223 REQUIRE(keydata
->common
.rdtype
== type
);
224 REQUIRE(keydata
->common
.rdclass
== rdclass
);
230 RETERR(uint32_tobuffer(keydata
->refresh
, target
));
233 RETERR(uint32_tobuffer(keydata
->addhd
, target
));
235 /* Remove hold-down */
236 RETERR(uint32_tobuffer(keydata
->removehd
, target
));
239 RETERR(uint16_tobuffer(keydata
->flags
, target
));
242 RETERR(uint8_tobuffer(keydata
->protocol
, target
));
245 RETERR(uint8_tobuffer(keydata
->algorithm
, target
));
248 return (mem_tobuffer(target
, keydata
->data
, keydata
->datalen
));
251 static inline isc_result_t
252 tostruct_keydata(ARGS_TOSTRUCT
) {
253 dns_rdata_keydata_t
*keydata
= target
;
256 REQUIRE(rdata
->type
== 65533);
257 REQUIRE(target
!= NULL
);
258 REQUIRE(rdata
->length
!= 0);
260 keydata
->common
.rdclass
= rdata
->rdclass
;
261 keydata
->common
.rdtype
= rdata
->type
;
262 ISC_LINK_INIT(&keydata
->common
, link
);
264 dns_rdata_toregion(rdata
, &sr
);
268 return (ISC_R_UNEXPECTEDEND
);
269 keydata
->refresh
= uint32_fromregion(&sr
);
270 isc_region_consume(&sr
, 4);
274 return (ISC_R_UNEXPECTEDEND
);
275 keydata
->addhd
= uint32_fromregion(&sr
);
276 isc_region_consume(&sr
, 4);
278 /* Remove hold-down */
280 return (ISC_R_UNEXPECTEDEND
);
281 keydata
->removehd
= uint32_fromregion(&sr
);
282 isc_region_consume(&sr
, 4);
286 return (ISC_R_UNEXPECTEDEND
);
287 keydata
->flags
= uint16_fromregion(&sr
);
288 isc_region_consume(&sr
, 2);
292 return (ISC_R_UNEXPECTEDEND
);
293 keydata
->protocol
= uint8_fromregion(&sr
);
294 isc_region_consume(&sr
, 1);
298 return (ISC_R_UNEXPECTEDEND
);
299 keydata
->algorithm
= uint8_fromregion(&sr
);
300 isc_region_consume(&sr
, 1);
303 keydata
->datalen
= sr
.length
;
304 keydata
->data
= mem_maybedup(mctx
, sr
.base
, keydata
->datalen
);
305 if (keydata
->data
== NULL
)
306 return (ISC_R_NOMEMORY
);
308 keydata
->mctx
= mctx
;
309 return (ISC_R_SUCCESS
);
313 freestruct_keydata(ARGS_FREESTRUCT
) {
314 dns_rdata_keydata_t
*keydata
= (dns_rdata_keydata_t
*) source
;
316 REQUIRE(source
!= NULL
);
317 REQUIRE(keydata
->common
.rdtype
== 65533);
319 if (keydata
->mctx
== NULL
)
322 if (keydata
->data
!= NULL
)
323 isc_mem_free(keydata
->mctx
, keydata
->data
);
324 keydata
->mctx
= NULL
;
327 static inline isc_result_t
328 additionaldata_keydata(ARGS_ADDLDATA
) {
329 REQUIRE(rdata
->type
== 65533);
335 return (ISC_R_SUCCESS
);
338 static inline isc_result_t
339 digest_keydata(ARGS_DIGEST
) {
342 REQUIRE(rdata
->type
== 65533);
344 dns_rdata_toregion(rdata
, &r
);
346 return ((digest
)(arg
, &r
));
349 static inline isc_boolean_t
350 checkowner_keydata(ARGS_CHECKOWNER
) {
352 REQUIRE(type
== 65533);
362 static inline isc_boolean_t
363 checknames_keydata(ARGS_CHECKNAMES
) {
365 REQUIRE(rdata
->type
== 65533);
375 casecompare_keydata(ARGS_COMPARE
) {
376 return (compare_keydata(rdata1
, rdata2
));
379 #endif /* GENERIC_KEYDATA_65533_C */