23 #include "ndn-cxx/security/pib/impl/key-impl.hpp"
34 : m_container(nullptr)
41 , m_container(&container)
48 BOOST_ASSERT(m_container !=
nullptr);
49 return m_container->get(*m_it);
70 bool isThisEnd = m_container ==
nullptr || m_it == m_container->m_keyNames.end();
71 bool isOtherEnd = other.m_container ==
nullptr || other.m_it == other.m_container->m_keyNames.end();
72 return ((isThisEnd || isOtherEnd) ?
73 (isThisEnd == isOtherEnd) :
74 m_container->m_pib == other.m_container->m_pib && m_it == other.m_it);
80 return !(*
this == other);
83 KeyContainer::KeyContainer(
const Name& identity, shared_ptr<PibImpl> pibImpl)
84 : m_identity(identity)
85 , m_pib(std::move(pibImpl))
87 BOOST_ASSERT(m_pib !=
nullptr);
88 m_keyNames = m_pib->getKeysOfIdentity(identity);
94 return {m_keyNames.begin(), *
this};
106 return {m_keyNames.find(keyName), *
this};
112 return m_keyNames.size();
119 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
120 "`" + m_identity.
toUri() +
"`"));
123 m_keyNames.insert(keyName);
124 m_keys[keyName] = make_shared<detail::KeyImpl>(keyName, key, m_pib);
132 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
133 "`" + m_identity.
toUri() +
"`"));
136 m_keyNames.erase(keyName);
137 m_keys.erase(keyName);
138 m_pib->removeKey(keyName);
145 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
146 "`" + m_identity.
toUri() +
"`"));
149 shared_ptr<detail::KeyImpl> key;
150 auto it = m_keys.find(keyName);
152 if (it != m_keys.end()) {
156 key = make_shared<detail::KeyImpl>(keyName, m_pib);
157 m_keys[keyName] = key;
166 return m_keyNames == m_pib->getKeysOfIdentity(m_identity);
Represents an absolute name.
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
const_iterator & operator++()
bool operator!=(const const_iterator &other)
bool operator==(const const_iterator &other)
Container of keys of an identity.
Key add(span< const uint8_t > key, const Name &keyName)
Add key with name keyName into the container.
Key get(const Name &keyName) const
Get a key with keyName from the container.
const_iterator find(const Name &keyName) const
bool isConsistent() const
Check if the container is consistent with the backend storage.
const_iterator begin() const
const_iterator end() const
void remove(const Name &keyName)
Remove a key with keyName from the container.
A frontend handle of a key instance.
#define NDN_CXX_ASSERT_FORWARD_ITERATOR(T)
assert T is a forward iterator
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.