blob: 0cfe7c130934209a8469d9f03afd08b416b9b1d7 [file] [log] [blame]
Yingdi Yuadadb712015-04-15 17:23:56 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesaventoaa82eb62016-04-22 19:08:40 +02003 * Copyright (c) 2013-2016 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 {
29
30/**
31 * @brief An in-memory implementation of Pib
32 *
33 * All the contents in Pib are stored in memory
34 * and have the same lifetime as the implementation instance.
35 */
Yingdi Yu3bf91f52015-06-12 19:39:40 -070036class PibMemory : public PibImpl
Yingdi Yuadadb712015-04-15 17:23:56 -070037{
38public:
39 class Error : public PibImpl::Error
40 {
41 public:
42 explicit
43 Error(const std::string& what)
44 : PibImpl::Error(what)
45 {
46 }
47 };
48
49public:
Yingdi Yu3bf91f52015-06-12 19:39:40 -070050 PibMemory();
Yingdi Yuadadb712015-04-15 17:23:56 -070051
52public: // TpmLocator management
53
Davide Pesavento57c07df2016-12-11 18:41:45 -050054 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020055 setTpmLocator(const std::string& tpmLocator) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070056
Davide Pesavento57c07df2016-12-11 18:41:45 -050057 std::string
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020058 getTpmLocator() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070059
60public: // Identity management
61
Davide Pesavento57c07df2016-12-11 18:41:45 -050062 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020063 hasIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070064
Davide Pesavento57c07df2016-12-11 18:41:45 -050065 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020066 addIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070067
Davide Pesavento57c07df2016-12-11 18:41:45 -050068 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020069 removeIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070070
Davide Pesavento57c07df2016-12-11 18:41:45 -050071 std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020072 getIdentities() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070073
Davide Pesavento57c07df2016-12-11 18:41:45 -050074 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020075 setDefaultIdentity(const Name& identityName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070076
Davide Pesavento57c07df2016-12-11 18:41:45 -050077 Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020078 getDefaultIdentity() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070079
80public: // Key management
81
Davide Pesavento57c07df2016-12-11 18:41:45 -050082 bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020083 hasKey(const Name& identity, const name::Component& keyId) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070084
Davide Pesavento57c07df2016-12-11 18:41:45 -050085 void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070086 addKey(const Name& identity, const name::Component& keyId, const v1::PublicKey& publicKey) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070087
Davide Pesavento57c07df2016-12-11 18:41:45 -050088 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020089 removeKey(const Name& identity, const name::Component& keyId) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070090
Davide Pesavento57c07df2016-12-11 18:41:45 -050091 v1::PublicKey
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020092 getKeyBits(const Name& identity, const name::Component& keyId) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070093
Davide Pesavento57c07df2016-12-11 18:41:45 -050094 std::set<name::Component>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020095 getKeysOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070096
Davide Pesavento57c07df2016-12-11 18:41:45 -050097 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020098 setDefaultKeyOfIdentity(const Name& identity, const name::Component& keyId) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070099
Davide Pesavento57c07df2016-12-11 18:41:45 -0500100 name::Component
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200101 getDefaultKeyOfIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700102
103public: // Certificate management
104
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
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700109 addCertificate(const v1::IdentityCertificate& 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
Davide Pesavento57c07df2016-12-11 18:41:45 -0500114 v1::IdentityCertificate
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>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200118 getCertificatesOfKey(const Name& identity, const name::Component& keyId) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700119
Davide Pesavento57c07df2016-12-11 18:41:45 -0500120 void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200121 setDefaultCertificateOfKey(const Name& identity, const name::Component& keyId, const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700122
Davide Pesavento57c07df2016-12-11 18:41:45 -0500123 v1::IdentityCertificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200124 getDefaultCertificateOfKey(const Name& identity, const name::Component& keyId) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700125
126private: // Key management
127
128 Name
129 getKeyName(const Name& identity, const name::Component& keyId) const;
130
131private:
132
133 std::set<Name> m_identities;
134 bool m_hasDefaultIdentity;
135 Name m_defaultIdentity;
136
137 /// @brief keyName => keyBits
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700138 std::map<Name, v1::PublicKey> m_keys;
Yingdi Yuadadb712015-04-15 17:23:56 -0700139
140 /// @brief identity => default key Name
141 std::map<Name, Name> m_defaultKey;
142
143 /// @brief certificate Name => certificate
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700144 std::map<Name, v1::IdentityCertificate> m_certs;
Yingdi Yuadadb712015-04-15 17:23:56 -0700145
146 /// @brief keyName => default certificate Name
147 std::map<Name, Name> m_defaultCert;
148};
149
150} // namespace security
151} // namespace ndn
152
Alexander Afanasyev97709c02016-08-25 19:58:30 -0700153#endif // NDN_SECURITY_PIB_PIB_MEMORY_HPP