blob: 2cf7b7e143d2526cc202e056a1731af84959eda9 [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
24#include "certificate-request.hpp"
25
26namespace ndn {
27namespace ndncert {
28
29class CaStorage : noncopyable
30{
31public:
32 /**
33 * @brief Error that can be thrown from CaStorage
34 */
35 class Error : public std::runtime_error
36 {
37 public:
38 using std::runtime_error::runtime_error;
39 };
40
Davide Pesavento08994782018-01-22 12:13:41 -050041 virtual
42 ~CaStorage();
43
44public: // certificate request related
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080045 virtual CertificateRequest
46 getRequest(const std::string& requestId) = 0;
47
48 virtual void
49 addRequest(const CertificateRequest& request) = 0;
50
51 virtual void
52 updateRequest(const CertificateRequest& request) = 0;
53
54 virtual void
55 deleteRequest(const std::string& requestId) = 0;
56
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070057 virtual std::list<CertificateRequest>
58 listAllRequests() = 0;
59
60 virtual std::list<CertificateRequest>
61 listAllRequests(const Name& caName) = 0;
62
Davide Pesavento08994782018-01-22 12:13:41 -050063public: // certificate related
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080064 virtual security::v2::Certificate
65 getCertificate(const std::string& certId) = 0;
66
67 virtual void
68 addCertificate(const std::string& certId, const security::v2::Certificate& cert) = 0;
69
70 virtual void
71 updateCertificate(const std::string& certId, const security::v2::Certificate& cert) = 0;
72
73 virtual void
74 deleteCertificate(const std::string& certId) = 0;
75
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070076 virtual std::list<security::v2::Certificate>
77 listAllIssuedCertificates() = 0;
78
79 virtual std::list<security::v2::Certificate>
80 listAllIssuedCertificates(const Name& caName) = 0;
81
Davide Pesavento08994782018-01-22 12:13:41 -050082public: // factory
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080083 template<class CaStorageType>
84 static void
85 registerCaStorage(const std::string& caStorageType = CaStorageType::STORAGE_TYPE)
86 {
87 CaStorageFactory& factory = getFactory();
88 BOOST_ASSERT(factory.count(caStorageType) == 0);
89 factory[caStorageType] = [] {
90 return make_unique<CaStorageType>();
91 };
92 }
93
94 static unique_ptr<CaStorage>
95 createCaStorage(const std::string& caStorageType);
96
97private:
98 using CaStorageCreateFunc = function<unique_ptr<CaStorage> ()>;
99 using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
100
101 static CaStorageFactory&
102 getFactory();
103};
104
105#define NDNCERT_REGISTER_CA_STORAGE(C) \
106static class NdnCert ## C ## CaStorageRegistrationClass \
107{ \
108public: \
109 NdnCert ## C ## CaStorageRegistrationClass() \
110 { \
111 ::ndn::ndncert::CaStorage::registerCaStorage<C>(); \
112 } \
113} g_NdnCert ## C ## CaStorageRegistrationVariable
114
115} // namespace ndncert
116} // namespace ndn
117
118#endif // NDNCERT_CA_STORAGE_HPP