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 <set>
26 #include <unordered_map>
27 #include "key.hpp"
28 
29 namespace ndn {
30 namespace security {
31 namespace pib {
32 
33 class PibImpl;
34 
35 namespace detail {
36 class KeyImpl;
37 class IdentityImpl;
38 } // namespace detail
39 
46 class KeyContainer : noncopyable
47 {
48 public:
49  class const_iterator : public std::iterator<std::forward_iterator_tag, const Key>
50  {
51  public:
53 
54  Key
55  operator*();
56 
58  operator++();
59 
61  operator++(int);
62 
63  bool
64  operator==(const const_iterator& other);
65 
66  bool
67  operator!=(const const_iterator& other);
68 
69  private:
70  const_iterator(std::set<Name>::const_iterator it, const KeyContainer& container);
71 
72  private:
73  std::set<Name>::const_iterator m_it;
74  const KeyContainer* m_container;
75 
76  friend class KeyContainer;
77  };
78 
80 
81 public:
83  begin() const;
84 
86  end() const;
87 
89  find(const Name& keyName) const;
90 
91  size_t
92  size() const;
93 
98  Key
99  add(const uint8_t* key, size_t keyLen, const Name& keyName);
100 
105  void
106  remove(const Name& keyName);
107 
113  Key
114  get(const Name& keyName) const;
115 
121  bool
122  isConsistent() const;
123 
129  KeyContainer(const Name& identity, shared_ptr<PibImpl> impl);
130 
131  const std::set<Name>&
132  getKeyNames() const
133  {
134  return m_keyNames;
135  }
136 
137  const std::unordered_map<Name, shared_ptr<detail::KeyImpl>>&
138  getLoadedKeys() const
139  {
140  return m_keys;
141  }
142 
143 private:
144  Name m_identity;
145  std::set<Name> m_keyNames;
147  mutable std::unordered_map<Name, shared_ptr<detail::KeyImpl>> m_keys;
148 
149  shared_ptr<PibImpl> m_impl;
150  friend class detail::IdentityImpl;
151 };
152 
153 } // namespace pib
154 
155 using pib::KeyContainer;
156 
157 } // namespace security
158 } // namespace ndn
159 
160 #endif // NDN_SECURITY_PIB_KEY_CONTAINER_HPP
const_iterator find(const Name &keyName) const
Backend instance of Identity.
const_iterator begin() const
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
bool operator==(const const_iterator &other)
bool isConsistent() const
Check if the container is consistent with the backend storage.
bool operator!=(const const_iterator &other)
Container of keys of an identity.
A frontend handle of a key instance.
Definition: key.hpp:49
Key add(const uint8_t *key, size_t keyLen, const Name &keyName)
Add key of keyLen bytes with keyName into the container.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const_iterator end() const