23 #include "ndn-cxx/security/pib/impl/key-impl.hpp"
32 KeyContainer::const_iterator::equals(
const const_iterator& other)
const noexcept
34 bool isThisEnd = m_container ==
nullptr || m_it == m_container->m_keyNames.end();
35 bool isOtherEnd = other.m_container ==
nullptr || other.m_it == other.m_container->m_keyNames.end();
38 return !isOtherEnd && m_container->m_pib == other.m_container->m_pib && m_it == other.m_it;
41 KeyContainer::KeyContainer(
const Name& identity, shared_ptr<PibImpl> pibImpl)
42 : m_identity(identity)
43 , m_pib(std::move(pibImpl))
45 BOOST_ASSERT(m_pib !=
nullptr);
46 m_keyNames = m_pib->getKeysOfIdentity(identity);
49 KeyContainer::const_iterator
50 KeyContainer::find(
const Name& keyName)
const
52 return {m_keyNames.find(keyName), *
this};
56 KeyContainer::add(span<const uint8_t> keyBits,
const Name& keyName)
59 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
60 "`" + m_identity.toUri() +
"`"));
63 bool isNew = m_keyNames.insert(keyName).second;
65 m_pib->addKey(m_identity, keyName, keyBits);
67 auto key = std::make_shared<KeyImpl>(keyName,
Buffer(keyBits.begin(), keyBits.end()), m_pib);
68 m_keys[keyName] = key;
73 KeyContainer::remove(
const Name& keyName)
76 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
77 "`" + m_identity.toUri() +
"`"));
80 if (m_keyNames.erase(keyName) > 0) {
82 m_keys.erase(keyName);
86 BOOST_ASSERT(m_keys.find(keyName) == m_keys.end());
88 m_pib->removeKey(keyName);
92 KeyContainer::get(
const Name& keyName)
const
95 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` does not match identity "
96 "`" + m_identity.toUri() +
"`"));
99 if (
auto it = m_keys.find(keyName); it != m_keys.end()) {
100 return Key(it->second);
105 auto keyBits = m_pib->getKeyBits(keyName);
107 auto key = std::make_shared<KeyImpl>(keyName, std::move(keyBits), m_pib);
108 m_keys[keyName] = key;
113 KeyContainer::isConsistent()
const
115 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.
Frontend handle for a key in the PIB.
#define NDN_LOG_DEBUG(expression)
Log at DEBUG level.
#define NDN_LOG_INIT(name)
Define a non-member log module.
Contains the ndn-cxx security framework.
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.