00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 }