Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame^] | 1 | /* -*- 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" |
| 27 | |
| 28 | #include <ndn-cxx/link.hpp> |
| 29 | #include <ndn-cxx/security/key-chain.hpp> |
| 30 | |
| 31 | #include <vector> |
| 32 | #include <string> |
| 33 | |
| 34 | namespace ndn { |
| 35 | namespace ndns { |
| 36 | |
| 37 | class RrsetFactory |
| 38 | { |
| 39 | public: |
| 40 | /** @brief Represents an error might be thrown during runtime |
| 41 | */ |
| 42 | class Error : public std::runtime_error |
| 43 | { |
| 44 | public: |
| 45 | explicit |
| 46 | Error(const std::string& what) : std::runtime_error(what) |
| 47 | { |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | public: |
| 52 | RrsetFactory(const std::string& dbFile, |
| 53 | const Name& zoneName, |
| 54 | KeyChain& keyChain, |
| 55 | const Name& inputDskCertName); |
| 56 | |
| 57 | void |
| 58 | checkZoneKey(); |
| 59 | |
| 60 | Rrset |
| 61 | generateNsRrset(const Name& label, |
| 62 | const name::Component& type, |
| 63 | const uint64_t version, |
| 64 | time::seconds ttl, |
| 65 | const ndn::Link::DelegationSet& delegations); |
| 66 | |
| 67 | Rrset |
| 68 | generateTxtRrset(const Name& label, |
| 69 | const name::Component& type, |
| 70 | const uint64_t version, |
| 71 | time::seconds ttl, |
| 72 | const std::vector<std::string>& contents); |
| 73 | |
| 74 | Rrset |
| 75 | generateCertRrset(const Name& label, |
| 76 | const name::Component& type, |
| 77 | const uint64_t version, |
| 78 | time::seconds ttl, |
| 79 | const IdentityCertificate& cert); |
| 80 | |
| 81 | static std::vector<std::string> |
| 82 | wireDecodeTxt(const Block& wire); |
| 83 | |
| 84 | NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 85 | // only used for database-test-data unit test |
| 86 | void |
| 87 | onlyCheckZone(); |
| 88 | |
| 89 | private: |
| 90 | std::pair<Rrset, Name> |
| 91 | generateBaseRrset(const Name& label, |
| 92 | const name::Component& type, |
| 93 | const uint64_t version, |
| 94 | const time::seconds& ttl); |
| 95 | |
| 96 | bool |
| 97 | matchCertificate(const Name& certName, const Name& identity); |
| 98 | |
| 99 | template<encoding::Tag TAG> |
| 100 | inline size_t |
| 101 | wireEncode(EncodingImpl<TAG>& block, const std::vector<Block>& rrs) const; |
| 102 | |
| 103 | const Block |
| 104 | wireEncode(const std::vector<Block>& rrs) const; |
| 105 | |
| 106 | void |
| 107 | sign(Data& data); |
| 108 | |
| 109 | void |
| 110 | setMetaInfo(Data& data); |
| 111 | |
| 112 | private: |
| 113 | KeyChain& m_keyChain; |
| 114 | std::string m_dbFile; |
| 115 | Zone m_zone; |
| 116 | Name m_dskCertName; |
| 117 | Name m_dskName; |
| 118 | bool m_checked; |
| 119 | }; |
| 120 | |
| 121 | } // namespace ndns |
| 122 | } // namespace ndn |
| 123 | |
| 124 | #endif // NDNS_DAEMON_RRSET_FACTORY_HPP |
| 125 | |