Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / tkey_249.c
blob7dfb482f296c6620ab5d7993b025d74e781c0dbb
1 /* $NetBSD: tkey_249.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007, 2009, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id */
23 * Reviewed: Thu Mar 16 17:35:30 PST 2000 by halley.
26 /* draft-ietf-dnsext-tkey-01.txt */
28 #ifndef RDATA_GENERIC_TKEY_249_C
29 #define RDATA_GENERIC_TKEY_249_C
31 #define RRTYPE_TKEY_ATTRIBUTES (DNS_RDATATYPEATTR_META)
33 static inline isc_result_t
34 fromtext_tkey(ARGS_FROMTEXT) {
35 isc_token_t token;
36 dns_rcode_t rcode;
37 dns_name_t name;
38 isc_buffer_t buffer;
39 long i;
40 char *e;
42 REQUIRE(type == 249);
44 UNUSED(type);
45 UNUSED(rdclass);
46 UNUSED(callbacks);
49 * Algorithm.
51 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
52 ISC_FALSE));
53 dns_name_init(&name, NULL);
54 buffer_fromregion(&buffer, &token.value.as_region);
55 origin = (origin != NULL) ? origin : dns_rootname;
56 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
60 * Inception.
62 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
63 ISC_FALSE));
64 RETERR(uint32_tobuffer(token.value.as_ulong, target));
67 * Expiration.
69 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
70 ISC_FALSE));
71 RETERR(uint32_tobuffer(token.value.as_ulong, target));
74 * Mode.
76 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
77 ISC_FALSE));
78 if (token.value.as_ulong > 0xffffU)
79 RETTOK(ISC_R_RANGE);
80 RETERR(uint16_tobuffer(token.value.as_ulong, target));
83 * Error.
85 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
86 ISC_FALSE));
87 if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion)
88 != ISC_R_SUCCESS)
90 i = strtol(DNS_AS_STR(token), &e, 10);
91 if (*e != 0)
92 RETTOK(DNS_R_UNKNOWN);
93 if (i < 0 || i > 0xffff)
94 RETTOK(ISC_R_RANGE);
95 rcode = (dns_rcode_t)i;
97 RETERR(uint16_tobuffer(rcode, target));
100 * Key Size.
102 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
103 ISC_FALSE));
104 if (token.value.as_ulong > 0xffffU)
105 RETTOK(ISC_R_RANGE);
106 RETERR(uint16_tobuffer(token.value.as_ulong, target));
109 * Key Data.
111 RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
114 * Other Size.
116 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
117 ISC_FALSE));
118 if (token.value.as_ulong > 0xffffU)
119 RETTOK(ISC_R_RANGE);
120 RETERR(uint16_tobuffer(token.value.as_ulong, target));
123 * Other Data.
125 return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
128 static inline isc_result_t
129 totext_tkey(ARGS_TOTEXT) {
130 isc_region_t sr, dr;
131 char buf[sizeof("4294967295 ")];
132 unsigned long n;
133 dns_name_t name;
134 dns_name_t prefix;
135 isc_boolean_t sub;
137 REQUIRE(rdata->type == 249);
138 REQUIRE(rdata->length != 0);
140 dns_rdata_toregion(rdata, &sr);
143 * Algorithm.
145 dns_name_init(&name, NULL);
146 dns_name_init(&prefix, NULL);
147 dns_name_fromregion(&name, &sr);
148 sub = name_prefix(&name, tctx->origin, &prefix);
149 RETERR(dns_name_totext(&prefix, sub, target));
150 RETERR(str_totext(" ", target));
151 isc_region_consume(&sr, name_length(&name));
154 * Inception.
156 n = uint32_fromregion(&sr);
157 isc_region_consume(&sr, 4);
158 sprintf(buf, "%lu ", n);
159 RETERR(str_totext(buf, target));
162 * Expiration.
164 n = uint32_fromregion(&sr);
165 isc_region_consume(&sr, 4);
166 sprintf(buf, "%lu ", n);
167 RETERR(str_totext(buf, target));
170 * Mode.
172 n = uint16_fromregion(&sr);
173 isc_region_consume(&sr, 2);
174 sprintf(buf, "%lu ", n);
175 RETERR(str_totext(buf, target));
178 * Error.
180 n = uint16_fromregion(&sr);
181 isc_region_consume(&sr, 2);
182 if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
183 RETERR(str_totext(" ", target));
184 else {
185 sprintf(buf, "%lu ", n);
186 RETERR(str_totext(buf, target));
190 * Key Size.
192 n = uint16_fromregion(&sr);
193 isc_region_consume(&sr, 2);
194 sprintf(buf, "%lu", n);
195 RETERR(str_totext(buf, target));
198 * Key Data.
200 REQUIRE(n <= sr.length);
201 dr = sr;
202 dr.length = n;
203 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
204 RETERR(str_totext(" (", target));
205 RETERR(str_totext(tctx->linebreak, target));
206 if (tctx->width == 0) /* No splitting */
207 RETERR(isc_base64_totext(&dr, 60, "", target));
208 else
209 RETERR(isc_base64_totext(&dr, tctx->width - 2,
210 tctx->linebreak, target));
211 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
212 RETERR(str_totext(" ) ", target));
213 else
214 RETERR(str_totext(" ", target));
215 isc_region_consume(&sr, n);
218 * Other Size.
220 n = uint16_fromregion(&sr);
221 isc_region_consume(&sr, 2);
222 sprintf(buf, "%lu", n);
223 RETERR(str_totext(buf, target));
226 * Other Data.
228 REQUIRE(n <= sr.length);
229 if (n != 0U) {
230 dr = sr;
231 dr.length = n;
232 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
233 RETERR(str_totext(" (", target));
234 RETERR(str_totext(tctx->linebreak, target));
235 if (tctx->width == 0) /* No splitting */
236 RETERR(isc_base64_totext(&dr, 60, "", target));
237 else
238 RETERR(isc_base64_totext(&dr, tctx->width - 2,
239 tctx->linebreak, target));
240 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
241 RETERR(str_totext(" )", target));
243 return (ISC_R_SUCCESS);
246 static inline isc_result_t
247 fromwire_tkey(ARGS_FROMWIRE) {
248 isc_region_t sr;
249 unsigned long n;
250 dns_name_t name;
252 REQUIRE(type == 249);
254 UNUSED(type);
255 UNUSED(rdclass);
257 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
260 * Algorithm.
262 dns_name_init(&name, NULL);
263 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
266 * Inception: 4
267 * Expiration: 4
268 * Mode: 2
269 * Error: 2
271 isc_buffer_activeregion(source, &sr);
272 if (sr.length < 12)
273 return (ISC_R_UNEXPECTEDEND);
274 RETERR(mem_tobuffer(target, sr.base, 12));
275 isc_region_consume(&sr, 12);
276 isc_buffer_forward(source, 12);
279 * Key Length + Key Data.
281 if (sr.length < 2)
282 return (ISC_R_UNEXPECTEDEND);
283 n = uint16_fromregion(&sr);
284 if (sr.length < n + 2)
285 return (ISC_R_UNEXPECTEDEND);
286 RETERR(mem_tobuffer(target, sr.base, n + 2));
287 isc_region_consume(&sr, n + 2);
288 isc_buffer_forward(source, n + 2);
291 * Other Length + Other Data.
293 if (sr.length < 2)
294 return (ISC_R_UNEXPECTEDEND);
295 n = uint16_fromregion(&sr);
296 if (sr.length < n + 2)
297 return (ISC_R_UNEXPECTEDEND);
298 isc_buffer_forward(source, n + 2);
299 return (mem_tobuffer(target, sr.base, n + 2));
302 static inline isc_result_t
303 towire_tkey(ARGS_TOWIRE) {
304 isc_region_t sr;
305 dns_name_t name;
306 dns_offsets_t offsets;
308 REQUIRE(rdata->type == 249);
309 REQUIRE(rdata->length != 0);
311 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
313 * Algorithm.
315 dns_rdata_toregion(rdata, &sr);
316 dns_name_init(&name, offsets);
317 dns_name_fromregion(&name, &sr);
318 RETERR(dns_name_towire(&name, cctx, target));
319 isc_region_consume(&sr, name_length(&name));
321 return (mem_tobuffer(target, sr.base, sr.length));
324 static inline int
325 compare_tkey(ARGS_COMPARE) {
326 isc_region_t r1;
327 isc_region_t r2;
328 dns_name_t name1;
329 dns_name_t name2;
330 int order;
332 REQUIRE(rdata1->type == rdata2->type);
333 REQUIRE(rdata1->rdclass == rdata2->rdclass);
334 REQUIRE(rdata1->type == 249);
335 REQUIRE(rdata1->length != 0);
336 REQUIRE(rdata2->length != 0);
339 * Algorithm.
341 dns_rdata_toregion(rdata1, &r1);
342 dns_rdata_toregion(rdata2, &r2);
343 dns_name_init(&name1, NULL);
344 dns_name_init(&name2, NULL);
345 dns_name_fromregion(&name1, &r1);
346 dns_name_fromregion(&name2, &r2);
347 if ((order = dns_name_rdatacompare(&name1, &name2)) != 0)
348 return (order);
349 isc_region_consume(&r1, name_length(&name1));
350 isc_region_consume(&r2, name_length(&name2));
351 return (isc_region_compare(&r1, &r2));
354 static inline isc_result_t
355 fromstruct_tkey(ARGS_FROMSTRUCT) {
356 dns_rdata_tkey_t *tkey = source;
358 REQUIRE(type == 249);
359 REQUIRE(source != NULL);
360 REQUIRE(tkey->common.rdtype == type);
361 REQUIRE(tkey->common.rdclass == rdclass);
363 UNUSED(type);
364 UNUSED(rdclass);
367 * Algorithm Name.
369 RETERR(name_tobuffer(&tkey->algorithm, target));
372 * Inception: 32 bits.
374 RETERR(uint32_tobuffer(tkey->inception, target));
377 * Expire: 32 bits.
379 RETERR(uint32_tobuffer(tkey->expire, target));
382 * Mode: 16 bits.
384 RETERR(uint16_tobuffer(tkey->mode, target));
387 * Error: 16 bits.
389 RETERR(uint16_tobuffer(tkey->error, target));
392 * Key size: 16 bits.
394 RETERR(uint16_tobuffer(tkey->keylen, target));
397 * Key.
399 RETERR(mem_tobuffer(target, tkey->key, tkey->keylen));
402 * Other size: 16 bits.
404 RETERR(uint16_tobuffer(tkey->otherlen, target));
407 * Other data.
409 return (mem_tobuffer(target, tkey->other, tkey->otherlen));
412 static inline isc_result_t
413 tostruct_tkey(ARGS_TOSTRUCT) {
414 dns_rdata_tkey_t *tkey = target;
415 dns_name_t alg;
416 isc_region_t sr;
418 REQUIRE(rdata->type == 249);
419 REQUIRE(target != NULL);
420 REQUIRE(rdata->length != 0);
422 tkey->common.rdclass = rdata->rdclass;
423 tkey->common.rdtype = rdata->type;
424 ISC_LINK_INIT(&tkey->common, link);
426 dns_rdata_toregion(rdata, &sr);
429 * Algorithm Name.
431 dns_name_init(&alg, NULL);
432 dns_name_fromregion(&alg, &sr);
433 dns_name_init(&tkey->algorithm, NULL);
434 RETERR(name_duporclone(&alg, mctx, &tkey->algorithm));
435 isc_region_consume(&sr, name_length(&tkey->algorithm));
438 * Inception.
440 tkey->inception = uint32_fromregion(&sr);
441 isc_region_consume(&sr, 4);
444 * Expire.
446 tkey->expire = uint32_fromregion(&sr);
447 isc_region_consume(&sr, 4);
450 * Mode.
452 tkey->mode = uint16_fromregion(&sr);
453 isc_region_consume(&sr, 2);
456 * Error.
458 tkey->error = uint16_fromregion(&sr);
459 isc_region_consume(&sr, 2);
462 * Key size.
464 tkey->keylen = uint16_fromregion(&sr);
465 isc_region_consume(&sr, 2);
468 * Key.
470 INSIST(tkey->keylen + 2U <= sr.length);
471 tkey->key = mem_maybedup(mctx, sr.base, tkey->keylen);
472 if (tkey->key == NULL)
473 goto cleanup;
474 isc_region_consume(&sr, tkey->keylen);
477 * Other size.
479 tkey->otherlen = uint16_fromregion(&sr);
480 isc_region_consume(&sr, 2);
483 * Other.
485 INSIST(tkey->otherlen <= sr.length);
486 tkey->other = mem_maybedup(mctx, sr.base, tkey->otherlen);
487 if (tkey->other == NULL)
488 goto cleanup;
490 tkey->mctx = mctx;
491 return (ISC_R_SUCCESS);
493 cleanup:
494 if (mctx != NULL)
495 dns_name_free(&tkey->algorithm, mctx);
496 if (mctx != NULL && tkey->key != NULL)
497 isc_mem_free(mctx, tkey->key);
498 return (ISC_R_NOMEMORY);
501 static inline void
502 freestruct_tkey(ARGS_FREESTRUCT) {
503 dns_rdata_tkey_t *tkey = (dns_rdata_tkey_t *) source;
505 REQUIRE(source != NULL);
507 if (tkey->mctx == NULL)
508 return;
510 dns_name_free(&tkey->algorithm, tkey->mctx);
511 if (tkey->key != NULL)
512 isc_mem_free(tkey->mctx, tkey->key);
513 if (tkey->other != NULL)
514 isc_mem_free(tkey->mctx, tkey->other);
515 tkey->mctx = NULL;
518 static inline isc_result_t
519 additionaldata_tkey(ARGS_ADDLDATA) {
520 UNUSED(rdata);
521 UNUSED(add);
522 UNUSED(arg);
524 REQUIRE(rdata->type == 249);
526 return (ISC_R_SUCCESS);
529 static inline isc_result_t
530 digest_tkey(ARGS_DIGEST) {
531 UNUSED(rdata);
532 UNUSED(digest);
533 UNUSED(arg);
535 REQUIRE(rdata->type == 249);
537 return (ISC_R_NOTIMPLEMENTED);
540 static inline isc_boolean_t
541 checkowner_tkey(ARGS_CHECKOWNER) {
543 REQUIRE(type == 249);
545 UNUSED(name);
546 UNUSED(type);
547 UNUSED(rdclass);
548 UNUSED(wildcard);
550 return (ISC_TRUE);
553 static inline isc_boolean_t
554 checknames_tkey(ARGS_CHECKNAMES) {
556 REQUIRE(rdata->type == 249);
558 UNUSED(rdata);
559 UNUSED(owner);
560 UNUSED(bad);
562 return (ISC_TRUE);
565 static inline isc_result_t
566 casecompare_tkey(ARGS_COMPARE) {
567 return (compare_tkey(rdata1, rdata2));
569 #endif /* RDATA_GENERIC_TKEY_249_C */