Coverage Report

Created: 2022-03-10 07:56

/src/bind9/lib/dns/keydata.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
 *
4
 * SPDX-License-Identifier: MPL-2.0
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 https://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
0
         isc_mem_t *mctx) {
30
0
  REQUIRE(keydata != NULL && dnskey != NULL);
31
32
0
  dnskey->common.rdtype = dns_rdatatype_dnskey;
33
0
  dnskey->common.rdclass = keydata->common.rdclass;
34
0
  dnskey->mctx = mctx;
35
0
  dnskey->flags = keydata->flags;
36
0
  dnskey->protocol = keydata->protocol;
37
0
  dnskey->algorithm = keydata->algorithm;
38
39
0
  dnskey->datalen = keydata->datalen;
40
41
0
  if (mctx == NULL) {
42
0
    dnskey->data = keydata->data;
43
0
  } else {
44
0
    dnskey->data = isc_mem_allocate(mctx, dnskey->datalen);
45
0
    memmove(dnskey->data, keydata->data, dnskey->datalen);
46
0
  }
47
48
0
  return (ISC_R_SUCCESS);
49
0
}
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
0
           isc_mem_t *mctx) {
55
0
  REQUIRE(keydata != NULL && dnskey != NULL);
56
57
0
  keydata->common.rdtype = dns_rdatatype_keydata;
58
0
  keydata->common.rdclass = dnskey->common.rdclass;
59
0
  keydata->mctx = mctx;
60
0
  keydata->refresh = refresh;
61
0
  keydata->addhd = addhd;
62
0
  keydata->removehd = removehd;
63
0
  keydata->flags = dnskey->flags;
64
0
  keydata->protocol = dnskey->protocol;
65
0
  keydata->algorithm = dnskey->algorithm;
66
67
0
  keydata->datalen = dnskey->datalen;
68
0
  if (mctx == NULL) {
69
0
    keydata->data = dnskey->data;
70
0
  } else {
71
0
    keydata->data = isc_mem_allocate(mctx, keydata->datalen);
72
0
    memmove(keydata->data, dnskey->data, keydata->datalen);
73
0
  }
74
75
0
  return (ISC_R_SUCCESS);
76
0
}