tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 3 | * Copyright (c) 2017-2022, 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" |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 25 | |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 26 | #include <map> |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 27 | |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 28 | namespace ndncert { |
| 29 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 30 | class NameAssignmentFunc : boost::noncopyable |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 31 | { |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 32 | protected: |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 33 | explicit |
| 34 | NameAssignmentFunc(const std::string& format = ""); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 35 | |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 36 | public: |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 37 | virtual |
| 38 | ~NameAssignmentFunc() = default; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 39 | |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 40 | /** |
| 41 | * @brief The name assignment function provided by the CA operator to generate available |
| 42 | * namecomponents. |
Zhiyi Zhang | 6d9eda6 | 2020-10-16 17:37:02 -0700 | [diff] [blame] | 43 | * |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 44 | * The function does not guarantee that all the returned names are available. Therefore the |
| 45 | * CA should further check the availability of each returned name and remove unavailable results. |
| 46 | * |
Zhiyi Zhang | 6d9eda6 | 2020-10-16 17:37:02 -0700 | [diff] [blame] | 47 | * @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] | 48 | * @return a vector containing the possible namespaces derived from the parameters. |
| 49 | */ |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 50 | virtual std::vector<ndn::PartialName> |
Zhiyi Zhang | f22ae24 | 2020-11-17 10:51:15 -0800 | [diff] [blame] | 51 | assignName(const std::multimap<std::string, std::string>& params) = 0; |
Zhiyi Zhang | 74c6114 | 2020-10-07 21:00:49 -0700 | [diff] [blame] | 52 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 53 | public: // factory |
| 54 | template<class AssignmentType> |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 55 | static void |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 56 | registerNameAssignmentFunc(const std::string& type) |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 57 | { |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 58 | auto& factory = getFactory(); |
| 59 | BOOST_ASSERT(factory.count(type) == 0); |
| 60 | factory[type] = [] (const std::string& format) { return std::make_unique<AssignmentType>(format); }; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 63 | static std::unique_ptr<NameAssignmentFunc> |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 64 | createNameAssignmentFunc(const std::string& type, const std::string& format = ""); |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 65 | |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 66 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED: |
Zhiyi Zhang | 84e1184 | 2020-11-19 20:03:23 -0800 | [diff] [blame] | 67 | std::vector<std::string> m_nameFormat; |
Zhiyi Zhang | f22ae24 | 2020-11-17 10:51:15 -0800 | [diff] [blame] | 68 | |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 69 | private: |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 70 | using CreateFunc = std::function<std::unique_ptr<NameAssignmentFunc>(const std::string &)>; |
| 71 | using FuncFactory = std::map<std::string, CreateFunc>; |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 72 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 73 | static FuncFactory& |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 74 | getFactory(); |
| 75 | }; |
| 76 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 77 | } // namespace ndncert |
tylerliu | 01d63ca | 2020-10-06 16:29:23 -0700 | [diff] [blame] | 78 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 79 | #define NDNCERT_REGISTER_NAME_ASSIGNMENT_FUNC(C, T) \ |
| 80 | static class NdnCert##C##NameAssignmentRegistrationClass \ |
| 81 | { \ |
| 82 | public: \ |
| 83 | NdnCert##C##NameAssignmentRegistrationClass() \ |
| 84 | { \ |
| 85 | ::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T); \ |
| 86 | } \ |
| 87 | } g_NdnCert##C##NameAssignmentRegistrationVariable |
| 88 | |
tylerliu | 6563f93 | 2020-10-30 11:13:38 -0700 | [diff] [blame] | 89 | #endif // NDNCERT_ASSIGNMENT_FUNC_HPP |