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 | |
tylerliu | 6563f93 | 2020-10-30 11:13:38 -0700 | [diff] [blame] | 21 | #ifndef NDNCERT_ASSIGNMENT_FUNC_HPP |
| 22 | #define NDNCERT_ASSIGNMENT_FUNC_HPP |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 23 | |
Zhiyi Zhang | 34f03f0 | 2020-10-29 18:34:42 -0700 | [diff] [blame] | 24 | #include "detail/ca-request-state.hpp" |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 25 | #include <map> |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 30 | class NameAssignmentFunc : noncopyable |
| 31 | { |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 32 | protected: |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 33 | explicit NameAssignmentFunc(const std::string& format = ""); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 34 | |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 35 | public: |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 36 | virtual ~NameAssignmentFunc() = default; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 37 | |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 38 | /** |
| 39 | * @brief The name assignment function provided by the CA operator to generate available |
| 40 | * namecomponents. |
Zhiyi Zhang | 6d9eda6 | 2020-10-16 17:37:02 -0700 | [diff] [blame] | 41 | * |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 42 | * The function does not guarantee that all the returned names are available. Therefore the |
| 43 | * CA should further check the availability of each returned name and remove unavailable results. |
| 44 | * |
Zhiyi Zhang | 6d9eda6 | 2020-10-16 17:37:02 -0700 | [diff] [blame] | 45 | * @param vector A list of parameter key-value pair used for name assignment. |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 46 | * @return a vector containing the possible namespaces derived from the parameters. |
| 47 | */ |
| 48 | virtual std::vector<PartialName> |
Zhiyi Zhang | f22ae24 | 2020-11-17 10:51:15 -0800 | [diff] [blame] | 49 | assignName(const std::multimap<std::string, std::string>& params) = 0; |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 50 | |
| 51 | public: |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 52 | template <class AssignmentType> |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 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 | { |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 56 | CurriedFuncFactory& factory = getFactory(); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 57 | BOOST_ASSERT(factory.count(typeName) == 0); |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 58 | factory[typeName] = [](const std::string& format) { return std::make_unique<AssignmentType>(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 | |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 64 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 65 | std::vector<std::string> m_nameFormat; |
Zhiyi Zhang | f22ae24 | 2020-11-17 10:51:15 -0800 | [diff] [blame] | 66 | |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 67 | private: |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 68 | typedef function<unique_ptr<NameAssignmentFunc>(const std::string&)> FactoryCreateFunc; |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 69 | typedef std::map<std::string, FactoryCreateFunc> CurriedFuncFactory; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 70 | |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 71 | static CurriedFuncFactory& |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 72 | getFactory(); |
| 73 | }; |
| 74 | |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 75 | #define NDNCERT_REGISTER_FUNCFACTORY(C, T) \ |
| 76 | static class NdnCert##C##FuncFactoryRegistrationClass { \ |
| 77 | public: \ |
| 78 | NdnCert##C##FuncFactoryRegistrationClass() \ |
| 79 | { \ |
| 80 | ::ndn::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T); \ |
| 81 | } \ |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 82 | } g_NdnCert##C##ChallengeRegistrationVariable |
| 83 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 84 | } // namespace ndncert |
| 85 | } // namespace ndn |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 86 | |
tylerliu | 6563f93 | 2020-10-30 11:13:38 -0700 | [diff] [blame] | 87 | #endif // NDNCERT_ASSIGNMENT_FUNC_HPP |