f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews/*
a134177ed9f82189504191d90f3ed9e97c2b47cbTinderbox User * Copyright (C) 1999-2004, 2007, 2009, 2011, 2012, 2014-2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id$ */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley/*
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley * Reviewed: Thu Mar 16 17:35:30 PST 2000 by halley.
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley */
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley/* draft-ietf-dnsext-tkey-01.txt */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#ifndef RDATA_GENERIC_TKEY_249_C
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#define RDATA_GENERIC_TKEY_249_C
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff#define RRTYPE_TKEY_ATTRIBUTES (DNS_RDATATYPEATTR_META)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromtext_tkey(ARGS_FROMTEXT) {
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_token_t token;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_rcode_t rcode;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_t name;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_buffer_t buffer;
63430de3450a99b7ae0cb05a95a26cff8cc66358David Lawrence long i;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews char *e;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_tkey);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(rdclass);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews UNUSED(callbacks);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Algorithm.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_init(&name, NULL);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence buffer_fromregion(&buffer, &token.value.as_region);
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews if (origin == NULL)
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews origin = dns_rootname;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Inception.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Expiration.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Mode.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews if (token.value.as_ulong > 0xffffU)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(ISC_R_RANGE);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Error.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion)
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington != ISC_R_SUCCESS)
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington {
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews i = strtol(DNS_AS_STR(token), &e, 10);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (*e != 0)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(DNS_R_UNKNOWN);
63430de3450a99b7ae0cb05a95a26cff8cc66358David Lawrence if (i < 0 || i > 0xffff)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(ISC_R_RANGE);
63430de3450a99b7ae0cb05a95a26cff8cc66358David Lawrence rcode = (dns_rcode_t)i;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews }
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews RETERR(uint16_tobuffer(rcode, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key Size.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews if (token.value.as_ulong > 0xffffU)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(ISC_R_RANGE);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key Data.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other Size.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews if (token.value.as_ulong > 0xffffU)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(ISC_R_RANGE);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other Data.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews}
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetotext_tkey(ARGS_TOTEXT) {
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley isc_region_t sr, dr;
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson char buf[sizeof("4294967295 ")];
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews unsigned long n;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_t name;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_t prefix;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_boolean_t sub;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_tkey);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews dns_rdata_toregion(rdata, &sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Algorithm.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_init(&name, NULL);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_init(&prefix, NULL);
5901928ef856543882f38b2318e8991ce2644d2bMark Andrews dns_name_fromregion(&name, &sr);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&name, tctx->origin, &prefix);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews RETERR(dns_name_totext(&prefix, sub, target));
2cd8a160b9e2c0c7a016b534652b5c909f36ed4aMark Andrews RETERR(str_totext(" ", target));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_region_consume(&sr, name_length(&name));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Inception.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint32_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, 4);
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%lu ", n);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(str_totext(buf, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Expiration.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint32_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, 4);
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%lu ", n);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(str_totext(buf, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Mode.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint16_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, 2);
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%lu ", n);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(str_totext(buf, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Error.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint16_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, 2);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews RETERR(str_totext(" ", target));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews else {
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%lu ", n);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews RETERR(str_totext(buf, target));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews }
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key Size.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint16_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, 2);
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%lu", n);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(str_totext(buf, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key Data.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews REQUIRE(n <= sr.length);
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley dr = sr;
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley dr.length = n;
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson RETERR(str_totext(" (", target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt if (tctx->width == 0) /* No splitting */
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt RETERR(isc_base64_totext(&dr, 60, "", target));
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt else
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt RETERR(isc_base64_totext(&dr, tctx->width - 2,
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt tctx->linebreak, target));
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson RETERR(str_totext(" ) ", target));
fad44a20eede1bbc66716241dede225500c91caaAndreas Gustafsson else
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence RETERR(str_totext(" ", target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, n);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other Size.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint16_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, 2);
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%lu", n);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(str_totext(buf, target));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other Data.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley REQUIRE(n <= sr.length);
5eb91bd90e3ad3426e5e3213031556a737cf3809Mark Andrews if (n != 0U) {
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson dr = sr;
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson dr.length = n;
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson RETERR(str_totext(" (", target));
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt if (tctx->width == 0) /* No splitting */
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt RETERR(isc_base64_totext(&dr, 60, "", target));
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt else
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt RETERR(isc_base64_totext(&dr, tctx->width - 2,
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt tctx->linebreak, target));
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson RETERR(str_totext(" )", target));
a3c9e34301218c7092cd8b6add6eec0957ab5483Andreas Gustafsson }
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley return (ISC_R_SUCCESS);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews}
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromwire_tkey(ARGS_FROMWIRE) {
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_t sr;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews unsigned long n;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_t name;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_tkey);
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(rdclass);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Algorithm.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_init(&name, NULL);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews RETERR(dns_name_fromwire(&name, source, dctx, options, target));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews * Inception: 4
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews * Expiration: 4
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews * Mode: 2
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews * Error: 2
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews */
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_activeregion(source, &sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews if (sr.length < 12)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(mem_tobuffer(target, sr.base, 12));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, 12);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_buffer_forward(source, 12);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key Length + Key Data.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews if (sr.length < 2)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint16_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews if (sr.length < n + 2)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews RETERR(mem_tobuffer(target, sr.base, n + 2));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_consume(&sr, n + 2);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_buffer_forward(source, n + 2);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other Length + Other Data.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews if (sr.length < 2)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews n = uint16_fromregion(&sr);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews if (sr.length < n + 2)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_buffer_forward(source, n + 2);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews return (mem_tobuffer(target, sr.base, n + 2));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews}
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetowire_tkey(ARGS_TOWIRE) {
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_t sr;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_t name;
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_offsets_t offsets;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_tkey);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Algorithm.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews dns_rdata_toregion(rdata, &sr);
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_name_init(&name, offsets);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_fromregion(&name, &sr);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews RETERR(dns_name_towire(&name, cctx, target));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_region_consume(&sr, name_length(&name));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews return (mem_tobuffer(target, sr.base, sr.length));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews}
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline int
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencecompare_tkey(ARGS_COMPARE) {
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_t r1;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews isc_region_t r2;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_t name1;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_t name2;
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson int order;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews REQUIRE(rdata1->type == rdata2->type);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(rdata1->rdclass == rdata2->rdclass);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_tkey);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata1->length != 0);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata2->length != 0);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Algorithm.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews dns_rdata_toregion(rdata1, &r1);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews dns_rdata_toregion(rdata2, &r2);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_init(&name1, NULL);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_init(&name2, NULL);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_name_fromregion(&name1, &r1);
5901928ef856543882f38b2318e8991ce2644d2bMark Andrews dns_name_fromregion(&name2, &r2);
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson if ((order = dns_name_rdatacompare(&name1, &name2)) != 0)
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson return (order);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_region_consume(&r1, name_length(&name1));
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_region_consume(&r2, name_length(&name2));
90e303b114e56db5809fdd19805243457fa43cd9Olafur Gudmundsson return (isc_region_compare(&r1, &r2));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews}
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromstruct_tkey(ARGS_FROMSTRUCT) {
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews dns_rdata_tkey_t *tkey = source;
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_tkey);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(source != NULL);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(tkey->common.rdtype == type);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(tkey->common.rdclass == rdclass);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson UNUSED(rdclass);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Algorithm Name.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson RETERR(name_tobuffer(&tkey->algorithm, target));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Inception: 32 bits.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(uint32_tobuffer(tkey->inception, target));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Expire: 32 bits.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(uint32_tobuffer(tkey->expire, target));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Mode: 16 bits.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(uint16_tobuffer(tkey->mode, target));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Error: 16 bits.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(uint16_tobuffer(tkey->error, target));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key size: 16 bits.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(uint16_tobuffer(tkey->keylen, target));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews RETERR(mem_tobuffer(target, tkey->key, tkey->keylen));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other size: 16 bits.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington RETERR(uint16_tobuffer(tkey->otherlen, target));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other data.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews return (mem_tobuffer(target, tkey->other, tkey->otherlen));
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews}
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetostruct_tkey(ARGS_TOSTRUCT) {
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_rdata_tkey_t *tkey = target;
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_name_t alg;
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_t sr;
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_tkey);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews REQUIRE(target != NULL);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->common.rdclass = rdata->rdclass;
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->common.rdtype = rdata->type;
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington ISC_LINK_INIT(&tkey->common, link);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_rdata_toregion(rdata, &sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Algorithm Name.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_name_init(&alg, NULL);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_name_fromregion(&alg, &sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_name_init(&tkey->algorithm, NULL);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews RETERR(name_duporclone(&alg, mctx, &tkey->algorithm));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, name_length(&tkey->algorithm));
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Inception.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->inception = uint32_fromregion(&sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, 4);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Expire.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->expire = uint32_fromregion(&sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, 4);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Mode.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->mode = uint16_fromregion(&sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, 2);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Error.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->error = uint16_fromregion(&sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, 2);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key size.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->keylen = uint16_fromregion(&sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, 2);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Key.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
1208790272c8547682be4114ca3492477a3598b5Mark Andrews INSIST(tkey->keylen + 2U <= sr.length);
85bdc128fcda11c89ec1d76ea4221f4fa8e4fc24Mark Andrews tkey->key = mem_maybedup(mctx, sr.base, tkey->keylen);
85bdc128fcda11c89ec1d76ea4221f4fa8e4fc24Mark Andrews if (tkey->key == NULL)
85bdc128fcda11c89ec1d76ea4221f4fa8e4fc24Mark Andrews goto cleanup;
85bdc128fcda11c89ec1d76ea4221f4fa8e4fc24Mark Andrews isc_region_consume(&sr, tkey->keylen);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other size.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington tkey->otherlen = uint16_fromregion(&sr);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington isc_region_consume(&sr, 2);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence /*
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence * Other.
652c80435a97ca558a47e2f320047b73b3626cd1David Lawrence */
8a2ff13c3dbf43c3a3f0ff8f24d9559ec2d72089Mark Andrews INSIST(tkey->otherlen <= sr.length);
85bdc128fcda11c89ec1d76ea4221f4fa8e4fc24Mark Andrews tkey->other = mem_maybedup(mctx, sr.base, tkey->otherlen);
85bdc128fcda11c89ec1d76ea4221f4fa8e4fc24Mark Andrews if (tkey->other == NULL)
85bdc128fcda11c89ec1d76ea4221f4fa8e4fc24Mark Andrews goto cleanup;
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews tkey->mctx = mctx;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews cleanup:
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (mctx != NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_name_free(&tkey->algorithm, mctx);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (mctx != NULL && tkey->key != NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews isc_mem_free(mctx, tkey->key);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews return (ISC_R_NOMEMORY);
f427e7850928d15ffc37b1f68c60588995c9b318Mark Andrews}
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefreestruct_tkey(ARGS_FREESTRUCT) {
b8dd48ecf83142f6ee7238cbd68fec455e527fc8Mark Andrews dns_rdata_tkey_t *tkey = (dns_rdata_tkey_t *) source;
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(source != NULL);
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (tkey->mctx == NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews return;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
cf3f14106d082e4676431c10c54b60b9a0e9b127Brian Wellington dns_name_free(&tkey->algorithm, tkey->mctx);
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley if (tkey->key != NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews isc_mem_free(tkey->mctx, tkey->key);
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley if (tkey->other != NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews isc_mem_free(tkey->mctx, tkey->other);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews tkey->mctx = NULL;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceadditionaldata_tkey(ARGS_ADDLDATA) {
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(rdata);
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley UNUSED(add);
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley UNUSED(arg);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_tkey);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedigest_tkey(ARGS_DIGEST) {
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(rdata);
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley UNUSED(digest);
d10099d8663f4a4b21219f0c4bcc4f2b1ca1d877Bob Halley UNUSED(arg);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_tkey);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOTIMPLEMENTED);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley}
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsstatic inline isc_boolean_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewscheckowner_tkey(ARGS_CHECKOWNER) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_tkey);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(name);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(type);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(rdclass);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(wildcard);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (ISC_TRUE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsstatic inline isc_boolean_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewschecknames_tkey(ARGS_CHECKNAMES) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_tkey);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(rdata);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(owner);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(bad);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (ISC_TRUE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic inline isc_result_t
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewscasecompare_tkey(ARGS_COMPARE) {
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (compare_tkey(rdata1, rdata2));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews}
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#endif /* RDATA_GENERIC_TKEY_249_C */