23 #include "ndn-cxx/security/pib/impl/key-impl.hpp"
37 const KeyContainer& container) noexcept
39 , m_container(&container)
46 BOOST_ASSERT(m_container !=
nullptr);
47 return m_container->
get(*m_it);
53 bool isThisEnd = m_container ==
nullptr || m_it == m_container->m_keyNames.end();
54 bool isOtherEnd = other.m_container ==
nullptr || other.m_it == other.m_container->m_keyNames.end();
57 return !isOtherEnd && m_container->m_pib == other.m_container->m_pib && m_it == other.m_it;
60 KeyContainer::KeyContainer(
const Name& identity, shared_ptr<PibImpl> pibImpl)
61 : m_identity(identity)
62 , m_pib(std::move(pibImpl))
64 BOOST_ASSERT(m_pib !=
nullptr);
65 m_keyNames = m_pib->getKeysOfIdentity(identity);
71 return {m_keyNames.find(keyName), *
this};
78 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
79 "`" + m_identity.
toUri() +
"`"));
82 bool isNew = m_keyNames.insert(keyName).second;
84 m_pib->addKey(m_identity, keyName, keyBits);
86 auto key = std::make_shared<detail::KeyImpl>(keyName,
Buffer(keyBits.begin(), keyBits.end()), m_pib);
87 m_keys[keyName] = key;
95 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
96 "`" + m_identity.
toUri() +
"`"));
99 if (m_keyNames.erase(keyName) > 0) {
101 m_keys.erase(keyName);
105 BOOST_ASSERT(m_keys.find(keyName) == m_keys.end());
107 m_pib->removeKey(keyName);
114 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
115 "`" + m_identity.
toUri() +
"`"));
118 auto it = m_keys.find(keyName);
119 if (it != m_keys.end()) {
120 return Key(it->second);
125 auto keyBits = m_pib->getKeyBits(keyName);
127 auto key = std::make_shared<detail::KeyImpl>(keyName, std::move(keyBits), m_pib);
128 m_keys[keyName] = key;
135 return m_keyNames == m_pib->getKeysOfIdentity(m_identity);
General-purpose automatically managed/resized buffer.
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.
bool operator==(const const_iterator &other) const
Key add(span< const uint8_t > key, const Name &keyName)
Add key with name keyName into the container.
Key get(const Name &keyName) const
Return a key by name.
const_iterator find(const Name &keyName) const
bool isConsistent() const
Check if the container is consistent with the backend storage.
void remove(const Name &keyName)
Remove a key with keyName from the container.
Frontend handle for a key in the PIB.
#define NDN_CXX_ASSERT_FORWARD_ITERATOR(T)
Assert T is a forward iterator.
#define NDN_LOG_DEBUG(expression)
Log at DEBUG level.
#define NDN_LOG_INIT(name)
Define a non-member log module.
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.