PageRenderTime 128ms CodeModel.GetById 107ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/bind9/lib/dns/keydata.c

https://bitbucket.org/freebsd/freebsd-head/
C | 89 lines | 57 code | 15 blank | 17 comment | 16 complexity | a224c288bd52e63117873398a97fec1e MD5 | raw file
 1/*
 2 * Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
 3 *
 4 * Permission to use, copy, modify, and/or distribute this software for any
 5 * purpose with or without fee is hereby granted, provided that the above
 6 * copyright notice and this permission notice appear in all copies.
 7 *
 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* $Id: keydata.c,v 1.3 2009/07/01 23:47:36 tbox Exp $ */
18
19/*! \file */
20
21#include <config.h>
22
23
24#include <isc/buffer.h>
25#include <isc/mem.h>
26#include <isc/string.h>
27#include <isc/util.h>
28
29#include <dns/rdata.h>
30#include <dns/rdatastruct.h>
31#include <dns/keydata.h>
32
33isc_result_t
34dns_keydata_todnskey(dns_rdata_keydata_t *keydata,
35		     dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx)
36{
37	REQUIRE(keydata != NULL && dnskey != NULL);
38
39	dnskey->common.rdtype = dns_rdatatype_dnskey;
40	dnskey->common.rdclass = keydata->common.rdclass;
41	dnskey->mctx = mctx;
42	dnskey->flags = keydata->flags;
43	dnskey->protocol = keydata->protocol;
44	dnskey->algorithm = keydata->algorithm;
45
46	dnskey->datalen = keydata->datalen;
47
48	if (mctx == NULL)
49		dnskey->data = keydata->data;
50	else {
51		dnskey->data = isc_mem_allocate(mctx, dnskey->datalen);
52		if (dnskey->data == NULL)
53			return (ISC_R_NOMEMORY);
54		memcpy(dnskey->data, keydata->data, dnskey->datalen);
55	}
56
57	return (ISC_R_SUCCESS);
58}
59
60isc_result_t
61dns_keydata_fromdnskey(dns_rdata_keydata_t *keydata,
62		       dns_rdata_dnskey_t *dnskey,
63		       isc_uint32_t refresh, isc_uint32_t addhd,
64		       isc_uint32_t removehd, isc_mem_t *mctx)
65{
66	REQUIRE(keydata != NULL && dnskey != NULL);
67
68	keydata->common.rdtype = dns_rdatatype_keydata;
69	keydata->common.rdclass = dnskey->common.rdclass;
70	keydata->mctx = mctx;
71	keydata->refresh = refresh;
72	keydata->addhd = addhd;
73	keydata->removehd = removehd;
74	keydata->flags = dnskey->flags;
75	keydata->protocol = dnskey->protocol;
76	keydata->algorithm = dnskey->algorithm;
77
78	keydata->datalen = dnskey->datalen;
79	if (mctx == NULL)
80		keydata->data = dnskey->data;
81	else {
82		keydata->data = isc_mem_allocate(mctx, keydata->datalen);
83		if (keydata->data == NULL)
84			return (ISC_R_NOMEMORY);
85		memcpy(keydata->data, dnskey->data, keydata->datalen);
86	}
87
88	return (ISC_R_SUCCESS);
89}