Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2019, 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 | |
| 21 | #ifndef NDNCERT_CA_STORAGE_HPP |
| 22 | #define NDNCERT_CA_STORAGE_HPP |
| 23 | |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 24 | #include "ca-state.hpp" |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
| 29 | class CaStorage : noncopyable |
| 30 | { |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame^] | 31 | public: // request related |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 32 | virtual CaState |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 33 | getRequest(const std::string& requestId) = 0; |
| 34 | |
| 35 | virtual void |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 36 | addRequest(const CaState& request) = 0; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 37 | |
| 38 | virtual void |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 39 | updateRequest(const CaState& request) = 0; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 40 | |
| 41 | virtual void |
| 42 | deleteRequest(const std::string& requestId) = 0; |
| 43 | |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 44 | virtual std::list<CaState> |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 45 | listAllRequests() = 0; |
| 46 | |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 47 | virtual std::list<CaState> |
Zhiyi Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 48 | listAllRequests(const Name& caName) = 0; |
| 49 | |
Davide Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame] | 50 | public: // factory |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 51 | template<class CaStorageType> |
| 52 | static void |
| 53 | registerCaStorage(const std::string& caStorageType = CaStorageType::STORAGE_TYPE) |
| 54 | { |
| 55 | CaStorageFactory& factory = getFactory(); |
| 56 | BOOST_ASSERT(factory.count(caStorageType) == 0); |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame^] | 57 | factory[caStorageType] = [] (const Name& caName, const std::string& path) { |
| 58 | return make_unique<CaStorageType>(caName, path); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 59 | }; |
| 60 | } |
| 61 | |
| 62 | static unique_ptr<CaStorage> |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame^] | 63 | createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path); |
| 64 | |
| 65 | virtual |
| 66 | ~CaStorage() = default; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 67 | |
| 68 | private: |
Zhiyi Zhang | d1d9f5a | 2020-10-05 18:04:23 -0700 | [diff] [blame^] | 69 | using CaStorageCreateFunc = function<unique_ptr<CaStorage> (const Name&, const std::string&)>; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 70 | using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>; |
| 71 | |
| 72 | static CaStorageFactory& |
| 73 | getFactory(); |
| 74 | }; |
| 75 | |
| 76 | #define NDNCERT_REGISTER_CA_STORAGE(C) \ |
| 77 | static class NdnCert ## C ## CaStorageRegistrationClass \ |
| 78 | { \ |
| 79 | public: \ |
| 80 | NdnCert ## C ## CaStorageRegistrationClass() \ |
| 81 | { \ |
| 82 | ::ndn::ndncert::CaStorage::registerCaStorage<C>(); \ |
| 83 | } \ |
| 84 | } g_NdnCert ## C ## CaStorageRegistrationVariable |
| 85 | |
| 86 | } // namespace ndncert |
| 87 | } // namespace ndn |
| 88 | |
| 89 | #endif // NDNCERT_CA_STORAGE_HPP |