blob: 083b8a579cac4a1da5fadd9dc66888e2775c469b [file] [log] [blame]
Yumin Xiaf853ad72016-11-03 21:14:07 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yumin Xiaacd21332016-11-28 22:54:48 -08003 * Copyright (c) 2014-2017, Regents of the University of California.
Yumin Xiaf853ad72016-11-03 21:14:07 -07004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NDNS_DAEMON_RRSET_FACTORY_HPP
21#define NDNS_DAEMON_RRSET_FACTORY_HPP
22
23#include "common.hpp"
24#include "rrset.hpp"
25#include "logger.hpp"
26#include "daemon/db-mgr.hpp"
Yumin Xiaa484ba72016-11-10 20:40:12 -080027#include "ndns-enum.hpp"
Yumin Xiaf853ad72016-11-03 21:14:07 -070028
29#include <ndn-cxx/link.hpp>
30#include <ndn-cxx/security/key-chain.hpp>
31
32#include <vector>
33#include <string>
34
35namespace ndn {
36namespace ndns {
37
38class RrsetFactory
39{
40public:
41 /** @brief Represents an error might be thrown during runtime
42 */
43 class Error : public std::runtime_error
44 {
45 public:
46 explicit
47 Error(const std::string& what) : std::runtime_error(what)
48 {
49 }
50 };
51
52public:
53 RrsetFactory(const std::string& dbFile,
54 const Name& zoneName,
55 KeyChain& keyChain,
56 const Name& inputDskCertName);
57
58 void
59 checkZoneKey();
60
61 Rrset
62 generateNsRrset(const Name& label,
63 const name::Component& type,
64 const uint64_t version,
65 time::seconds ttl,
66 const ndn::Link::DelegationSet& delegations);
67
68 Rrset
69 generateTxtRrset(const Name& label,
70 const name::Component& type,
71 const uint64_t version,
72 time::seconds ttl,
73 const std::vector<std::string>& contents);
74
75 Rrset
Yumin Xiaacd21332016-11-28 22:54:48 -080076 generateAuthRrset(const Name& label,
77 const name::Component& type,
78 const uint64_t version,
79 time::seconds ttl);
80
81 Rrset
Yumin Xiaf853ad72016-11-03 21:14:07 -070082 generateCertRrset(const Name& label,
83 const name::Component& type,
84 const uint64_t version,
85 time::seconds ttl,
86 const IdentityCertificate& cert);
87
88 static std::vector<std::string>
89 wireDecodeTxt(const Block& wire);
90
91NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
92 // only used for database-test-data unit test
93 void
94 onlyCheckZone();
95
96private:
97 std::pair<Rrset, Name>
98 generateBaseRrset(const Name& label,
99 const name::Component& type,
100 const uint64_t version,
101 const time::seconds& ttl);
102
103 bool
104 matchCertificate(const Name& certName, const Name& identity);
105
106 template<encoding::Tag TAG>
107 inline size_t
108 wireEncode(EncodingImpl<TAG>& block, const std::vector<Block>& rrs) const;
109
110 const Block
111 wireEncode(const std::vector<Block>& rrs) const;
112
113 void
114 sign(Data& data);
115
Yumin Xia3c6b1fd2016-12-11 19:08:47 -0800116 void
117 setContentType(Data& data, NdnsContentType contentType,
118 const time::seconds& ttl);
Yumin Xiaf853ad72016-11-03 21:14:07 -0700119
120private:
121 KeyChain& m_keyChain;
122 std::string m_dbFile;
123 Zone m_zone;
124 Name m_dskCertName;
125 Name m_dskName;
126 bool m_checked;
127};
128
129} // namespace ndns
130} // namespace ndn
131
132#endif // NDNS_DAEMON_RRSET_FACTORY_HPP
133