Use std::move in more places

Plus various code simplifications

Change-Id: I19805e4a635e4c74afaff68f9d8968475217ec6e
diff --git a/src/data.cpp b/src/data.cpp
index 090b82d..169d99c 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -263,10 +263,10 @@
 }
 
 Data&
-Data::setContent(const ConstBufferPtr& value)
+Data::setContent(ConstBufferPtr value)
 {
   resetWire();
-  m_content = Block(tlv::Content, value);
+  m_content = Block(tlv::Content, std::move(value));
   return *this;
 }
 
diff --git a/src/data.hpp b/src/data.hpp
index d70f509..56f98ed 100644
--- a/src/data.hpp
+++ b/src/data.hpp
@@ -181,7 +181,7 @@
    *  @return a reference to this Data, to allow chaining
    */
   Data&
-  setContent(const ConstBufferPtr& value);
+  setContent(ConstBufferPtr value);
 
   /** @brief Get Signature
    */
diff --git a/src/detail/pending-interest.hpp b/src/detail/pending-interest.hpp
index 2a4da87..a4f643f 100644
--- a/src/detail/pending-interest.hpp
+++ b/src/detail/pending-interest.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -22,6 +22,8 @@
 #ifndef NDN_DETAIL_PENDING_INTEREST_HPP
 #define NDN_DETAIL_PENDING_INTEREST_HPP
 
+#include "../face.hpp"
+
 #include "../data.hpp"
 #include "../interest.hpp"
 #include "../lp/nack.hpp"
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index 1aa9756..fc9a0dc 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -191,14 +191,15 @@
 std::tuple<bool, Block>
 Block::fromBuffer(ConstBufferPtr buffer, size_t offset)
 {
-  const Buffer::const_iterator begin = buffer->begin() + offset;
-  Buffer::const_iterator pos = begin;
+  auto begin = buffer->begin() + offset;
+  auto pos = begin;
 
   uint32_t type = 0;
   bool isOk = tlv::readType(pos, buffer->end(), type);
   if (!isOk) {
     return std::make_tuple(false, Block());
   }
+
   uint64_t length = 0;
   isOk = tlv::readVarNumber(pos, buffer->end(), length);
   if (!isOk) {
@@ -210,7 +211,7 @@
     return std::make_tuple(false, Block());
   }
 
-  return std::make_tuple(true, Block(buffer, type, begin, pos + length, pos, pos + length));
+  return std::make_tuple(true, Block(std::move(buffer), type, begin, pos + length, pos, pos + length));
 }
 
 std::tuple<bool, Block>
diff --git a/src/face.cpp b/src/face.cpp
index cf1e69d..abdd93b 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -322,18 +322,16 @@
     }
 
     if (timeout > time::milliseconds::zero()) {
-      boost::asio::io_service& ioService = m_ioService;
-      unique_ptr<boost::asio::io_service::work>& work = m_impl->m_ioServiceWork;
       m_impl->m_processEventsTimeoutEvent = m_impl->m_scheduler.scheduleEvent(timeout,
-        [&ioService, &work] {
-          ioService.stop();
+        [&io = m_ioService, &work = m_impl->m_ioServiceWork] {
+          io.stop();
           work.reset();
         });
     }
 
     if (keepThread) {
       // work will ensure that m_ioService is running until work object exists
-      m_impl->m_ioServiceWork.reset(new boost::asio::io_service::work(m_ioService));
+      m_impl->m_ioServiceWork = make_unique<boost::asio::io_service::work>(m_ioService);
     }
 
     m_ioService.run();
diff --git a/src/mgmt/nfd/controller.cpp b/src/mgmt/nfd/controller.cpp
index 7ed8005..1af70b7 100644
--- a/src/mgmt/nfd/controller.cpp
+++ b/src/mgmt/nfd/controller.cpp
@@ -22,7 +22,6 @@
 #include "controller.hpp"
 #include "face.hpp"
 #include "security/v2/key-chain.hpp"
-#include "security/validator-null.hpp"
 #include "util/segment-fetcher.hpp"
 
 #include <boost/lexical_cast.hpp>
@@ -49,28 +48,25 @@
 void
 Controller::startCommand(const shared_ptr<ControlCommand>& command,
                          const ControlParameters& parameters,
-                         const CommandSucceedCallback& onSuccess1,
-                         const CommandFailCallback& onFailure1,
+                         const CommandSucceedCallback& onSuccess,
+                         const CommandFailCallback& onFailure,
                          const CommandOptions& options)
 {
-  const CommandSucceedCallback& onSuccess = onSuccess1 ?
-    onSuccess1 : [] (const ControlParameters&) {};
-  const CommandFailCallback& onFailure = onFailure1 ?
-    onFailure1 : [] (const ControlResponse&) {};
-
   Name requestName = command->getRequestName(options.getPrefix(), parameters);
   Interest interest = m_signer.makeCommandInterest(requestName, options.getSigningInfo());
   interest.setInterestLifetime(options.getTimeout());
 
   m_face.expressInterest(interest,
     [=] (const Interest&, const Data& data) {
-      this->processCommandResponse(data, command, onSuccess, onFailure);
+      processCommandResponse(data, command, onSuccess, onFailure);
     },
     [=] (const Interest&, const lp::Nack&) {
-      onFailure(ControlResponse(Controller::ERROR_NACK, "network Nack received"));
+      if (onFailure)
+        onFailure(ControlResponse(Controller::ERROR_NACK, "network Nack received"));
     },
     [=] (const Interest&) {
-      onFailure(ControlResponse(Controller::ERROR_TIMEOUT, "request timed out"));
+      if (onFailure)
+        onFailure(ControlResponse(Controller::ERROR_TIMEOUT, "request timed out"));
     });
 }
 
@@ -82,10 +78,11 @@
 {
   m_validator.validate(data,
     [=] (const Data& data) {
-      this->processValidatedCommandResponse(data, command, onSuccess, onFailure);
+      processValidatedCommandResponse(data, command, onSuccess, onFailure);
     },
-    [=] (const Data& data, const security::v2::ValidationError& error) {
-      onFailure(ControlResponse(ERROR_VALIDATION, boost::lexical_cast<std::string>(error)));
+    [=] (const Data&, const auto& error) {
+      if (onFailure)
+        onFailure(ControlResponse(ERROR_VALIDATION, boost::lexical_cast<std::string>(error)));
     }
   );
 }
@@ -101,13 +98,15 @@
     response.wireDecode(data.getContent().blockFromValue());
   }
   catch (const tlv::Error& e) {
-    onFailure(ControlResponse(ERROR_SERVER, e.what()));
+    if (onFailure)
+      onFailure(ControlResponse(ERROR_SERVER, e.what()));
     return;
   }
 
   uint32_t code = response.getCode();
   if (code >= ERROR_LBOUND) {
-    onFailure(response);
+    if (onFailure)
+      onFailure(response);
     return;
   }
 
@@ -116,7 +115,8 @@
     parameters.wireDecode(response.getBody());
   }
   catch (const tlv::Error& e) {
-    onFailure(ControlResponse(ERROR_SERVER, e.what()));
+    if (onFailure)
+      onFailure(ControlResponse(ERROR_SERVER, e.what()));
     return;
   }
 
@@ -124,11 +124,13 @@
     command->validateResponse(parameters);
   }
   catch (const ControlCommand::ArgumentError& e) {
-    onFailure(ControlResponse(ERROR_SERVER, e.what()));
+    if (onFailure)
+      onFailure(ControlResponse(ERROR_SERVER, e.what()));
     return;
   }
 
-  onSuccess(parameters);
+  if (onSuccess)
+    onSuccess(parameters);
 }
 
 void
@@ -137,21 +139,26 @@
                          const DatasetFailCallback& onFailure,
                          const CommandOptions& options)
 {
-  Interest baseInterest(prefix);
-
   SegmentFetcher::Options fetcherOptions;
   fetcherOptions.maxTimeout = options.getTimeout();
-  auto fetcher = SegmentFetcher::start(m_face, baseInterest, m_validator, fetcherOptions);
-  fetcher->onComplete.connect(processResponse);
-  fetcher->onError.connect([=] (uint32_t code, const std::string& msg) {
+
+  auto fetcher = SegmentFetcher::start(m_face, Interest(prefix), m_validator, fetcherOptions);
+  if (processResponse) {
+    fetcher->onComplete.connect(processResponse);
+  }
+  if (onFailure) {
+    fetcher->onError.connect([=] (uint32_t code, const std::string& msg) {
       processDatasetFetchError(onFailure, code, msg);
     });
+  }
 }
 
 void
 Controller::processDatasetFetchError(const DatasetFailCallback& onFailure,
                                      uint32_t code, std::string msg)
 {
+  BOOST_ASSERT(onFailure);
+
   switch (static_cast<SegmentFetcher::ErrorCode>(code)) {
     // It's intentional to cast as SegmentFetcher::ErrorCode, and to not have a 'default' clause.
     // This forces the switch statement to handle every defined SegmentFetcher::ErrorCode,
diff --git a/src/mgmt/nfd/controller.hpp b/src/mgmt/nfd/controller.hpp
index 8797b39..0553df1 100644
--- a/src/mgmt/nfd/controller.hpp
+++ b/src/mgmt/nfd/controller.hpp
@@ -52,20 +52,21 @@
 public:
   /** \brief a callback on command success
    */
-  typedef function<void(const ControlParameters&)> CommandSucceedCallback;
+  using CommandSucceedCallback = function<void(const ControlParameters&)>;
 
   /** \brief a callback on command failure
    */
-  typedef function<void(const ControlResponse&)> CommandFailCallback;
+  using CommandFailCallback = function<void(const ControlResponse&)>;
 
   /** \brief a callback on dataset retrieval failure
    */
-  typedef function<void(uint32_t code, const std::string& reason)> DatasetFailCallback;
+  using DatasetFailCallback = function<void(uint32_t code, const std::string& reason)>;
 
   /** \brief construct a Controller that uses face for transport,
    *         and uses the passed KeyChain to sign commands
    */
-  Controller(Face& face, KeyChain& keyChain, security::v2::Validator& validator = security::getAcceptAllValidator());
+  Controller(Face& face, KeyChain& keyChain,
+             security::v2::Validator& validator = security::getAcceptAllValidator());
 
   /** \brief start command execution
    */
@@ -76,8 +77,7 @@
         const CommandFailCallback& onFailure,
         const CommandOptions& options = CommandOptions())
   {
-    shared_ptr<ControlCommand> command = make_shared<Command>();
-    this->startCommand(command, parameters, onSuccess, onFailure, options);
+    startCommand(make_shared<Command>(), parameters, onSuccess, onFailure, options);
   }
 
   /** \brief start dataset fetching
@@ -88,7 +88,7 @@
         const DatasetFailCallback& onFailure,
         const CommandOptions& options = CommandOptions())
   {
-    this->fetchDataset(make_shared<Dataset>(), onSuccess, onFailure, options);
+    fetchDataset(make_shared<Dataset>(), onSuccess, onFailure, options);
   }
 
   /** \brief start dataset fetching
@@ -100,7 +100,7 @@
         const DatasetFailCallback& onFailure,
         const CommandOptions& options = CommandOptions())
   {
-    this->fetchDataset(make_shared<Dataset>(param), onSuccess, onFailure, options);
+    fetchDataset(make_shared<Dataset>(param), onSuccess, onFailure, options);
   }
 
 private:
@@ -175,41 +175,40 @@
 };
 
 template<typename Dataset>
-inline void
+void
 Controller::fetchDataset(shared_ptr<Dataset> dataset,
-                         const std::function<void(typename Dataset::ResultType)>& onSuccess1,
-                         const DatasetFailCallback& onFailure1,
+                         const std::function<void(typename Dataset::ResultType)>& onSuccess,
+                         const DatasetFailCallback& onFailure,
                          const CommandOptions& options)
 {
-  const std::function<void(typename Dataset::ResultType)>& onSuccess = onSuccess1 ?
-    onSuccess1 : [] (const typename Dataset::ResultType&) {};
-  const DatasetFailCallback& onFailure = onFailure1 ?
-    onFailure1 : [] (uint32_t, const std::string&) {};
-
   Name prefix = dataset->getDatasetPrefix(options.getPrefix());
-  this->fetchDataset(prefix,
-                     bind(&Controller::processDatasetResponse<Dataset>, this, dataset, onSuccess, onFailure, _1),
-                     onFailure,
-                     options);
+  fetchDataset(prefix,
+    [=, d = std::move(dataset)] (ConstBufferPtr p) {
+      processDatasetResponse(std::move(d), onSuccess, onFailure, std::move(p));
+    },
+    onFailure, options);
 }
 
 template<typename Dataset>
-inline void
+void
 Controller::processDatasetResponse(shared_ptr<Dataset> dataset,
                                    const std::function<void(typename Dataset::ResultType)>& onSuccess,
                                    const DatasetFailCallback& onFailure,
                                    ConstBufferPtr payload)
 {
   typename Dataset::ResultType result;
+
   try {
-    result = dataset->parseResult(payload);
+    result = dataset->parseResult(std::move(payload));
   }
   catch (const tlv::Error& e) {
-    onFailure(ERROR_SERVER, e.what());
+    if (onFailure)
+      onFailure(ERROR_SERVER, e.what());
     return;
   }
 
-  onSuccess(result);
+  if (onSuccess)
+    onSuccess(result);
 }
 
 } // namespace nfd
diff --git a/src/mgmt/nfd/status-dataset.cpp b/src/mgmt/nfd/status-dataset.cpp
index 5b6d66d..88ce648 100644
--- a/src/mgmt/nfd/status-dataset.cpp
+++ b/src/mgmt/nfd/status-dataset.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -85,7 +85,7 @@
 ForwarderGeneralStatusDataset::ResultType
 ForwarderGeneralStatusDataset::parseResult(ConstBufferPtr payload) const
 {
-  return ForwarderStatus(Block(tlv::Content, payload));
+  return ForwarderStatus(Block(tlv::Content, std::move(payload)));
 }
 
 FaceDatasetBase::FaceDatasetBase(const PartialName& datasetName)
@@ -96,7 +96,7 @@
 FaceDatasetBase::ResultType
 FaceDatasetBase::parseResult(ConstBufferPtr payload) const
 {
-  return parseDatasetVector<FaceStatus>(payload);
+  return parseDatasetVector<FaceStatus>(std::move(payload));
 }
 
 FaceDataset::FaceDataset()
@@ -124,7 +124,7 @@
 ChannelDataset::ResultType
 ChannelDataset::parseResult(ConstBufferPtr payload) const
 {
-  return parseDatasetVector<ChannelStatus>(payload);
+  return parseDatasetVector<ChannelStatus>(std::move(payload));
 }
 
 FibDataset::FibDataset()
@@ -135,7 +135,7 @@
 FibDataset::ResultType
 FibDataset::parseResult(ConstBufferPtr payload) const
 {
-  return parseDatasetVector<FibEntry>(payload);
+  return parseDatasetVector<FibEntry>(std::move(payload));
 }
 
 CsInfoDataset::CsInfoDataset()
@@ -146,7 +146,7 @@
 CsInfoDataset::ResultType
 CsInfoDataset::parseResult(ConstBufferPtr payload) const
 {
-  return CsInfo(Block(payload));
+  return CsInfo(Block(std::move(payload)));
 }
 
 StrategyChoiceDataset::StrategyChoiceDataset()
@@ -157,7 +157,7 @@
 StrategyChoiceDataset::ResultType
 StrategyChoiceDataset::parseResult(ConstBufferPtr payload) const
 {
-  return parseDatasetVector<StrategyChoice>(payload);
+  return parseDatasetVector<StrategyChoice>(std::move(payload));
 }
 
 RibDataset::RibDataset()
@@ -168,7 +168,7 @@
 RibDataset::ResultType
 RibDataset::parseResult(ConstBufferPtr payload) const
 {
-  return parseDatasetVector<RibEntry>(payload);
+  return parseDatasetVector<RibEntry>(std::move(payload));
 }
 
 } // namespace nfd
diff --git a/src/name-component.cpp b/src/name-component.cpp
index cb87c8b..7252d29 100644
--- a/src/name-component.cpp
+++ b/src/name-component.cpp
@@ -343,13 +343,13 @@
 }
 
 Component
-Component::fromImplicitSha256Digest(const ConstBufferPtr& digest)
+Component::fromImplicitSha256Digest(ConstBufferPtr digest)
 {
   if (digest->size() != util::Sha256::DIGEST_SIZE)
     BOOST_THROW_EXCEPTION(Error("Cannot create ImplicitSha256DigestComponent (input digest must be " +
                                 to_string(util::Sha256::DIGEST_SIZE) + " octets)"));
 
-  return Block(tlv::ImplicitSha256DigestComponent, digest);
+  return Block(tlv::ImplicitSha256DigestComponent, std::move(digest));
 }
 
 Component
diff --git a/src/name-component.hpp b/src/name-component.hpp
index 47b6b93..cf39e58 100644
--- a/src/name-component.hpp
+++ b/src/name-component.hpp
@@ -458,7 +458,7 @@
    * @brief Create ImplicitSha256DigestComponent component
    */
   static Component
-  fromImplicitSha256Digest(const ConstBufferPtr& digest);
+  fromImplicitSha256Digest(ConstBufferPtr digest);
 
   /**
    * @brief Create ImplicitSha256DigestComponent component
diff --git a/src/name.hpp b/src/name.hpp
index 0936d3f..2fd48a0 100644
--- a/src/name.hpp
+++ b/src/name.hpp
@@ -432,9 +432,9 @@
    *  @return a reference to this name, to allow chaining
    */
   Name&
-  appendImplicitSha256Digest(const ConstBufferPtr& digest)
+  appendImplicitSha256Digest(ConstBufferPtr digest)
   {
-    return append(Component::fromImplicitSha256Digest(digest));
+    return append(Component::fromImplicitSha256Digest(std::move(digest)));
   }
 
   /** @brief Append an ImplicitSha256Digest component
diff --git a/src/security/pib/identity-container.cpp b/src/security/pib/identity-container.cpp
index 7c018ce..0e4749f 100644
--- a/src/security/pib/identity-container.cpp
+++ b/src/security/pib/identity-container.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -81,10 +81,10 @@
 }
 
 IdentityContainer::IdentityContainer(shared_ptr<PibImpl> pibImpl)
-  : m_pibImpl(pibImpl)
+  : m_pibImpl(std::move(pibImpl))
 {
-  BOOST_ASSERT(pibImpl != nullptr);
-  m_identityNames = pibImpl->getIdentities();
+  BOOST_ASSERT(m_pibImpl != nullptr);
+  m_identityNames = m_pibImpl->getIdentities();
 }
 
 IdentityContainer::const_iterator
@@ -116,8 +116,7 @@
 {
   if (m_identityNames.count(identityName) == 0) {
     m_identityNames.insert(identityName);
-    m_identities[identityName] =
-      shared_ptr<detail::IdentityImpl>(new detail::IdentityImpl(identityName, m_pibImpl, true));
+    m_identities[identityName] = make_shared<detail::IdentityImpl>(identityName, m_pibImpl, true);
   }
   return get(identityName);
 }
@@ -140,7 +139,7 @@
     id = it->second;
   }
   else {
-    id = shared_ptr<detail::IdentityImpl>(new detail::IdentityImpl(identityName, m_pibImpl, false));
+    id = make_shared<detail::IdentityImpl>(identityName, m_pibImpl, false);
     m_identities[identityName] = id;
   }
   return Identity(id);
diff --git a/src/security/pib/key-container.cpp b/src/security/pib/key-container.cpp
index 7dc8358..ee47e37 100644
--- a/src/security/pib/key-container.cpp
+++ b/src/security/pib/key-container.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -121,7 +121,7 @@
   }
 
   m_keyNames.insert(keyName);
-  m_keys[keyName] = shared_ptr<detail::KeyImpl>(new detail::KeyImpl(keyName, key, keyLen, m_pib));
+  m_keys[keyName] = make_shared<detail::KeyImpl>(keyName, key, keyLen, m_pib);
 
   return get(keyName);
 }
@@ -154,7 +154,7 @@
     key = it->second;
   }
   else {
-    key = shared_ptr<detail::KeyImpl>(new detail::KeyImpl(keyName, m_pib));
+    key = make_shared<detail::KeyImpl>(keyName, m_pib);
     m_keys[keyName] = key;
   }
 
diff --git a/src/security/pib/pib.cpp b/src/security/pib/pib.cpp
index 68b9add..4fba641 100644
--- a/src/security/pib/pib.cpp
+++ b/src/security/pib/pib.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -34,9 +34,9 @@
   , m_location(location)
   , m_isDefaultIdentityLoaded(false)
   , m_identities(impl)
-  , m_impl(impl)
+  , m_impl(std::move(impl))
 {
-  BOOST_ASSERT(impl != nullptr);
+  BOOST_ASSERT(m_impl != nullptr);
 }
 
 Pib::~Pib() = default;
diff --git a/src/security/pib/pib.hpp b/src/security/pib/pib.hpp
index 947e5a5..27d83da 100644
--- a/src/security/pib/pib.hpp
+++ b/src/security/pib/pib.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -67,7 +67,7 @@
   ~Pib();
 
   /**
-   * @brief return the scheme of the PibLocator
+   * @brief return the scheme of the PIB Locator
    */
   std::string
   getScheme() const
@@ -110,19 +110,21 @@
   Identity
   getIdentity(const Name& identityName) const;
 
-  /// @brief Get all the identities
+  /**
+   * @brief Get all the identities
+   */
   const IdentityContainer&
   getIdentities() const;
 
   /**
    * @brief Get the default identity.
-   * @throw Pib::Error if no default identity.
+   * @throw Pib::Error if no default identity exists.
    */
   const Identity&
   getDefaultIdentity() const;
 
 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // write operations should be private
-  /*
+  /**
    * @brief Create a Pib instance
    *
    * @param scheme The scheme for the Pib
@@ -131,17 +133,8 @@
    */
   Pib(const std::string& scheme, const std::string& location, shared_ptr<PibImpl> impl);
 
-  /*
-   * @brief Create an identity with name @p identityName and return a reference to it.
-   *
-   * If there already exists an identity for the name @p identityName, then it is returned.
-   * If no default identity is set, the newly created identity will be set as the default.
-   *
-   * @param identityName The name for the identity to be added
-   */
-
   /**
-   * @brief Add an @p identity.
+   * @brief Add an identity.
    *
    * If no default identity is set before, the new identity will be set as the default identity
    *
@@ -150,8 +143,8 @@
   Identity
   addIdentity(const Name& identity);
 
-  /*
-   * @brief Remove an @p identity.
+  /**
+   * @brief Remove an identity.
    *
    * If the default identity is being removed, no default identity will be selected.
    */
@@ -159,7 +152,7 @@
   removeIdentity(const Name& identity);
 
   /**
-   * @brief Set an @p identity as the default identity.
+   * @brief Set an identity as the default identity.
    *
    * Create the identity if it does not exist.
    *
diff --git a/src/security/tpm/back-end-file.cpp b/src/security/tpm/back-end-file.cpp
index a560fad..12c1e37 100644
--- a/src/security/tpm/back-end-file.cpp
+++ b/src/security/tpm/back-end-file.cpp
@@ -125,11 +125,11 @@
   setKeyName(*keyHandle, identityName, params);
 
   try {
-    saveKey(keyHandle->getKeyName(), key);
+    saveKey(keyHandle->getKeyName(), *key);
     return keyHandle;
   }
   catch (const std::runtime_error& e) {
-    BOOST_THROW_EXCEPTION(Error("Cannot write key to disk: "s + e.what()));
+    BOOST_THROW_EXCEPTION(Error("Cannot write key to file: "s + e.what()));
   }
 }
 
@@ -137,27 +137,28 @@
 BackEndFile::doDeleteKey(const Name& keyName)
 {
   boost::filesystem::path keyPath(m_impl->toFileName(keyName));
+  if (!boost::filesystem::exists(keyPath))
+    return;
 
-  if (boost::filesystem::exists(keyPath)) {
-    try {
-      boost::filesystem::remove(keyPath);
-    }
-    catch (const boost::filesystem::filesystem_error&) {
-      BOOST_THROW_EXCEPTION(Error("Cannot delete key"));
-    }
+  try {
+    boost::filesystem::remove(keyPath);
+  }
+  catch (const boost::filesystem::filesystem_error& e) {
+    BOOST_THROW_EXCEPTION(Error("Cannot remove key file: "s + e.what()));
   }
 }
 
 ConstBufferPtr
 BackEndFile::doExportKey(const Name& keyName, const char* pw, size_t pwLen)
 {
-  shared_ptr<PrivateKey> key;
+  unique_ptr<PrivateKey> key;
   try {
     key = loadKey(keyName);
   }
-  catch (const PrivateKey::Error&) {
-    BOOST_THROW_EXCEPTION(Error("Cannot export private key"));
+  catch (const PrivateKey::Error& e) {
+    BOOST_THROW_EXCEPTION(Error("Cannot export private key: "s + e.what()));
   }
+
   OBufferStream os;
   key->savePkcs8(os, pw, pwLen);
   return os.buf();
@@ -167,33 +168,33 @@
 BackEndFile::doImportKey(const Name& keyName, const uint8_t* buf, size_t size, const char* pw, size_t pwLen)
 {
   try {
-    auto key = make_shared<PrivateKey>();
-    key->loadPkcs8(buf, size, pw, pwLen);
+    PrivateKey key;
+    key.loadPkcs8(buf, size, pw, pwLen);
     saveKey(keyName, key);
   }
-  catch (const PrivateKey::Error&) {
-    BOOST_THROW_EXCEPTION(Error("Cannot import private key"));
+  catch (const PrivateKey::Error& e) {
+    BOOST_THROW_EXCEPTION(Error("Cannot import private key: "s + e.what()));
   }
 }
 
-shared_ptr<PrivateKey>
+unique_ptr<PrivateKey>
 BackEndFile::loadKey(const Name& keyName) const
 {
-  auto key = make_shared<PrivateKey>();
-  std::fstream is(m_impl->toFileName(keyName).string(), std::ios_base::in);
+  std::ifstream is(m_impl->toFileName(keyName).string());
+  auto key = make_unique<PrivateKey>();
   key->loadPkcs1Base64(is);
   return key;
 }
 
 void
-BackEndFile::saveKey(const Name& keyName, shared_ptr<PrivateKey> key)
+BackEndFile::saveKey(const Name& keyName, const PrivateKey& key)
 {
   std::string fileName = m_impl->toFileName(keyName).string();
-  std::fstream os(fileName, std::ios_base::out);
-  key->savePkcs1Base64(os);
+  std::ofstream os(fileName);
+  key.savePkcs1Base64(os);
 
   // set file permission
-  ::chmod(fileName.c_str(), 0000400);
+  ::chmod(fileName.data(), 0000400);
 }
 
 } // namespace tpm
diff --git a/src/security/tpm/back-end-file.hpp b/src/security/tpm/back-end-file.hpp
index 5609cba..bd2838d 100644
--- a/src/security/tpm/back-end-file.hpp
+++ b/src/security/tpm/back-end-file.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -26,6 +26,7 @@
 
 namespace ndn {
 namespace security {
+
 namespace transform {
 class PrivateKey;
 } // namespace transform
@@ -123,14 +124,14 @@
   /**
    * @brief Load a private key with name @p keyName from the key file directory
    */
-  shared_ptr<transform::PrivateKey>
+  unique_ptr<transform::PrivateKey>
   loadKey(const Name& keyName) const;
 
   /**
    * @brief Save a private key with name @p keyName into the key file directory
    */
   void
-  saveKey(const Name& keyName, shared_ptr<transform::PrivateKey> key);
+  saveKey(const Name& keyName, const transform::PrivateKey& key);
 
 private:
   class Impl;
diff --git a/src/security/tpm/tpm.hpp b/src/security/tpm/tpm.hpp
index 4ce57f2..367a6b9 100644
--- a/src/security/tpm/tpm.hpp
+++ b/src/security/tpm/tpm.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -144,7 +144,7 @@
   unlockTpm(const char* password, size_t passwordLength) const;
 
 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  /*
+  /**
    * @brief Create a new TPM instance with the specified @p location.
    *
    * @param scheme The scheme for the TPM
diff --git a/src/security/v2/trust-anchor-container.cpp b/src/security/v2/trust-anchor-container.cpp
index 80ef5cc..9137d6f 100644
--- a/src/security/v2/trust-anchor-container.cpp
+++ b/src/security/v2/trust-anchor-container.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -85,6 +85,7 @@
   auto cert = m_anchors.lower_bound(keyName);
   if (cert == m_anchors.end() || !keyName.isPrefixOf(cert->getName()))
     return nullptr;
+
   return &*cert;
 }
 
@@ -123,7 +124,7 @@
 TrustAnchorContainer::refresh()
 {
   for (auto it = m_groups.begin(); it != m_groups.end(); ++it) {
-    m_groups.modify(it, [] (shared_ptr<TrustAnchorGroup>& group) { group->refresh(); });
+    m_groups.modify(it, [] (const auto& group) { group->refresh(); });
   }
 }
 
diff --git a/src/tag-host.hpp b/src/tag-host.hpp
index 0d1d39d..0d3b914 100644
--- a/src/tag-host.hpp
+++ b/src/tag-host.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -58,12 +58,11 @@
   removeTag() const;
 
 private:
-  mutable std::map<size_t, shared_ptr<Tag>> m_tags;
+  mutable std::map<int, shared_ptr<Tag>> m_tags;
 };
 
-
 template<typename T>
-inline shared_ptr<T>
+shared_ptr<T>
 TagHost::getTag() const
 {
   static_assert(std::is_base_of<Tag, T>::value, "T must inherit from Tag");
@@ -76,21 +75,21 @@
 }
 
 template<typename T>
-inline void
+void
 TagHost::setTag(shared_ptr<T> tag) const
 {
   static_assert(std::is_base_of<Tag, T>::value, "T must inherit from Tag");
 
   if (tag == nullptr) {
     m_tags.erase(T::getTypeId());
-    return;
   }
-
-  m_tags[T::getTypeId()] = tag;
+  else {
+    m_tags[T::getTypeId()] = std::move(tag);
+  }
 }
 
 template<typename T>
-inline void
+void
 TagHost::removeTag() const
 {
   setTag<T>(nullptr);
diff --git a/src/tag.hpp b/src/tag.hpp
index cd36445..1a2db36 100644
--- a/src/tag.hpp
+++ b/src/tag.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -34,13 +34,13 @@
   ~Tag();
 
   /**
-   * @fn static constexpr int getTypeId()
+   * @fn static constexpr int getTypeId() noexcept
    * @return an integer that uniquely identifies this Tag type
-   * @sa http://redmine.named-data.net/projects/ndn-cxx/wiki/PacketTagTypes
+   * @sa https://redmine.named-data.net/projects/ndn-cxx/wiki/PacketTagTypes
    */
 #ifdef DOXYGEN
   static constexpr int
-  getTypeId()
+  getTypeId() noexcept
   {
     return <type-identifier>;
   }
@@ -59,15 +59,15 @@
 {
 public:
   static constexpr int
-  getTypeId()
+  getTypeId() noexcept
   {
     return TypeId;
   }
 
   /** \brief explicitly convertible from T
    */
-  explicit
-  SimpleTag(const T& value)
+  constexpr explicit
+  SimpleTag(const T& value) noexcept
     : m_value(value)
   {
   }
@@ -82,8 +82,8 @@
 
   /** \return the enclosed value
    */
-  const T&
-  get() const
+  constexpr const T&
+  get() const noexcept
   {
     return m_value;
   }
diff --git a/src/util/dummy-client-face.cpp b/src/util/dummy-client-face.cpp
index 9f9383a..657fc02 100644
--- a/src/util/dummy-client-face.cpp
+++ b/src/util/dummy-client-face.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -95,33 +95,30 @@
 {
 }
 
-DummyClientFace::DummyClientFace(const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
+DummyClientFace::DummyClientFace(const Options& options)
   : Face(make_shared<DummyClientFace::Transport>())
-  , m_internalKeyChain(new KeyChain)
+  , m_internalKeyChain(make_unique<KeyChain>())
   , m_keyChain(*m_internalKeyChain)
 {
   this->construct(options);
 }
 
-DummyClientFace::DummyClientFace(KeyChain& keyChain,
-                                 const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
+DummyClientFace::DummyClientFace(KeyChain& keyChain, const Options& options)
   : Face(make_shared<DummyClientFace::Transport>(), keyChain)
   , m_keyChain(keyChain)
 {
   this->construct(options);
 }
 
-DummyClientFace::DummyClientFace(boost::asio::io_service& ioService,
-                                 const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
+DummyClientFace::DummyClientFace(boost::asio::io_service& ioService, const Options& options)
   : Face(make_shared<DummyClientFace::Transport>(), ioService)
-  , m_internalKeyChain(new KeyChain)
+  , m_internalKeyChain(make_unique<KeyChain>())
   , m_keyChain(*m_internalKeyChain)
 {
   this->construct(options);
 }
 
-DummyClientFace::DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain,
-                                 const Options& options/* = DummyClientFace::DEFAULT_OPTIONS*/)
+DummyClientFace::DummyClientFace(boost::asio::io_service& ioService, KeyChain& keyChain, const Options& options)
   : Face(make_shared<DummyClientFace::Transport>(), ioService, keyChain)
   , m_keyChain(keyChain)
 {