Home | History | Annotate | Line # | Download | only in dns
keydata.c revision 1.4
      1 /*	$NetBSD: keydata.c,v 1.4 2020/05/24 19:46:23 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * This Source Code Form is subject to the terms of the Mozilla Public
      7  * License, v. 2.0. If a copy of the MPL was not distributed with this
      8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
      9  *
     10  * See the COPYRIGHT file distributed with this work for additional
     11  * information regarding copyright ownership.
     12  */
     13 
     14 /*! \file */
     15 
     16 #include <inttypes.h>
     17 
     18 #include <isc/buffer.h>
     19 #include <isc/mem.h>
     20 #include <isc/string.h>
     21 #include <isc/util.h>
     22 
     23 #include <dns/keydata.h>
     24 #include <dns/rdata.h>
     25 #include <dns/rdatastruct.h>
     26 
     27 isc_result_t
     28 dns_keydata_todnskey(dns_rdata_keydata_t *keydata, dns_rdata_dnskey_t *dnskey,
     29 		     isc_mem_t *mctx) {
     30 	REQUIRE(keydata != NULL && dnskey != NULL);
     31 
     32 	dnskey->common.rdtype = dns_rdatatype_dnskey;
     33 	dnskey->common.rdclass = keydata->common.rdclass;
     34 	dnskey->mctx = mctx;
     35 	dnskey->flags = keydata->flags;
     36 	dnskey->protocol = keydata->protocol;
     37 	dnskey->algorithm = keydata->algorithm;
     38 
     39 	dnskey->datalen = keydata->datalen;
     40 
     41 	if (mctx == NULL) {
     42 		dnskey->data = keydata->data;
     43 	} else {
     44 		dnskey->data = isc_mem_allocate(mctx, dnskey->datalen);
     45 		memmove(dnskey->data, keydata->data, dnskey->datalen);
     46 	}
     47 
     48 	return (ISC_R_SUCCESS);
     49 }
     50 
     51 isc_result_t
     52 dns_keydata_fromdnskey(dns_rdata_keydata_t *keydata, dns_rdata_dnskey_t *dnskey,
     53 		       uint32_t refresh, uint32_t addhd, uint32_t removehd,
     54 		       isc_mem_t *mctx) {
     55 	REQUIRE(keydata != NULL && dnskey != NULL);
     56 
     57 	keydata->common.rdtype = dns_rdatatype_keydata;
     58 	keydata->common.rdclass = dnskey->common.rdclass;
     59 	keydata->mctx = mctx;
     60 	keydata->refresh = refresh;
     61 	keydata->addhd = addhd;
     62 	keydata->removehd = removehd;
     63 	keydata->flags = dnskey->flags;
     64 	keydata->protocol = dnskey->protocol;
     65 	keydata->algorithm = dnskey->algorithm;
     66 
     67 	keydata->datalen = dnskey->datalen;
     68 	if (mctx == NULL) {
     69 		keydata->data = dnskey->data;
     70 	} else {
     71 		keydata->data = isc_mem_allocate(mctx, keydata->datalen);
     72 		memmove(keydata->data, dnskey->data, keydata->datalen);
     73 	}
     74 
     75 	return (ISC_R_SUCCESS);
     76 }
     77