blob: 0a85f6c1388a2c5a3d39a9b1b0110b1c2c6b9438 [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
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
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
41public:
42 // certificate request related
43 virtual CertificateRequest
44 getRequest(const std::string& requestId) = 0;
45
46 virtual void
47 addRequest(const CertificateRequest& request) = 0;
48
49 virtual void
50 updateRequest(const CertificateRequest& request) = 0;
51
52 virtual void
53 deleteRequest(const std::string& requestId) = 0;
54
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070055 virtual std::list<CertificateRequest>
56 listAllRequests() = 0;
57
58 virtual std::list<CertificateRequest>
59 listAllRequests(const Name& caName) = 0;
60
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080061 // certificate related
62 virtual security::v2::Certificate
63 getCertificate(const std::string& certId) = 0;
64
65 virtual void
66 addCertificate(const std::string& certId, const security::v2::Certificate& cert) = 0;
67
68 virtual void
69 updateCertificate(const std::string& certId, const security::v2::Certificate& cert) = 0;
70
71 virtual void
72 deleteCertificate(const std::string& certId) = 0;
73
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070074 virtual std::list<security::v2::Certificate>
75 listAllIssuedCertificates() = 0;
76
77 virtual std::list<security::v2::Certificate>
78 listAllIssuedCertificates(const Name& caName) = 0;
79
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080080public:
81 template<class CaStorageType>
82 static void
83 registerCaStorage(const std::string& caStorageType = CaStorageType::STORAGE_TYPE)
84 {
85 CaStorageFactory& factory = getFactory();
86 BOOST_ASSERT(factory.count(caStorageType) == 0);
87 factory[caStorageType] = [] {
88 return make_unique<CaStorageType>();
89 };
90 }
91
92 static unique_ptr<CaStorage>
93 createCaStorage(const std::string& caStorageType);
94
95private:
96 using CaStorageCreateFunc = function<unique_ptr<CaStorage> ()>;
97 using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
98
99 static CaStorageFactory&
100 getFactory();
101};
102
103#define NDNCERT_REGISTER_CA_STORAGE(C) \
104static class NdnCert ## C ## CaStorageRegistrationClass \
105{ \
106public: \
107 NdnCert ## C ## CaStorageRegistrationClass() \
108 { \
109 ::ndn::ndncert::CaStorage::registerCaStorage<C>(); \
110 } \
111} g_NdnCert ## C ## CaStorageRegistrationVariable
112
113} // namespace ndncert
114} // namespace ndn
115
116#endif // NDNCERT_CA_STORAGE_HPP