blob: bef3de1c151ce393861ee2a9280e1d4c771db98f [file] [log] [blame]
tylerliu01d63ca2020-10-06 16:29:23 -07001/* -*- 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
27namespace ndn {
28namespace ndncert {
29
30class NameAssignmentFuncFactory : noncopyable {
31public:
32 explicit
33 NameAssignmentFuncFactory(const std::string& factoryType);
34
35 virtual ~NameAssignmentFuncFactory() = default;
36
37 template <class ChallengeType>
38 static void
tylerliuafb27a02020-10-06 17:20:06 -070039 registerNameAssignmentFuncFactories(const std::string& typeName)
tylerliu01d63ca2020-10-06 16:29:23 -070040 {
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>
tylerliu8d9e7122020-10-06 18:57:06 -070050 createNameAssignmentFuncFactory(const std::string& challengeType);
tylerliu01d63ca2020-10-06 16:29:23 -070051
52 virtual NameAssignmentFunc
53 getFunction(const std::string& factoryParam) = 0;
54
55public:
56 const std::string FACTORY_TYPE;
57
58private:
59 typedef function<unique_ptr<NameAssignmentFuncFactory>()> FactoryCreateFunc;
60 typedef std::map<std::string, FactoryCreateFunc> FuncFactoryFactory;
61
62 static FuncFactoryFactory&
63 getFactory();
64};
65
tylerliuafb27a02020-10-06 17:20:06 -070066#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 } \
tylerliu01d63ca2020-10-06 16:29:23 -070073 } g_NdnCert##C##ChallengeRegistrationVariable
74
75} // namespace ndncert
76} // namespace ndn
77
78#endif // NDNCERT_ASSIGNMENT_FUNCS_HPP