2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: key_25.c,v 1.51 2007/06/19 23:47:17 tbox Exp $ */
21 * Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
26 #ifndef RDATA_GENERIC_KEY_25_C
27 #define RDATA_GENERIC_KEY_25_C
31 #define RRTYPE_KEY_ATTRIBUTES (0)
33 static inline isc_result_t
34 fromtext_key(ARGS_FROMTEXT
) {
49 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
51 RETTOK(dns_keyflags_fromtext(&flags
, &token
.value
.as_textregion
));
52 RETERR(uint16_tobuffer(flags
, target
));
55 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
57 RETTOK(dns_secproto_fromtext(&proto
, &token
.value
.as_textregion
));
58 RETERR(mem_tobuffer(target
, &proto
, 1));
61 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
63 RETTOK(dns_secalg_fromtext(&alg
, &token
.value
.as_textregion
));
64 RETERR(mem_tobuffer(target
, &alg
, 1));
67 if ((flags
& 0xc000) == 0xc000)
68 return (ISC_R_SUCCESS
);
70 return (isc_base64_tobuffer(lexer
, target
, -1));
73 static inline isc_result_t
74 totext_key(ARGS_TOTEXT
) {
76 char buf
[sizeof("64000")];
78 unsigned char algorithm
;
80 REQUIRE(rdata
->type
== 25);
81 REQUIRE(rdata
->length
!= 0);
83 dns_rdata_toregion(rdata
, &sr
);
86 flags
= uint16_fromregion(&sr
);
87 isc_region_consume(&sr
, 2);
88 sprintf(buf
, "%u", flags
);
89 RETERR(str_totext(buf
, target
));
90 RETERR(str_totext(" ", target
));
93 sprintf(buf
, "%u", sr
.base
[0]);
94 isc_region_consume(&sr
, 1);
95 RETERR(str_totext(buf
, target
));
96 RETERR(str_totext(" ", target
));
99 algorithm
= sr
.base
[0];
100 sprintf(buf
, "%u", algorithm
);
101 isc_region_consume(&sr
, 1);
102 RETERR(str_totext(buf
, target
));
105 if ((flags
& 0xc000) == 0xc000)
106 return (ISC_R_SUCCESS
);
109 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
110 RETERR(str_totext(" (", target
));
111 RETERR(str_totext(tctx
->linebreak
, target
));
112 RETERR(isc_base64_totext(&sr
, tctx
->width
- 2,
113 tctx
->linebreak
, target
));
115 if ((tctx
->flags
& DNS_STYLEFLAG_COMMENT
) != 0)
116 RETERR(str_totext(tctx
->linebreak
, target
));
117 else if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
118 RETERR(str_totext(" ", target
));
120 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
121 RETERR(str_totext(")", target
));
123 if ((tctx
->flags
& DNS_STYLEFLAG_COMMENT
) != 0) {
126 RETERR(str_totext(" ; key id = ", target
));
127 dns_rdata_toregion(rdata
, &tmpr
);
128 sprintf(buf
, "%u", dst_region_computeid(&tmpr
, algorithm
));
129 RETERR(str_totext(buf
, target
));
131 return (ISC_R_SUCCESS
);
134 static inline isc_result_t
135 fromwire_key(ARGS_FROMWIRE
) {
145 isc_buffer_activeregion(source
, &sr
);
147 return (ISC_R_UNEXPECTEDEND
);
149 isc_buffer_forward(source
, sr
.length
);
150 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
153 static inline isc_result_t
154 towire_key(ARGS_TOWIRE
) {
157 REQUIRE(rdata
->type
== 25);
158 REQUIRE(rdata
->length
!= 0);
162 dns_rdata_toregion(rdata
, &sr
);
163 return (mem_tobuffer(target
, sr
.base
, sr
.length
));
167 compare_key(ARGS_COMPARE
) {
171 REQUIRE(rdata1
->type
== rdata2
->type
);
172 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
173 REQUIRE(rdata1
->type
== 25);
174 REQUIRE(rdata1
->length
!= 0);
175 REQUIRE(rdata2
->length
!= 0);
177 dns_rdata_toregion(rdata1
, &r1
);
178 dns_rdata_toregion(rdata2
, &r2
);
179 return (isc_region_compare(&r1
, &r2
));
182 static inline isc_result_t
183 fromstruct_key(ARGS_FROMSTRUCT
) {
184 dns_rdata_key_t
*key
= source
;
187 REQUIRE(source
!= NULL
);
188 REQUIRE(key
->common
.rdtype
== type
);
189 REQUIRE(key
->common
.rdclass
== rdclass
);
195 RETERR(uint16_tobuffer(key
->flags
, target
));
198 RETERR(uint8_tobuffer(key
->protocol
, target
));
201 RETERR(uint8_tobuffer(key
->algorithm
, target
));
204 return (mem_tobuffer(target
, key
->data
, key
->datalen
));
207 static inline isc_result_t
208 tostruct_key(ARGS_TOSTRUCT
) {
209 dns_rdata_key_t
*key
= target
;
212 REQUIRE(rdata
->type
== 25);
213 REQUIRE(target
!= NULL
);
214 REQUIRE(rdata
->length
!= 0);
216 key
->common
.rdclass
= rdata
->rdclass
;
217 key
->common
.rdtype
= rdata
->type
;
218 ISC_LINK_INIT(&key
->common
, link
);
220 dns_rdata_toregion(rdata
, &sr
);
224 return (ISC_R_UNEXPECTEDEND
);
225 key
->flags
= uint16_fromregion(&sr
);
226 isc_region_consume(&sr
, 2);
230 return (ISC_R_UNEXPECTEDEND
);
231 key
->protocol
= uint8_fromregion(&sr
);
232 isc_region_consume(&sr
, 1);
236 return (ISC_R_UNEXPECTEDEND
);
237 key
->algorithm
= uint8_fromregion(&sr
);
238 isc_region_consume(&sr
, 1);
241 key
->datalen
= sr
.length
;
242 key
->data
= mem_maybedup(mctx
, sr
.base
, key
->datalen
);
243 if (key
->data
== NULL
)
244 return (ISC_R_NOMEMORY
);
247 return (ISC_R_SUCCESS
);
251 freestruct_key(ARGS_FREESTRUCT
) {
252 dns_rdata_key_t
*key
= (dns_rdata_key_t
*) source
;
254 REQUIRE(source
!= NULL
);
255 REQUIRE(key
->common
.rdtype
== 25);
257 if (key
->mctx
== NULL
)
260 if (key
->data
!= NULL
)
261 isc_mem_free(key
->mctx
, key
->data
);
265 static inline isc_result_t
266 additionaldata_key(ARGS_ADDLDATA
) {
267 REQUIRE(rdata
->type
== 25);
273 return (ISC_R_SUCCESS
);
276 static inline isc_result_t
277 digest_key(ARGS_DIGEST
) {
280 REQUIRE(rdata
->type
== 25);
282 dns_rdata_toregion(rdata
, &r
);
284 return ((digest
)(arg
, &r
));
287 static inline isc_boolean_t
288 checkowner_key(ARGS_CHECKOWNER
) {
300 static inline isc_boolean_t
301 checknames_key(ARGS_CHECKNAMES
) {
303 REQUIRE(rdata
->type
== 25);
312 #endif /* RDATA_GENERIC_KEY_25_C */