blob: e18a5bc8605497fc68f07020904c20e650a821f3 [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang74c61142020-10-07 21:00:49 -07003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08004 *
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
tylerliu8704d032020-06-23 10:18:15 -070024#include "ca-state.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080025
26namespace ndn {
27namespace ndncert {
28
29class CaStorage : noncopyable
30{
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070031public: // request related
Zhiyi Zhang21d52b52020-10-05 18:29:15 -070032 /**
33 * @throw if request cannot be fetched from underlying data storage
34 */
tylerliu8704d032020-06-23 10:18:15 -070035 virtual CaState
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080036 getRequest(const std::string& requestId) = 0;
37
Zhiyi Zhang21d52b52020-10-05 18:29:15 -070038 /**
39 * @throw if there is an existing request with the same request ID
40 */
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080041 virtual void
tylerliu8704d032020-06-23 10:18:15 -070042 addRequest(const CaState& request) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080043
44 virtual void
tylerliu8704d032020-06-23 10:18:15 -070045 updateRequest(const CaState& request) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080046
47 virtual void
48 deleteRequest(const std::string& requestId) = 0;
49
tylerliu8704d032020-06-23 10:18:15 -070050 virtual std::list<CaState>
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070051 listAllRequests() = 0;
52
tylerliu8704d032020-06-23 10:18:15 -070053 virtual std::list<CaState>
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070054 listAllRequests(const Name& caName) = 0;
55
Davide Pesavento08994782018-01-22 12:13:41 -050056public: // factory
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080057 template<class CaStorageType>
58 static void
59 registerCaStorage(const std::string& caStorageType = CaStorageType::STORAGE_TYPE)
60 {
61 CaStorageFactory& factory = getFactory();
62 BOOST_ASSERT(factory.count(caStorageType) == 0);
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070063 factory[caStorageType] = [] (const Name& caName, const std::string& path) {
Zhiyi Zhang32437282020-10-10 16:15:37 -070064 return std::make_unique<CaStorageType>(caName, path);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080065 };
66 }
67
68 static unique_ptr<CaStorage>
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070069 createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path);
70
71 virtual
72 ~CaStorage() = default;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080073
74private:
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070075 using CaStorageCreateFunc = function<unique_ptr<CaStorage> (const Name&, const std::string&)>;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080076 using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
77
78 static CaStorageFactory&
79 getFactory();
80};
81
82#define NDNCERT_REGISTER_CA_STORAGE(C) \
83static class NdnCert ## C ## CaStorageRegistrationClass \
84{ \
85public: \
86 NdnCert ## C ## CaStorageRegistrationClass() \
87 { \
88 ::ndn::ndncert::CaStorage::registerCaStorage<C>(); \
89 } \
90} g_NdnCert ## C ## CaStorageRegistrationVariable
91
92} // namespace ndncert
93} // namespace ndn
94
95#endif // NDNCERT_CA_STORAGE_HPP