keydata_65533.c revision 3d17a3ba61a303d5c4d9867068d0fbe9f24d2988
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews/*
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * purpose with or without fee is hereby granted, provided that the above
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
15a44745412679c30a6d022733925af70a38b715David Lawrence */
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews/* $Id: keydata_65533.c,v 1.3 2009/12/04 21:09:33 marka Exp $ */
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence#ifndef GENERIC_KEYDATA_65533_C
6b7257f756eb0530cdf54df9a7fab8d51a5001c3David Lawrence#define GENERIC_KEYDATA_65533_C 1
6b7257f756eb0530cdf54df9a7fab8d51a5001c3David Lawrence
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <dst/dst.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#define RRTYPE_KEYDATA_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graffstatic inline isc_result_t
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halleyfromtext_keydata(ARGS_FROMTEXT) {
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff isc_token_t token;
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff dns_secalg_t alg;
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff dns_secproto_t proto;
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff dns_keyflags_t flags;
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews isc_uint32_t refresh, addhd, removehd;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews REQUIRE(type == 65533);
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(type);
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews UNUSED(rdclass);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(origin);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence UNUSED(options);
5236050c0f819b727dfc4850133f5194f346f76fDanny Mayer UNUSED(callbacks);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley /* refresh timer */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_FALSE));
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &refresh));
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence RETERR(uint32_tobuffer(refresh, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* add hold-down */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_FALSE));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &addhd));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint32_tobuffer(addhd, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* remove hold-down */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_FALSE));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &removehd));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint32_tobuffer(removehd, target));
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence /* flags */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_FALSE));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETTOK(dns_keyflags_fromtext(&flags, &token.value.as_textregion));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint16_tobuffer(flags, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence /* protocol */
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence ISC_FALSE));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETTOK(dns_secproto_fromtext(&proto, &token.value.as_textregion));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(mem_tobuffer(target, &proto, 1));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence /* algorithm */
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence ISC_FALSE));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETTOK(dns_secalg_fromtext(&alg, &token.value.as_textregion));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(mem_tobuffer(target, &alg, 1));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* No Key? */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if ((flags & 0xc000) == 0xc000)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (isc_base64_tobuffer(lexer, target, -1));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline isc_result_t
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstotext_keydata(ARGS_TOTEXT) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_t sr;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews char buf[sizeof("64000")];
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned int flags;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned char algorithm;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned long when;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata->type == 65533);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata->length != 0);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_rdata_toregion(rdata, &sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* refresh timer */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews when = uint32_fromregion(&sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 4);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(dns_time32_totext(when, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(" ", target));
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* add hold-down */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews when = uint32_fromregion(&sr);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence isc_region_consume(&sr, 4);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(dns_time32_totext(when, target));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(str_totext(" ", target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* remove hold-down */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews when = uint32_fromregion(&sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 4);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(dns_time32_totext(when, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(" ", target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley /* flags */
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley flags = uint16_fromregion(&sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 2);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence sprintf(buf, "%u", flags);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(str_totext(buf, target));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(str_totext(" ", target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* protocol */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews sprintf(buf, "%u", sr.base[0]);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 1);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(buf, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(" ", target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* algorithm */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews algorithm = sr.base[0];
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews sprintf(buf, "%u", algorithm);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 1);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(buf, target));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence /* No Key? */
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence if ((flags & 0xc000) == 0xc000)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* key */
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(str_totext(" (", target));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(str_totext(tctx->linebreak, target));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(isc_base64_totext(&sr, tctx->width - 2,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews tctx->linebreak, target));
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence if ((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(tctx->linebreak, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(" ", target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(str_totext(")", target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if ((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_t tmpr;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff RETERR(str_totext(" ; key id = ", target));
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews dns_rdata_toregion(rdata, &tmpr);
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews /* Skip over refresh, addhd, and removehd */
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews isc_region_consume(&tmpr, 12);
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews sprintf(buf, "%u", dst_region_computeid(&tmpr, algorithm));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington RETERR(str_totext(buf, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews }
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_SUCCESS);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline isc_result_t
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsfromwire_keydata(ARGS_FROMWIRE) {
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews isc_region_t sr;
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews REQUIRE(type == 65533);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews UNUSED(type);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(rdclass);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(dctx);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(options);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_activeregion(source, &sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if (sr.length < 4)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_UNEXPECTEDEND);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_forward(source, sr.length);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (mem_tobuffer(target, sr.base, sr.length));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewsstatic inline isc_result_t
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewstowire_keydata(ARGS_TOWIRE) {
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews isc_region_t sr;
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews REQUIRE(rdata->type == 65533);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata->length != 0);
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington UNUSED(cctx);
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington dns_rdata_toregion(rdata, &sr);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews return (mem_tobuffer(target, sr.base, sr.length));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline int
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewscompare_keydata(ARGS_COMPARE) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_t r1;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_t r2;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata1->type == rdata2->type);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews REQUIRE(rdata1->rdclass == rdata2->rdclass);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata1->type == 65533);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews REQUIRE(rdata1->length != 0);
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington REQUIRE(rdata2->length != 0);
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews dns_rdata_toregion(rdata1, &r1);
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington dns_rdata_toregion(rdata2, &r2);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (isc_region_compare(&r1, &r2));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline isc_result_t
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrewsfromstruct_keydata(ARGS_FROMSTRUCT) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_rdata_keydata_t *keydata = source;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews REQUIRE(type == 65533);
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington REQUIRE(source != NULL);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence REQUIRE(keydata->common.rdtype == type);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence REQUIRE(keydata->common.rdclass == rdclass);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence UNUSED(type);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(rdclass);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence /* Refresh timer */
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence RETERR(uint32_tobuffer(keydata->refresh, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Add hold-down */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint32_tobuffer(keydata->addhd, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence /* Remove hold-down */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint32_tobuffer(keydata->removehd, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Flags */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint16_tobuffer(keydata->flags, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Protocol */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint8_tobuffer(keydata->protocol, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Algorithm */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RETERR(uint8_tobuffer(keydata->algorithm, target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Data */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (mem_tobuffer(target, keydata->data, keydata->datalen));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline isc_result_t
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstostruct_keydata(ARGS_TOSTRUCT) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_rdata_keydata_t *keydata = target;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_t sr;
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence REQUIRE(rdata->type == 65533);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence REQUIRE(target != NULL);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence REQUIRE(rdata->length != 0);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence keydata->common.rdclass = rdata->rdclass;
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence keydata->common.rdtype = rdata->type;
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence ISC_LINK_INIT(&keydata->common, link);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence dns_rdata_toregion(rdata, &sr);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence /* Refresh timer */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if (sr.length < 4)
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence return (ISC_R_UNEXPECTEDEND);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence keydata->refresh = uint32_fromregion(&sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 4);
ea023072092112a831ca7c2943387ccbb422a3f2Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Add hold-down */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if (sr.length < 4)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_UNEXPECTEDEND);
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff keydata->addhd = uint32_fromregion(&sr);
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington isc_region_consume(&sr, 4);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington /* Remove hold-down */
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews if (sr.length < 4)
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews return (ISC_R_UNEXPECTEDEND);
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington keydata->removehd = uint32_fromregion(&sr);
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington isc_region_consume(&sr, 4);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington /* Flags */
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington if (sr.length < 2)
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington return (ISC_R_UNEXPECTEDEND);
171d0db7f93bf796f870713d6208b21893401cfcBrian Wellington keydata->flags = uint16_fromregion(&sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 2);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Protocol */
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews if (sr.length < 1)
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington return (ISC_R_UNEXPECTEDEND);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews keydata->protocol = uint8_fromregion(&sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 1);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Algorithm */
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence if (sr.length < 1)
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence return (ISC_R_UNEXPECTEDEND);
ca81c3971cd0c9cfd830c0a18289d4d1b0f9de01David Lawrence keydata->algorithm = uint8_fromregion(&sr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_consume(&sr, 1);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /* Data */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews keydata->datalen = sr.length;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews keydata->data = mem_maybedup(mctx, sr.base, keydata->datalen);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if (keydata->data == NULL)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_NOMEMORY);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews keydata->mctx = mctx;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsfreestruct_keydata(ARGS_FREESTRUCT) {
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrence dns_rdata_keydata_t *keydata = (dns_rdata_keydata_t *) source;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(source != NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(keydata->common.rdtype == 65533);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff if (keydata->mctx == NULL)
03084608809afbaf570093a14d2dc4ad507336a0Brian Wellington return;
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
347ccc2716b45b8c72a1021d7a74faab49d3eefaBrian Wellington if (keydata->data != NULL)
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews isc_mem_free(keydata->mctx, keydata->data);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews keydata->mctx = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline isc_result_t
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsadditionaldata_keydata(ARGS_ADDLDATA) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata->type == 65533);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews UNUSED(rdata);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews UNUSED(add);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews UNUSED(arg);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrewsstatic inline isc_result_t
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdigest_keydata(ARGS_DIGEST) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_region_t r;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata->type == 65533);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_rdata_toregion(rdata, &r);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return ((digest)(arg, &r));
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline isc_boolean_t
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewscheckowner_keydata(ARGS_CHECKOWNER) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(type == 65533);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(name);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews UNUSED(type);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(rdclass);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(wildcard);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_TRUE);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews}
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewsstatic inline isc_boolean_t
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewschecknames_keydata(ARGS_CHECKNAMES) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews REQUIRE(rdata->type == 65533);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(rdata);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(owner);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews UNUSED(bad);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (ISC_TRUE);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline int
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewscasecompare_keydata(ARGS_COMPARE) {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (compare_keydata(rdata1, rdata2));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#endif /* GENERIC_KEYDATA_65533_C */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews