tkey_249.c revision 8d3e74b1683f714a484bbcf73249e8ee470e36d7
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews/*
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Copyright (C) 1999 Internet Software Consortium.
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews *
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Permission to use, copy, modify, and distribute this software for any
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * purpose with or without fee is hereby granted, provided that the above
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * copyright notice and this permission notice appear in all copies.
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews *
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * SOFTWARE.
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* $Id: tkey_249.c,v 1.2 1999/02/04 06:38:43 marka Exp $ */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* draft-ietf-dnssec-tkey-01.txt */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#ifndef RDATA_GENERIC_TKEY_249_H
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#define RDATA_GENERIC_TKEY_249_H
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsstatic dns_result_t
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsfromtext_tkey(dns_rdataclass_t class, dns_rdatatype_t type,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_lex_t *lexer, dns_name_t *origin,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_boolean_t downcase, isc_buffer_t *target)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews{
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_token_t token;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_rcode_t rcode;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_t name;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_t buffer;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews char *e;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews REQUIRE(type == 249);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews class = class; /*unused*/
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Algorithm */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_init(&name, NULL);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews buffer_fromregion(&buffer, &token.value.as_region,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews ISC_BUFFERTYPE_TEXT);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews origin = (origin != NULL) ? origin : dns_rootname;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Inception */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Expiration */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Mode */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (token.value.as_ulong > 0xffff)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_RANGE);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Error */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (dns_rcode_fromtext(&rcode, &token.value.as_textregion)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews != DNS_R_SUCCESS) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews rcode = strtol(token.value.as_pointer, &e, 10);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (*e != 0)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_UNKNOWN);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (rcode > 0xffff)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_RANGE);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews }
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(uint16_tobuffer(rcode, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Signature Size */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (token.value.as_ulong > 0xffff)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_RANGE);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Signature */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(base64_tobuffer(lexer, target, token.value.as_ulong));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Other Len */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (token.value.as_ulong > 0xffff)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_RANGE);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Other Data */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (base64_tobuffer(lexer, target, token.value.as_ulong));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsstatic dns_result_t
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewstotext_tkey(dns_rdata_t *rdata, dns_name_t *origin, isc_buffer_t *target) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_t sr;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_t sigr;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews char buf[sizeof "4294967295 "];
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews unsigned long n;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_t name;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_t prefix;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_boolean_t sub;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews REQUIRE(rdata->type == 249);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_rdata_toregion(rdata, &sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Algorithm */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_init(&name, NULL);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_init(&prefix, NULL);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sub = name_prefix(&name, origin, &prefix);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(dns_name_totext(&prefix, sub, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, name_length(&name));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Inception */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint32_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, 4);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sprintf(buf, "%lu ", n);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(buf, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Expiration */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint32_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, 4);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sprintf(buf, "%lu ", n);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(buf, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Mode */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint16_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, 2);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sprintf(buf, "%lu ", n);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(buf, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Error */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint16_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, 2);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (dns_rcode_totext(n, target) == DNS_R_SUCCESS)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(" ", target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews else {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sprintf(buf, "%lu ", n);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(buf, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews }
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Signature Size */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint16_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, 2);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sprintf(buf, "%lu ", n);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(buf, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Signature */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews REQUIRE(n <= sr.length);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sigr = sr;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sigr.length = n;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(base64_totext(&sigr, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(" ", target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, n);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Other Size */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint16_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, 2);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews sprintf(buf, "%lu ", n);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(str_totext(buf, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Other */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (base64_totext(&sr, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsstatic dns_result_t
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsfromwire_tkey(dns_rdataclass_t class, dns_rdatatype_t type,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_t *source, dns_decompress_t *dctx,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_boolean_t downcase, isc_buffer_t *target)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews{
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_t sr;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews unsigned long n;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_t name;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews REQUIRE(type == 249);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews class = class; /*unused*/
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Algorithm */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_init(&name, NULL);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /*
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Inception: 4
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Expiration: 4
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Mode: 2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Error: 2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_active(source, &sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (sr.length < 12)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_UNEXPECTEDEND);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(mem_tobuffer(target, sr.base, 12));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, 12);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_forward(source, 12);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Signature Length + Signature */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (sr.length < 2)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_UNEXPECTEDEND);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint16_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (sr.length < n + 2)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_UNEXPECTEDEND);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews RETERR(mem_tobuffer(target, sr.base, n + 2));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_consume(&sr, n + 2);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_forward(source, n + 2);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews /* Other Length + Other */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (sr.length < 2)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_UNEXPECTEDEND);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews n = uint16_fromregion(&sr);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (sr.length < n + 2)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (DNS_R_UNEXPECTEDEND);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_buffer_forward(source, n + 2);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (mem_tobuffer(target, sr.base, n + 2));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsstatic dns_result_t
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewstowire_tkey(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_region_t sr;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews dns_name_t name;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews REQUIRE(rdata->type == 249);
/* Algorithm */
dns_rdata_toregion(rdata, &sr);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &sr);
RETERR(dns_name_towire(&name, cctx, target));
isc_region_consume(&sr, name_length(&name));
return (mem_tobuffer(target, sr.base, sr.length));
}
static int
compare_tkey(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
isc_region_t r1;
isc_region_t r2;
dns_name_t name1;
dns_name_t name2;
int result;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->class == rdata2->class);
REQUIRE(rdata1->type == 249);
/* Algorithm */
dns_rdata_toregion(rdata1, &r1);
dns_rdata_toregion(rdata2, &r2);
dns_name_init(&name1, NULL);
dns_name_init(&name2, NULL);
dns_name_fromregion(&name1, &r1);
dns_name_fromregion(&name1, &r1);
if ((result = dns_name_compare(&name1, &name2)) != 0)
return (result);
isc_region_consume(&r1, name_length(&name1));
isc_region_consume(&r2, name_length(&name2));
return (compare_region(&r1, &r2));
}
static dns_result_t
fromstruct_tkey(dns_rdataclass_t class, dns_rdatatype_t type,
void *source, isc_buffer_t *target) {
REQUIRE(type == 249);
class = class; /*unused*/
source = source;
target = target;
return (DNS_R_NOTIMPLEMENTED);
}
static dns_result_t
tostruct_tkey(dns_rdata_t *rdata, void *target) {
REQUIRE(rdata->type == 249);
target = target;
return (DNS_R_NOTIMPLEMENTED);
}
#endif /* RDATA_GENERIC_TKEY_249_H */