blob: 8ef5bab663fea8afb965a023b576cf31269d54e0 [file] [log] [blame]
Yingdi Yuadadb712015-04-15 17:23:56 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 Regents of the University of California.
4 *
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
22#ifndef NDN_SECURITY_IN_MEMORY_PIB_IMPL_HPP
23#define NDN_SECURITY_IN_MEMORY_PIB_IMPL_HPP
24
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 */
36class InMemoryPibImpl : public PibImpl
37{
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:
50 InMemoryPibImpl();
51
52public: // TpmLocator management
53
54 virtual void
55 setTpmLocator(const std::string& tpmLocator) NDN_CXX_DECL_OVERRIDE;
56
57 virtual std::string
58 getTpmLocator() const NDN_CXX_DECL_OVERRIDE;
59
60public: // Identity management
61
62 virtual bool
63 hasIdentity(const Name& identity) const NDN_CXX_DECL_OVERRIDE;
64
65 virtual void
66 addIdentity(const Name& identity) NDN_CXX_DECL_OVERRIDE;
67
68 virtual void
69 removeIdentity(const Name& identity) NDN_CXX_DECL_OVERRIDE;
70
71 virtual std::set<Name>
72 getIdentities() const NDN_CXX_DECL_OVERRIDE;
73
74 virtual void
75 setDefaultIdentity(const Name& identityName) NDN_CXX_DECL_OVERRIDE;
76
77 virtual Name
78 getDefaultIdentity() const NDN_CXX_DECL_OVERRIDE;
79
80public: // Key management
81
82 virtual bool
83 hasKey(const Name& identity, const name::Component& keyId) const NDN_CXX_DECL_OVERRIDE;
84
85 virtual void
86 addKey(const Name& identity, const name::Component& keyId, const PublicKey& publicKey) NDN_CXX_DECL_OVERRIDE;
87
88 virtual void
89 removeKey(const Name& identity, const name::Component& keyId) NDN_CXX_DECL_OVERRIDE;
90
91 virtual PublicKey
92 getKeyBits(const Name& identity, const name::Component& keyId) const NDN_CXX_DECL_OVERRIDE;
93
94 virtual std::set<name::Component>
95 getKeysOfIdentity(const Name& identity) const NDN_CXX_DECL_OVERRIDE;
96
97 virtual void
98 setDefaultKeyOfIdentity(const Name& identity, const name::Component& keyId) NDN_CXX_DECL_OVERRIDE;
99
100 virtual name::Component
101 getDefaultKeyOfIdentity(const Name& identity) const NDN_CXX_DECL_OVERRIDE;
102
103public: // Certificate management
104
105 virtual bool
106 hasCertificate(const Name& certName) const NDN_CXX_DECL_OVERRIDE;
107
108 virtual void
109 addCertificate(const IdentityCertificate& certificate) NDN_CXX_DECL_OVERRIDE;
110
111 virtual void
112 removeCertificate(const Name& certName) NDN_CXX_DECL_OVERRIDE;
113
114 virtual IdentityCertificate
115 getCertificate(const Name& certName) const NDN_CXX_DECL_OVERRIDE;
116
117 virtual std::set<Name>
118 getCertificatesOfKey(const Name& identity, const name::Component& keyId) const NDN_CXX_DECL_OVERRIDE;
119
120 virtual void
121 setDefaultCertificateOfKey(const Name& identity, const name::Component& keyId, const Name& certName) NDN_CXX_DECL_OVERRIDE;
122
123 virtual IdentityCertificate
124 getDefaultCertificateOfKey(const Name& identity, const name::Component& keyId) const NDN_CXX_DECL_OVERRIDE;
125
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
153#endif // NDN_SECURITY_SEC_PIB_MEMORY_IMPL_HPP