blob: c2ca1c56c494e8f3f3949051a4155e2261023e38 [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -07003 * Copyright (c) 2017-2019, 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
tylerliu8704d032020-06-23 10:18:15 -070032 virtual CaState
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080033 getRequest(const std::string& requestId) = 0;
34
35 virtual void
tylerliu8704d032020-06-23 10:18:15 -070036 addRequest(const CaState& request) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080037
38 virtual void
tylerliu8704d032020-06-23 10:18:15 -070039 updateRequest(const CaState& request) = 0;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080040
41 virtual void
42 deleteRequest(const std::string& requestId) = 0;
43
tylerliu8704d032020-06-23 10:18:15 -070044 virtual std::list<CaState>
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070045 listAllRequests() = 0;
46
tylerliu8704d032020-06-23 10:18:15 -070047 virtual std::list<CaState>
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070048 listAllRequests(const Name& caName) = 0;
49
Davide Pesavento08994782018-01-22 12:13:41 -050050public: // factory
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080051 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 Zhangd1d9f5a2020-10-05 18:04:23 -070057 factory[caStorageType] = [] (const Name& caName, const std::string& path) {
58 return make_unique<CaStorageType>(caName, path);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080059 };
60 }
61
62 static unique_ptr<CaStorage>
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070063 createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path);
64
65 virtual
66 ~CaStorage() = default;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080067
68private:
Zhiyi Zhangd1d9f5a2020-10-05 18:04:23 -070069 using CaStorageCreateFunc = function<unique_ptr<CaStorage> (const Name&, const std::string&)>;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080070 using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
71
72 static CaStorageFactory&
73 getFactory();
74};
75
76#define NDNCERT_REGISTER_CA_STORAGE(C) \
77static class NdnCert ## C ## CaStorageRegistrationClass \
78{ \
79public: \
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