tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
| 21 | #ifndef NDNCERT_ASSIGNMENT_FUNCS_HPP |
| 22 | #define NDNCERT_ASSIGNMENT_FUNCS_HPP |
| 23 | |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame] | 24 | #include "../ca-state.hpp" |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame^] | 29 | class NameAssignmentFunc : noncopyable |
| 30 | { |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 31 | public: |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 32 | explicit NameAssignmentFunc(const std::string& factoryType, const std::string& format = ""); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 33 | |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 34 | virtual ~NameAssignmentFunc() = default; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 35 | |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 36 | /** |
| 37 | * @brief The name assignment function provided by the CA operator to generate available |
| 38 | * namecomponents. |
| 39 | * The function does not guarantee that all the returned names are available. Therefore the |
| 40 | * CA should further check the availability of each returned name and remove unavailable results. |
| 41 | * |
| 42 | * @p vector, input, a list of parameter key-value pair used for name assignment. |
| 43 | * @return a vector containing the possible namespaces derived from the parameters. |
| 44 | */ |
| 45 | virtual std::vector<PartialName> |
| 46 | assignName(const std::vector<std::tuple<std::string, std::string>>& params) = 0; |
| 47 | |
| 48 | const std::string FACTORY_TYPE; |
| 49 | std::vector<std::string> m_nameFormat; |
| 50 | |
| 51 | public: |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 52 | template <class ChallengeType> |
| 53 | static void |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 54 | registerNameAssignmentFunc(const std::string& typeName) |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 55 | { |
| 56 | FuncFactoryFactory& factory = getFactory(); |
| 57 | BOOST_ASSERT(factory.count(typeName) == 0); |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 58 | factory[typeName] = [](const std::string& format) { return std::make_unique<ChallengeType>(format); }; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 61 | static unique_ptr<NameAssignmentFunc> |
| 62 | createNameAssignmentFunc(const std::string& challengeType, const std::string& format = ""); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 63 | |
| 64 | private: |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 65 | typedef function<unique_ptr<NameAssignmentFunc>(const std::string&)> FactoryCreateFunc; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 66 | typedef std::map<std::string, FactoryCreateFunc> FuncFactoryFactory; |
| 67 | |
| 68 | static FuncFactoryFactory& |
| 69 | getFactory(); |
| 70 | }; |
| 71 | |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 72 | #define NDNCERT_REGISTER_FUNCFACTORY(C, T) \ |
| 73 | static class NdnCert##C##FuncFactoryRegistrationClass { \ |
| 74 | public: \ |
| 75 | NdnCert##C##FuncFactoryRegistrationClass() \ |
| 76 | { \ |
| 77 | ::ndn::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T); \ |
| 78 | } \ |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 79 | } g_NdnCert##C##ChallengeRegistrationVariable |
| 80 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 81 | } // namespace ndncert |
| 82 | } // namespace ndn |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 83 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 84 | #endif // NDNCERT_ASSIGNMENT_FUNCS_HPP |