cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2009, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt *
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/.
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt */
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
c6fb85f9500350e5ce58c9a24f5d264c8a8bd6f4Automatic Updater/* $Id: keydata.c,v 1.3 2009/07/01 23:47:36 tbox Exp $ */
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt/*! \file */
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <config.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <isc/buffer.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <isc/mem.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <isc/string.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <isc/util.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <dns/rdata.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <dns/rdatastruct.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <dns/keydata.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Huntisc_result_t
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Huntdns_keydata_todnskey(dns_rdata_keydata_t *keydata,
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx)
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt{
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt REQUIRE(keydata != NULL && dnskey != NULL);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->common.rdtype = dns_rdatatype_dnskey;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->common.rdclass = keydata->common.rdclass;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->mctx = mctx;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->flags = keydata->flags;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->protocol = keydata->protocol;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->algorithm = keydata->algorithm;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->datalen = keydata->datalen;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt if (mctx == NULL)
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->data = keydata->data;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt else {
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dnskey->data = isc_mem_allocate(mctx, dnskey->datalen);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt if (dnskey->data == NULL)
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt return (ISC_R_NOMEMORY);
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(dnskey->data, keydata->data, dnskey->datalen);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt }
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt return (ISC_R_SUCCESS);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt}
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Huntisc_result_t
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Huntdns_keydata_fromdnskey(dns_rdata_keydata_t *keydata,
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt dns_rdata_dnskey_t *dnskey,
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt isc_uint32_t refresh, isc_uint32_t addhd,
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt isc_uint32_t removehd, isc_mem_t *mctx)
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt{
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt REQUIRE(keydata != NULL && dnskey != NULL);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->common.rdtype = dns_rdatatype_keydata;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->common.rdclass = dnskey->common.rdclass;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->mctx = mctx;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->refresh = refresh;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->addhd = addhd;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->removehd = removehd;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->flags = dnskey->flags;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->protocol = dnskey->protocol;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->algorithm = dnskey->algorithm;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->datalen = dnskey->datalen;
c6fb85f9500350e5ce58c9a24f5d264c8a8bd6f4Automatic Updater if (mctx == NULL)
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->data = dnskey->data;
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt else {
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt keydata->data = isc_mem_allocate(mctx, keydata->datalen);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt if (keydata->data == NULL)
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt return (ISC_R_NOMEMORY);
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(keydata->data, dnskey->data, keydata->datalen);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt }
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt return (ISC_R_SUCCESS);
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt}