security: move shared_ptr<PibImpl> when possible
Also rename m_impl to m_pib, since it's not a pimpl pointer.
Change-Id: I9e10ada54332318154374f61df6e387348ccc60a
diff --git a/src/security/pib/detail/identity-impl.cpp b/src/security/pib/detail/identity-impl.cpp
index 284f14c..45b07b0 100644
--- a/src/security/pib/detail/identity-impl.cpp
+++ b/src/security/pib/detail/identity-impl.cpp
@@ -28,18 +28,18 @@
namespace pib {
namespace detail {
-IdentityImpl::IdentityImpl(const Name& identityName, shared_ptr<PibImpl> impl, bool needInit)
+IdentityImpl::IdentityImpl(const Name& identityName, shared_ptr<PibImpl> pibImpl, bool needInit)
: m_name(identityName)
+ , m_pib(std::move(pibImpl))
+ , m_keys(identityName, m_pib)
, m_isDefaultKeyLoaded(false)
- , m_keys(identityName, impl)
- , m_impl(impl)
{
- BOOST_ASSERT(impl != nullptr);
+ BOOST_ASSERT(m_pib != nullptr);
if (needInit) {
- m_impl->addIdentity(m_name);
+ m_pib->addIdentity(m_name);
}
- else if (!m_impl->hasIdentity(m_name)) {
+ else if (!m_pib->hasIdentity(m_name)) {
BOOST_THROW_EXCEPTION(Pib::Error("Identity " + m_name.toUri() + " does not exist"));
}
}
@@ -48,7 +48,6 @@
IdentityImpl::addKey(const uint8_t* key, size_t keyLen, const Name& keyName)
{
BOOST_ASSERT(m_keys.isConsistent());
-
return m_keys.add(key, keyLen, keyName);
}
@@ -67,7 +66,6 @@
IdentityImpl::getKey(const Name& keyName) const
{
BOOST_ASSERT(m_keys.isConsistent());
-
return m_keys.get(keyName);
}
@@ -75,7 +73,6 @@
IdentityImpl::getKeys() const
{
BOOST_ASSERT(m_keys.isConsistent());
-
return m_keys;
}
@@ -86,7 +83,7 @@
m_defaultKey = m_keys.get(keyName);
m_isDefaultKeyLoaded = true;
- m_impl->setDefaultKeyOfIdentity(m_name, keyName);
+ m_pib->setDefaultKeyOfIdentity(m_name, keyName);
return m_defaultKey;
}
@@ -103,11 +100,10 @@
BOOST_ASSERT(m_keys.isConsistent());
if (!m_isDefaultKeyLoaded) {
- m_defaultKey = m_keys.get(m_impl->getDefaultKeyOfIdentity(m_name));
+ m_defaultKey = m_keys.get(m_pib->getDefaultKeyOfIdentity(m_name));
m_isDefaultKeyLoaded = true;
}
-
- BOOST_ASSERT(m_impl->getDefaultKeyOfIdentity(m_name) == m_defaultKey.getName());
+ BOOST_ASSERT(m_pib->getDefaultKeyOfIdentity(m_name) == m_defaultKey.getName());
return m_defaultKey;
}
diff --git a/src/security/pib/detail/identity-impl.hpp b/src/security/pib/detail/identity-impl.hpp
index ceff37d..b4823a1 100644
--- a/src/security/pib/detail/identity-impl.hpp
+++ b/src/security/pib/detail/identity-impl.hpp
@@ -47,13 +47,15 @@
* @brief Create an Identity with @p identityName.
*
* @param identityName The name of the Identity.
- * @param impl The PIB backend implementation.
+ * @param pibImpl The PIB backend implementation.
* @param needInit If true, create the identity in backend when the identity does not exist.
* Otherwise, throw Pib::Error when the identity does not exist.
*/
- IdentityImpl(const Name& identityName, shared_ptr<PibImpl> impl, bool needInit = false);
+ IdentityImpl(const Name& identityName, shared_ptr<PibImpl> pibImpl, bool needInit = false);
- /// @brief Get the name of the identity.
+ /**
+ * @brief Get the name of the identity.
+ */
const Name&
getName() const
{
@@ -122,12 +124,11 @@
private:
Name m_name;
+ shared_ptr<PibImpl> m_pib;
+
+ KeyContainer m_keys;
mutable bool m_isDefaultKeyLoaded;
mutable Key m_defaultKey;
-
- mutable KeyContainer m_keys;
-
- shared_ptr<PibImpl> m_impl;
};
} // namespace detail
diff --git a/src/security/pib/detail/key-impl.cpp b/src/security/pib/detail/key-impl.cpp
index c0cd839..e88bdac 100644
--- a/src/security/pib/detail/key-impl.cpp
+++ b/src/security/pib/detail/key-impl.cpp
@@ -29,15 +29,15 @@
namespace pib {
namespace detail {
-KeyImpl::KeyImpl(const Name& keyName, const uint8_t* key, size_t keyLen, shared_ptr<PibImpl> impl)
+KeyImpl::KeyImpl(const Name& keyName, const uint8_t* key, size_t keyLen, shared_ptr<PibImpl> pibImpl)
: m_identity(v2::extractIdentityFromKeyName(keyName))
, m_keyName(keyName)
, m_key(key, keyLen)
+ , m_pib(std::move(pibImpl))
+ , m_certificates(keyName, m_pib)
, m_isDefaultCertificateLoaded(false)
- , m_certificates(keyName, impl)
- , m_impl(impl)
{
- BOOST_ASSERT(impl != nullptr);
+ BOOST_ASSERT(m_pib != nullptr);
transform::PublicKey publicKey;
try {
@@ -48,19 +48,19 @@
}
m_keyType = publicKey.getKeyType();
- m_impl->addKey(m_identity, m_keyName, key, keyLen);
+ m_pib->addKey(m_identity, m_keyName, key, keyLen);
}
-KeyImpl::KeyImpl(const Name& keyName, shared_ptr<PibImpl> impl)
+KeyImpl::KeyImpl(const Name& keyName, shared_ptr<PibImpl> pibImpl)
: m_identity(v2::extractIdentityFromKeyName(keyName))
, m_keyName(keyName)
+ , m_pib(std::move(pibImpl))
+ , m_certificates(keyName, m_pib)
, m_isDefaultCertificateLoaded(false)
- , m_certificates(keyName, impl)
- , m_impl(impl)
{
- BOOST_ASSERT(impl != nullptr);
+ BOOST_ASSERT(m_pib != nullptr);
- m_key = m_impl->getKeyBits(m_keyName);
+ m_key = m_pib->getKeyBits(m_keyName);
transform::PublicKey key;
key.loadPkcs8(m_key.buf(), m_key.size());
@@ -89,7 +89,6 @@
KeyImpl::getCertificate(const Name& certName) const
{
BOOST_ASSERT(m_certificates.isConsistent());
-
return m_certificates.get(certName);
}
@@ -97,7 +96,6 @@
KeyImpl::getCertificates() const
{
BOOST_ASSERT(m_certificates.isConsistent());
-
return m_certificates;
}
@@ -107,7 +105,7 @@
BOOST_ASSERT(m_certificates.isConsistent());
m_defaultCertificate = m_certificates.get(certName);
- m_impl->setDefaultCertificateOfKey(m_keyName, certName);
+ m_pib->setDefaultCertificateOfKey(m_keyName, certName);
m_isDefaultCertificateLoaded = true;
return m_defaultCertificate;
}
@@ -125,11 +123,10 @@
BOOST_ASSERT(m_certificates.isConsistent());
if (!m_isDefaultCertificateLoaded) {
- m_defaultCertificate = m_impl->getDefaultCertificateOfKey(m_keyName);
+ m_defaultCertificate = m_pib->getDefaultCertificateOfKey(m_keyName);
m_isDefaultCertificateLoaded = true;
}
-
- BOOST_ASSERT(m_impl->getDefaultCertificateOfKey(m_keyName).wireEncode() == m_defaultCertificate.wireEncode());
+ BOOST_ASSERT(m_pib->getDefaultCertificateOfKey(m_keyName).wireEncode() == m_defaultCertificate.wireEncode());
return m_defaultCertificate;
}
diff --git a/src/security/pib/detail/key-impl.hpp b/src/security/pib/detail/key-impl.hpp
index a7e683f..efc69b2 100644
--- a/src/security/pib/detail/key-impl.hpp
+++ b/src/security/pib/detail/key-impl.hpp
@@ -22,9 +22,8 @@
#ifndef NDN_SECURITY_PIB_DETAIL_KEY_IMPL_HPP
#define NDN_SECURITY_PIB_DETAIL_KEY_IMPL_HPP
-#include "../../../data.hpp"
-#include "../certificate-container.hpp"
#include "../../security-common.hpp"
+#include "../certificate-container.hpp"
namespace ndn {
namespace security {
@@ -53,21 +52,23 @@
* @param keyName The name of the key.
* @param key The public key to add.
* @param keyLen The length of the key.
- * @param impl The Pib backend implementation.
+ * @param pibImpl The Pib backend implementation.
* @throw Pib::Error a key with the same @p keyName already exists.
*/
- KeyImpl(const Name& keyName, const uint8_t* key, size_t keyLen, shared_ptr<PibImpl> impl);
+ KeyImpl(const Name& keyName, const uint8_t* key, size_t keyLen, shared_ptr<PibImpl> pibImpl);
/**
* @brief Create a KeyImpl with @p keyName.
*
* @param keyName The name of the key.
- * @param impl The Pib backend implementation.
+ * @param pibImpl The Pib backend implementation.
* @throw Pib::Error the key does not exist.
*/
- KeyImpl(const Name& keyName, shared_ptr<PibImpl> impl);
+ KeyImpl(const Name& keyName, shared_ptr<PibImpl> pibImpl);
- /// @brief Get the name of the key.
+ /**
+ * @brief Get the name of the key.
+ */
const Name&
getName() const
{
@@ -130,7 +131,9 @@
v2::Certificate
getCertificate(const Name& certName) const;
- /// @brief Get all the certificates for this key.
+ /**
+ * @brief Get all the certificates for this key.
+ */
const CertificateContainer&
getCertificates() const;
@@ -165,12 +168,11 @@
Buffer m_key;
KeyType m_keyType;
- mutable bool m_isDefaultCertificateLoaded;
- mutable v2::Certificate m_defaultCertificate;
+ shared_ptr<PibImpl> m_pib;
CertificateContainer m_certificates;
-
- shared_ptr<PibImpl> m_impl;
+ mutable bool m_isDefaultCertificateLoaded;
+ mutable v2::Certificate m_defaultCertificate;
};
} // namespace detail