keydata.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id: keydata.c,v 1.3 2009/07/01 23:47:36 tbox Exp $ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 
00024 #include <isc/buffer.h>
00025 #include <isc/mem.h>
00026 #include <isc/string.h>
00027 #include <isc/util.h>
00028 
00029 #include <dns/rdata.h>
00030 #include <dns/rdatastruct.h>
00031 #include <dns/keydata.h>
00032 
00033 isc_result_t
00034 dns_keydata_todnskey(dns_rdata_keydata_t *keydata,
00035                      dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx)
00036 {
00037         REQUIRE(keydata != NULL && dnskey != NULL);
00038 
00039         dnskey->common.rdtype = dns_rdatatype_dnskey;
00040         dnskey->common.rdclass = keydata->common.rdclass;
00041         dnskey->mctx = mctx;
00042         dnskey->flags = keydata->flags;
00043         dnskey->protocol = keydata->protocol;
00044         dnskey->algorithm = keydata->algorithm;
00045 
00046         dnskey->datalen = keydata->datalen;
00047 
00048         if (mctx == NULL)
00049                 dnskey->data = keydata->data;
00050         else {
00051                 dnskey->data = isc_mem_allocate(mctx, dnskey->datalen);
00052                 if (dnskey->data == NULL)
00053                         return (ISC_R_NOMEMORY);
00054                 memmove(dnskey->data, keydata->data, dnskey->datalen);
00055         }
00056 
00057         return (ISC_R_SUCCESS);
00058 }
00059 
00060 isc_result_t
00061 dns_keydata_fromdnskey(dns_rdata_keydata_t *keydata,
00062                        dns_rdata_dnskey_t *dnskey,
00063                        isc_uint32_t refresh, isc_uint32_t addhd,
00064                        isc_uint32_t removehd, isc_mem_t *mctx)
00065 {
00066         REQUIRE(keydata != NULL && dnskey != NULL);
00067 
00068         keydata->common.rdtype = dns_rdatatype_keydata;
00069         keydata->common.rdclass = dnskey->common.rdclass;
00070         keydata->mctx = mctx;
00071         keydata->refresh = refresh;
00072         keydata->addhd = addhd;
00073         keydata->removehd = removehd;
00074         keydata->flags = dnskey->flags;
00075         keydata->protocol = dnskey->protocol;
00076         keydata->algorithm = dnskey->algorithm;
00077 
00078         keydata->datalen = dnskey->datalen;
00079         if (mctx == NULL)
00080                 keydata->data = dnskey->data;
00081         else {
00082                 keydata->data = isc_mem_allocate(mctx, keydata->datalen);
00083                 if (keydata->data == NULL)
00084                         return (ISC_R_NOMEMORY);
00085                 memmove(keydata->data, dnskey->data, keydata->datalen);
00086         }
00087 
00088         return (ISC_R_SUCCESS);
00089 }

Generated on Tue Apr 28 17:40:57 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha