blob: 377d52dd236b650f5dfc48e6b13dec27e28fdedf [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
Yingdi Yu3bf91f52015-06-12 19:39:40 -070022#ifndef NDN_SECURITY_PIB_MEMORY_HPP
23#define NDN_SECURITY_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
54 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020055 setTpmLocator(const std::string& tpmLocator) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070056
57 virtual 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
62 virtual bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020063 hasIdentity(const Name& identity) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070064
65 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020066 addIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070067
68 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020069 removeIdentity(const Name& identity) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070070
71 virtual std::set<Name>
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020072 getIdentities() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070073
74 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020075 setDefaultIdentity(const Name& identityName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070076
77 virtual Name
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020078 getDefaultIdentity() const override;
Yingdi Yuadadb712015-04-15 17:23:56 -070079
80public: // Key management
81
82 virtual 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
85 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +020086 addKey(const Name& identity, const name::Component& keyId, const PublicKey& publicKey) override;
Yingdi Yuadadb712015-04-15 17:23:56 -070087
88 virtual 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
91 virtual 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
94 virtual 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
97 virtual 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
100 virtual 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
105 virtual bool
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200106 hasCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700107
108 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200109 addCertificate(const IdentityCertificate& certificate) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700110
111 virtual void
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200112 removeCertificate(const Name& certName) override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700113
114 virtual IdentityCertificate
Davide Pesaventoaa82eb62016-04-22 19:08:40 +0200115 getCertificate(const Name& certName) const override;
Yingdi Yuadadb712015-04-15 17:23:56 -0700116
117 virtual 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
120 virtual 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
123 virtual 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
138 std::map<Name, PublicKey> m_keys;
139
140 /// @brief identity => default key Name
141 std::map<Name, Name> m_defaultKey;
142
143 /// @brief certificate Name => certificate
144 std::map<Name, IdentityCertificate> m_certs;
145
146 /// @brief keyName => default certificate Name
147 std::map<Name, Name> m_defaultCert;
148};
149
150} // namespace security
151} // namespace ndn
152
Yingdi Yu3bf91f52015-06-12 19:39:40 -0700153#endif // NDN_SECURITY_PIB_MEMORY_HPP