blob: 5331c7f09f6483b73830cda738ff5bf73076938e [file] [log] [blame]
Yingdi Yuadadb712015-04-15 17:23:56 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi68b53852018-07-25 13:56:38 -06002/*
3 * Copyright (c) 2013-2018 Regents of the University of California.
Yingdi Yuadadb712015-04-15 17:23:56 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library 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 Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Alexander Afanasyev97709c02016-08-25 19:58:30 -070022#ifndef NDN_SECURITY_PIB_PIB_MEMORY_HPP
23#define NDN_SECURITY_PIB_PIB_MEMORY_HPP
Yingdi Yuadadb712015-04-15 17:23:56 -070024
25#include "pib-impl.hpp"
26
27namespace ndn {
28namespace security {
Yingdi Yu6ee2d362015-07-16 21:48:05 -070029namespace pib {
Yingdi Yuadadb712015-04-15 17:23:56 -070030
31/**
32 * @brief An in-memory implementation of Pib
33 *
34 * All the contents in Pib are stored in memory
35 * and have the same lifetime as the implementation instance.
36 */
Yingdi Yu3bf91f52015-06-12 19:39:40 -070037class PibMemory : public PibImpl
Yingdi Yuadadb712015-04-15 17:23:56 -070038{
39public:
Yingdi Yufe4733a2015-10-22 14:24:12 -070040 /**
41 * @brief Create memory based PIB backend
42 * @param location Not used (required by the PIB-registration interface)
43 */
44 explicit
45 PibMemory(const std::string& location = "");
46
47 static const std::string&
48 getScheme();
Yingdi Yuadadb712015-04-15 17:23:56 -070049
50public: // TpmLocator management
Davide Pesavento57c07df2016-12-11 18:41:45 -050051 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020052 setTpmLocator(const std::string& tpmLocator) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070053
Davide Pesavento57c07df2016-12-11 18:41:45 -050054 std::string
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020055 getTpmLocator() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070056
57public: // Identity management
Davide Pesavento57c07df2016-12-11 18:41:45 -050058 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020059 hasIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070060
Davide Pesavento57c07df2016-12-11 18:41:45 -050061 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020062 addIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070063
Davide Pesavento57c07df2016-12-11 18:41:45 -050064 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020065 removeIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070066
Yingdi Yu7b3b5e92015-08-13 19:52:35 -070067 void
68 clearIdentities() override;
69
Davide Pesavento57c07df2016-12-11 18:41:45 -050070 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020071 getIdentities() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070072
Davide Pesavento57c07df2016-12-11 18:41:45 -050073 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020074 setDefaultIdentity(const Name& identityName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070075
Davide Pesavento57c07df2016-12-11 18:41:45 -050076 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020077 getDefaultIdentity() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070078
79public: // Key management
Davide Pesavento57c07df2016-12-11 18:41:45 -050080 bool
Yingdi Yu6ee2d362015-07-16 21:48:05 -070081 hasKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070082
Davide Pesavento57c07df2016-12-11 18:41:45 -050083 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070084 addKey(const Name& identity, const Name& keyName, const uint8_t* key, size_t keyLen) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070085
Davide Pesavento57c07df2016-12-11 18:41:45 -050086 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070087 removeKey(const Name& keyName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070088
Yingdi Yu6ee2d362015-07-16 21:48:05 -070089 Buffer
90 getKeyBits(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070091
Yingdi Yu6ee2d362015-07-16 21:48:05 -070092 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020093 getKeysOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070094
Davide Pesavento57c07df2016-12-11 18:41:45 -050095 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070096 setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070097
Yingdi Yu6ee2d362015-07-16 21:48:05 -070098 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020099 getDefaultKeyOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700100
101public: // Certificate management
Davide Pesavento57c07df2016-12-11 18:41:45 -0500102 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200103 hasCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700104
Davide Pesavento57c07df2016-12-11 18:41:45 -0500105 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700106 addCertificate(const v2::Certificate& certificate) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700107
Davide Pesavento57c07df2016-12-11 18:41:45 -0500108 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200109 removeCertificate(const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700110
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700111 v2::Certificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200112 getCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700113
Davide Pesavento57c07df2016-12-11 18:41:45 -0500114 std::set<Name>
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700115 getCertificatesOfKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700116
Davide Pesavento57c07df2016-12-11 18:41:45 -0500117 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700118 setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700119
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700120 v2::Certificate
121 getDefaultCertificateOfKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700122
123private:
Yingdi Yu7b3b5e92015-08-13 19:52:35 -0700124 std::string m_tpmLocator;
125
Yingdi Yuadadb712015-04-15 17:23:56 -0700126 bool m_hasDefaultIdentity;
127 Name m_defaultIdentity;
128
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700129 std::set<Name> m_identities;
Yingdi Yuadadb712015-04-15 17:23:56 -0700130
131 /// @brief identity => default key Name
Yingdi Yu03997682015-11-23 16:41:38 -0800132 std::map<Name, Name> m_defaultKeys;
Yingdi Yuadadb712015-04-15 17:23:56 -0700133
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700134 /// @brief keyName => keyBits
135 std::map<Name, Buffer> m_keys;
Yingdi Yuadadb712015-04-15 17:23:56 -0700136
137 /// @brief keyName => default certificate Name
Yingdi Yu03997682015-11-23 16:41:38 -0800138 std::map<Name, Name> m_defaultCerts;
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700139
140 /// @brief certificate Name => certificate
141 std::map<Name, v2::Certificate> m_certs;
Yingdi Yuadadb712015-04-15 17:23:56 -0700142};
143
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700144} // namespace pib
Yingdi Yuadadb712015-04-15 17:23:56 -0700145} // namespace security
146} // namespace ndn
147
Alexander Afanasyev97709c02016-08-25 19:58:30 -0700148#endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP