key-container.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_SECURITY_PIB_KEY_CONTAINER_HPP
23 #define NDN_SECURITY_PIB_KEY_CONTAINER_HPP
24 
25 #include "key.hpp"
26 
27 #include <set>
28 #include <unordered_map>
29 
30 namespace ndn {
31 namespace security {
32 namespace pib {
33 
34 class PibImpl;
35 
36 namespace detail {
37 class KeyImpl;
38 class IdentityImpl;
39 } // namespace detail
40 
47 class KeyContainer : noncopyable
48 {
49 public:
50  class const_iterator : public std::iterator<std::forward_iterator_tag, const Key>
51  {
52  public:
54 
55  Key
56  operator*();
57 
59  operator++();
60 
62  operator++(int);
63 
64  bool
65  operator==(const const_iterator& other);
66 
67  bool
68  operator!=(const const_iterator& other);
69 
70  private:
71  const_iterator(std::set<Name>::const_iterator it, const KeyContainer& container);
72 
73  private:
74  std::set<Name>::const_iterator m_it;
75  const KeyContainer* m_container;
76 
77  friend class KeyContainer;
78  };
79 
81 
82 public:
84  begin() const;
85 
87  end() const;
88 
90  find(const Name& keyName) const;
91 
92  size_t
93  size() const;
94 
101  Key
102  add(const uint8_t* key, size_t keyLen, const Name& keyName);
103 
108  void
109  remove(const Name& keyName);
110 
116  Key
117  get(const Name& keyName) const;
118 
124  bool
125  isConsistent() const;
126 
132  KeyContainer(const Name& identity, shared_ptr<PibImpl> pibImpl);
133 
134  const std::set<Name>&
135  getKeyNames() const
136  {
137  return m_keyNames;
138  }
139 
140  const std::unordered_map<Name, shared_ptr<detail::KeyImpl>>&
141  getLoadedKeys() const
142  {
143  return m_keys;
144  }
145 
146 private:
147  Name m_identity;
148  std::set<Name> m_keyNames;
150  mutable std::unordered_map<Name, shared_ptr<detail::KeyImpl>> m_keys;
151 
152  shared_ptr<PibImpl> m_pib;
153 
154  friend class detail::IdentityImpl;
155 };
156 
157 } // namespace pib
158 
159 using pib::KeyContainer;
160 
161 } // namespace security
162 } // namespace ndn
163 
164 #endif // NDN_SECURITY_PIB_KEY_CONTAINER_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
bool operator==(const Identity &lhs, const Identity &rhs)
Definition: identity.hpp:162
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
Container of keys of an identity.
A frontend handle of a key instance.
Definition: key.hpp:49
Represents an absolute name.
Definition: name.hpp:42
bool operator!=(const Identity &lhs, const Identity &rhs)
Definition: identity.cpp:101