tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2017-2019, Regents of the University of California. |
| 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 | |
| 24 | #include <configuration.hpp> |
| 25 | #include "ca-state.hpp" |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | |
| 30 | class NameAssignmentFuncFactory : noncopyable { |
| 31 | public: |
| 32 | explicit |
| 33 | NameAssignmentFuncFactory(const std::string& factoryType); |
| 34 | |
| 35 | virtual ~NameAssignmentFuncFactory() = default; |
| 36 | |
| 37 | template <class ChallengeType> |
| 38 | static void |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 39 | registerNameAssignmentFuncFactories(const std::string& typeName) |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 40 | { |
| 41 | FuncFactoryFactory& factory = getFactory(); |
| 42 | BOOST_ASSERT(factory.count(typeName) == 0); |
| 43 | factory[typeName] = [] { return make_unique<ChallengeType>(); }; |
| 44 | } |
| 45 | |
| 46 | static bool |
| 47 | isChallengeSupported(const std::string& challengeType); |
| 48 | |
| 49 | static unique_ptr<NameAssignmentFuncFactory> |
tylerliu | 8d9e712 | 2020-10-06 18:57:06 -0700 | [diff] [blame] | 50 | createNameAssignmentFuncFactory(const std::string& challengeType); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 51 | |
| 52 | virtual NameAssignmentFunc |
| 53 | getFunction(const std::string& factoryParam) = 0; |
| 54 | |
| 55 | public: |
| 56 | const std::string FACTORY_TYPE; |
| 57 | |
| 58 | private: |
| 59 | typedef function<unique_ptr<NameAssignmentFuncFactory>()> FactoryCreateFunc; |
| 60 | typedef std::map<std::string, FactoryCreateFunc> FuncFactoryFactory; |
| 61 | |
| 62 | static FuncFactoryFactory& |
| 63 | getFactory(); |
| 64 | }; |
| 65 | |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 66 | #define NDNCERT_REGISTER_FUNCFACTORY(C, T) \ |
| 67 | static class NdnCert##C##FuncFactoryRegistrationClass { \ |
| 68 | public: \ |
| 69 | NdnCert##C##FuncFactoryRegistrationClass() \ |
| 70 | { \ |
| 71 | ::ndn::ndncert::NameAssignmentFuncFactory::registerNameAssignmentFuncFactories<C>(T); \ |
| 72 | } \ |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 73 | } g_NdnCert##C##ChallengeRegistrationVariable |
| 74 | |
| 75 | } // namespace ndncert |
| 76 | } // namespace ndn |
| 77 | |
| 78 | #endif // NDNCERT_ASSIGNMENT_FUNCS_HPP |