1 /* $NetBSD: keydata.c,v 1.5 2014/12/10 04:37:58 christos Exp $ */
4 * Copyright (C) 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id: keydata.c,v 1.3 2009/07/01 23:47:36 tbox Exp */
26 #include <isc/buffer.h>
28 #include <isc/string.h>
31 #include <dns/rdata.h>
32 #include <dns/rdatastruct.h>
33 #include <dns/keydata.h>
36 dns_keydata_todnskey(dns_rdata_keydata_t
*keydata
,
37 dns_rdata_dnskey_t
*dnskey
, isc_mem_t
*mctx
)
39 REQUIRE(keydata
!= NULL
&& dnskey
!= NULL
);
41 dnskey
->common
.rdtype
= dns_rdatatype_dnskey
;
42 dnskey
->common
.rdclass
= keydata
->common
.rdclass
;
44 dnskey
->flags
= keydata
->flags
;
45 dnskey
->protocol
= keydata
->protocol
;
46 dnskey
->algorithm
= keydata
->algorithm
;
48 dnskey
->datalen
= keydata
->datalen
;
51 dnskey
->data
= keydata
->data
;
53 dnskey
->data
= isc_mem_allocate(mctx
, dnskey
->datalen
);
54 if (dnskey
->data
== NULL
)
55 return (ISC_R_NOMEMORY
);
56 memmove(dnskey
->data
, keydata
->data
, dnskey
->datalen
);
59 return (ISC_R_SUCCESS
);
63 dns_keydata_fromdnskey(dns_rdata_keydata_t
*keydata
,
64 dns_rdata_dnskey_t
*dnskey
,
65 isc_uint32_t refresh
, isc_uint32_t addhd
,
66 isc_uint32_t removehd
, isc_mem_t
*mctx
)
68 REQUIRE(keydata
!= NULL
&& dnskey
!= NULL
);
70 keydata
->common
.rdtype
= dns_rdatatype_keydata
;
71 keydata
->common
.rdclass
= dnskey
->common
.rdclass
;
73 keydata
->refresh
= refresh
;
74 keydata
->addhd
= addhd
;
75 keydata
->removehd
= removehd
;
76 keydata
->flags
= dnskey
->flags
;
77 keydata
->protocol
= dnskey
->protocol
;
78 keydata
->algorithm
= dnskey
->algorithm
;
80 keydata
->datalen
= dnskey
->datalen
;
82 keydata
->data
= dnskey
->data
;
84 keydata
->data
= isc_mem_allocate(mctx
, keydata
->datalen
);
85 if (keydata
->data
== NULL
)
86 return (ISC_R_NOMEMORY
);
87 memmove(keydata
->data
, dnskey
->data
, keydata
->datalen
);
90 return (ISC_R_SUCCESS
);