NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
key-container.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 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_PIB_KEY_CONTAINER_HPP
23 #define NDN_SECURITY_PIB_KEY_CONTAINER_HPP
24 
26 
27 #include <iterator>
28 #include <set>
29 #include <unordered_map>
30 
31 namespace ndn {
32 namespace security {
33 namespace pib {
34 
35 class PibImpl;
36 
37 namespace detail {
38 class KeyImpl;
39 class IdentityImpl;
40 } // namespace detail
41 
48 class KeyContainer : noncopyable
49 {
50 public:
52  {
53  public:
54  using iterator_category = std::forward_iterator_tag;
55  using value_type = const Key;
56  using difference_type = std::ptrdiff_t;
57  using pointer = value_type*;
59 
61 
62  Key
63  operator*();
64 
66  operator++();
67 
69  operator++(int);
70 
71  bool
72  operator==(const const_iterator& other);
73 
74  bool
75  operator!=(const const_iterator& other);
76 
77  private:
78  const_iterator(std::set<Name>::const_iterator it, const KeyContainer& container);
79 
80  private:
81  std::set<Name>::const_iterator m_it;
82  const KeyContainer* m_container;
83 
84  friend class KeyContainer;
85  };
86 
88 
89 public:
91  begin() const;
92 
94  end() const;
95 
97  find(const Name& keyName) const;
98 
99  size_t
100  size() const;
101 
108  Key
109  add(const uint8_t* key, size_t keyLen, const Name& keyName);
110 
115  void
116  remove(const Name& keyName);
117 
123  Key
124  get(const Name& keyName) const;
125 
131  bool
132  isConsistent() const;
133 
139  KeyContainer(const Name& identity, shared_ptr<PibImpl> pibImpl);
140 
141  const std::set<Name>&
142  getKeyNames() const
143  {
144  return m_keyNames;
145  }
146 
147  const std::unordered_map<Name, shared_ptr<detail::KeyImpl>>&
149  {
150  return m_keys;
151  }
152 
153 private:
154  Name m_identity;
155  std::set<Name> m_keyNames;
157  mutable std::unordered_map<Name, shared_ptr<detail::KeyImpl>> m_keys;
158 
159  shared_ptr<PibImpl> m_pib;
160 
161  friend class detail::IdentityImpl;
162 };
163 
164 } // namespace pib
165 
166 using pib::KeyContainer;
167 
168 } // namespace security
169 } // namespace ndn
170 
171 #endif // NDN_SECURITY_PIB_KEY_CONTAINER_HPP
Backend instance of Identity.
const_iterator find(const Name &keyName) const
Copyright (c) 2011-2015 Regents of the University of California.
const_iterator begin() const
const std::set< Name > & getKeyNames() const
bool operator==(const const_iterator &other)
void remove(const Name &keyName)
Remove a key with keyName from the container.
bool operator!=(const const_iterator &other)
Container of keys of an identity.
const_iterator end() const
A frontend handle of a key instance.
Definition: key.hpp:49
Key get(const Name &keyName) const
Get a key with keyName from the container.
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE shared_ptr< PibImpl > pibImpl
Key add(const uint8_t *key, size_t keyLen, const Name &keyName)
Add key of keyLen bytes with keyName into the container.
bool isConsistent() const
Check if the container is consistent with the backend storage.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
Represents an absolute name.
Definition: name.hpp:43
const std::unordered_map< Name, shared_ptr< detail::KeyImpl > > & getLoadedKeys() const