Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [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. |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [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 | |
Zhiyi Zhang | a62bf98 | 2020-10-26 13:10:02 -0700 | [diff] [blame] | 21 | #ifndef NDNCERT_DETAIL_CA_STORAGE_HPP |
| 22 | #define NDNCERT_DETAIL_CA_STORAGE_HPP |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 23 | |
Zhiyi Zhang | 34f03f0 | 2020-10-29 18:34:42 -0700 | [diff] [blame] | 24 | #include "detail/ca-request-state.hpp" |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 25 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 26 | #include <map> |
| 27 | |
| 28 | namespace ndncert::ca { |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 29 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 30 | class CaStorage : boost::noncopyable |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 31 | { |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 32 | public: |
| 33 | virtual |
| 34 | ~CaStorage() = default; |
| 35 | |
Zhiyi Zhang | 21d52b5 | 2020-10-05 18:29:15 -0700 | [diff] [blame] | 36 | /** |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 37 | * @throw std::runtime_error The request cannot be fetched from underlying data storage |
Zhiyi Zhang | 21d52b5 | 2020-10-05 18:29:15 -0700 | [diff] [blame] | 38 | */ |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 39 | virtual RequestState |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame] | 40 | getRequest(const RequestId& requestId) = 0; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 41 | |
Zhiyi Zhang | 21d52b5 | 2020-10-05 18:29:15 -0700 | [diff] [blame] | 42 | /** |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 43 | * @throw std::runtime_error There is an existing request with the same request ID |
Zhiyi Zhang | 21d52b5 | 2020-10-05 18:29:15 -0700 | [diff] [blame] | 44 | */ |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 45 | virtual void |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 46 | addRequest(const RequestState& request) = 0; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 47 | |
| 48 | virtual void |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 49 | updateRequest(const RequestState& request) = 0; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 50 | |
| 51 | virtual void |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame] | 52 | deleteRequest(const RequestId& requestId) = 0; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 53 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 54 | virtual std::list<RequestState> |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 55 | listAllRequests() = 0; |
| 56 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 57 | virtual std::list<RequestState> |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 58 | listAllRequests(const Name& caName) = 0; |
| 59 | |
Davide Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame] | 60 | public: // factory |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 61 | template<class CaStorageType> |
| 62 | static void |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 63 | registerCaStorage(const std::string& type = CaStorageType::STORAGE_TYPE) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 64 | { |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 65 | auto& factory = getFactory(); |
| 66 | BOOST_ASSERT(factory.count(type) == 0); |
| 67 | factory[type] = [] (const Name& caName, const std::string& path) { |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 68 | return std::make_unique<CaStorageType>(caName, path); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 69 | }; |
| 70 | } |
| 71 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 72 | static std::unique_ptr<CaStorage> |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame] | 73 | createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path); |
| 74 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 75 | private: |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 76 | using CreateFunc = std::function<std::unique_ptr<CaStorage>(const Name&, const std::string&)>; |
| 77 | using CaStorageFactory = std::map<std::string, CreateFunc>; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 78 | |
| 79 | static CaStorageFactory& |
| 80 | getFactory(); |
| 81 | }; |
| 82 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 83 | } // namespace ndncert::ca |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 84 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 85 | #define NDNCERT_REGISTER_CA_STORAGE(C) \ |
| 86 | static class NdnCert##C##CaStorageRegistrationClass \ |
| 87 | { \ |
| 88 | public: \ |
| 89 | NdnCert##C##CaStorageRegistrationClass() \ |
| 90 | { \ |
| 91 | ::ndncert::ca::CaStorage::registerCaStorage<C>(); \ |
| 92 | } \ |
| 93 | } g_NdnCert##C##CaStorageRegistrationVariable |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 94 | |
Zhiyi Zhang | a62bf98 | 2020-10-26 13:10:02 -0700 | [diff] [blame] | 95 | #endif // NDNCERT_DETAIL_CA_STORAGE_HPP |