Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame^] | 3 | * Copyright (c) 2017-2018, 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 | |
| 24 | #include "certificate-request.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
| 29 | class CaStorage : noncopyable |
| 30 | { |
| 31 | public: |
| 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 Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame^] | 41 | virtual |
| 42 | ~CaStorage(); |
| 43 | |
| 44 | public: // certificate request related |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 45 | 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 Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 57 | virtual std::list<CertificateRequest> |
| 58 | listAllRequests() = 0; |
| 59 | |
| 60 | virtual std::list<CertificateRequest> |
| 61 | listAllRequests(const Name& caName) = 0; |
| 62 | |
Davide Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame^] | 63 | public: // certificate related |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 64 | 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 Zhang | ae123bf | 2017-04-14 12:24:53 -0700 | [diff] [blame] | 76 | 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 Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame^] | 82 | public: // factory |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 83 | 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 | |
| 97 | private: |
| 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) \ |
| 106 | static class NdnCert ## C ## CaStorageRegistrationClass \ |
| 107 | { \ |
| 108 | public: \ |
| 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 |