blob: 8318bb88554c88a46a9e664788539afad93ba139 [file] [log] [blame]
Yumin Xiaf853ad72016-11-03 21:14:07 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, Regents of the University of California.
4 *
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
76 generateCertRrset(const Name& label,
77 const name::Component& type,
78 const uint64_t version,
79 time::seconds ttl,
80 const IdentityCertificate& cert);
81
82 static std::vector<std::string>
83 wireDecodeTxt(const Block& wire);
84
85NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
86 // only used for database-test-data unit test
87 void
88 onlyCheckZone();
89
90private:
91 std::pair<Rrset, Name>
92 generateBaseRrset(const Name& label,
93 const name::Component& type,
94 const uint64_t version,
95 const time::seconds& ttl);
96
97 bool
98 matchCertificate(const Name& certName, const Name& identity);
99
100 template<encoding::Tag TAG>
101 inline size_t
102 wireEncode(EncodingImpl<TAG>& block, const std::vector<Block>& rrs) const;
103
104 const Block
105 wireEncode(const std::vector<Block>& rrs) const;
106
107 void
108 sign(Data& data);
109
Yumin Xiaa484ba72016-11-10 20:40:12 -0800110 void setContentType(Data& data, NdnsContentType contentType,
111 const time::seconds& ttl);
Yumin Xiaf853ad72016-11-03 21:14:07 -0700112
113private:
114 KeyChain& m_keyChain;
115 std::string m_dbFile;
116 Zone m_zone;
117 Name m_dskCertName;
118 Name m_dskName;
119 bool m_checked;
120};
121
122} // namespace ndns
123} // namespace ndn
124
125#endif // NDNS_DAEMON_RRSET_FACTORY_HPP
126