blob: 8bacf5c221bdede013a42f98b5359952e9e00264 [file] [log] [blame]
Yingdi Yuadadb712015-04-15 17:23:56 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu6ee2d362015-07-16 21:48:05 -07003 * Copyright (c) 2013-2017 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:
40 class Error : public PibImpl::Error
41 {
42 public:
43 explicit
44 Error(const std::string& what)
45 : PibImpl::Error(what)
46 {
47 }
48 };
49
50public:
Yingdi Yu3bf91f52015-06-12 19:39:40 -070051 PibMemory();
Yingdi Yuadadb712015-04-15 17:23:56 -070052
53public: // TpmLocator management
54
Davide Pesavento57c07df2016-12-11 18:41:45 -050055 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020056 setTpmLocator(const std::string& tpmLocator) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070057
Davide Pesavento57c07df2016-12-11 18:41:45 -050058 std::string
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020059 getTpmLocator() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070060
61public: // Identity management
62
Davide Pesavento57c07df2016-12-11 18:41:45 -050063 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020064 hasIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070065
Davide Pesavento57c07df2016-12-11 18:41:45 -050066 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020067 addIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070068
Davide Pesavento57c07df2016-12-11 18:41:45 -050069 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020070 removeIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070071
Davide Pesavento57c07df2016-12-11 18:41:45 -050072 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020073 getIdentities() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070074
Davide Pesavento57c07df2016-12-11 18:41:45 -050075 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020076 setDefaultIdentity(const Name& identityName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070077
Davide Pesavento57c07df2016-12-11 18:41:45 -050078 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020079 getDefaultIdentity() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070080
81public: // Key management
82
Davide Pesavento57c07df2016-12-11 18:41:45 -050083 bool
Yingdi Yu6ee2d362015-07-16 21:48:05 -070084 hasKey(const Name& keyName) const 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 addKey(const Name& identity, const Name& keyName, const uint8_t* key, size_t keyLen) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070088
Davide Pesavento57c07df2016-12-11 18:41:45 -050089 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070090 removeKey(const Name& keyName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070091
Yingdi Yu6ee2d362015-07-16 21:48:05 -070092 Buffer
93 getKeyBits(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070094
Yingdi Yu6ee2d362015-07-16 21:48:05 -070095 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020096 getKeysOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070097
Davide Pesavento57c07df2016-12-11 18:41:45 -050098 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -070099 setDefaultKeyOfIdentity(const Name& identity, const Name& keyName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700100
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700101 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200102 getDefaultKeyOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700103
104public: // Certificate management
Davide Pesavento57c07df2016-12-11 18:41:45 -0500105 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200106 hasCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700107
Davide Pesavento57c07df2016-12-11 18:41:45 -0500108 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700109 addCertificate(const v2::Certificate& certificate) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700110
Davide Pesavento57c07df2016-12-11 18:41:45 -0500111 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200112 removeCertificate(const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700113
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700114 v2::Certificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200115 getCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700116
Davide Pesavento57c07df2016-12-11 18:41:45 -0500117 std::set<Name>
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700118 getCertificatesOfKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700119
Davide Pesavento57c07df2016-12-11 18:41:45 -0500120 void
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700121 setDefaultCertificateOfKey(const Name& keyName, const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700122
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700123 v2::Certificate
124 getDefaultCertificateOfKey(const Name& keyName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700125
126private:
Yingdi Yuadadb712015-04-15 17:23:56 -0700127 bool m_hasDefaultIdentity;
128 Name m_defaultIdentity;
129
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700130 std::set<Name> m_identities;
Yingdi Yuadadb712015-04-15 17:23:56 -0700131
132 /// @brief identity => default key Name
133 std::map<Name, Name> m_defaultKey;
134
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700135 /// @brief keyName => keyBits
136 std::map<Name, Buffer> m_keys;
Yingdi Yuadadb712015-04-15 17:23:56 -0700137
138 /// @brief keyName => default certificate Name
139 std::map<Name, Name> m_defaultCert;
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700140
141 /// @brief certificate Name => certificate
142 std::map<Name, v2::Certificate> m_certs;
Yingdi Yuadadb712015-04-15 17:23:56 -0700143};
144
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700145} // namespace pib
Yingdi Yuadadb712015-04-15 17:23:56 -0700146} // namespace security
147} // namespace ndn
148
Alexander Afanasyev97709c02016-08-25 19:58:30 -0700149#endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP