src: Improving consistency and correcting code style

As of this commit, all data structures can be directly constructed from
wire format.

This commit excludes full correction of code style in security/ and
tools/ndnsec*, which will be part of a different commit.

Change-Id: I121ac1f81948bc7468990df52cdefeb2988d91a1
Refs: #1403
diff --git a/src/data.hpp b/src/data.hpp
index 4d84933..ee84615 100644
--- a/src/data.hpp
+++ b/src/data.hpp
@@ -241,7 +241,7 @@
 inline size_t
 Data::wireEncode(EncodingImpl<T>& block, bool unsignedPortion/* = false*/) const
 {
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   // Data ::= DATA-TLV TLV-LENGTH
   //            Name
@@ -259,27 +259,27 @@
   if (!unsignedPortion)
     {
       // SignatureValue
-      total_len += prependBlock(block, m_signature.getValue());
+      totalLength += prependBlock(block, m_signature.getValue());
     }
 
   // SignatureInfo
-  total_len += prependBlock(block, m_signature.getInfo());
+  totalLength += prependBlock(block, m_signature.getInfo());
 
   // Content
-  total_len += prependBlock(block, getContent());
+  totalLength += prependBlock(block, getContent());
 
   // MetaInfo
-  total_len += getMetaInfo().wireEncode(block);
+  totalLength += getMetaInfo().wireEncode(block);
 
   // Name
-  total_len += getName().wireEncode(block);
+  totalLength += getName().wireEncode(block);
 
   if (!unsignedPortion)
     {
-      total_len += block.prependVarNumber (total_len);
-      total_len += block.prependVarNumber (Tlv::Data);
+      totalLength += block.prependVarNumber (totalLength);
+      totalLength += block.prependVarNumber (Tlv::Data);
     }
-  return total_len;
+  return totalLength;
 }
 
 inline const Block&
diff --git a/src/detail/pending-interest.hpp b/src/detail/pending-interest.hpp
index 4cfc48a..c481acc 100644
--- a/src/detail/pending-interest.hpp
+++ b/src/detail/pending-interest.hpp
@@ -20,62 +20,64 @@
   typedef function<void(const Interest&)> OnTimeout;
 
   /**
-   * Create a new PitEntry and set the timeoutTime_ based on the current time and the interest lifetime.
-   * @param interest A shared_ptr for the interest.
+   * @brief Create a new PitEntry and set the timeout based on the current time and
+   *        the interest lifetime.
+   *
+   * @param interest A shared_ptr for the interest
    * @param onData A function object to call when a matching data packet is received.
-   * @param onTimeout A function object to call if the interest times out.  If onTimeout is an empty OnTimeout(), this does not use it.
+   * @param onTimeout A function object to call if the interest times out.
+   *                  If onTimeout is an empty OnTimeout(), this does not use it.
    */
-  PendingInterest(const shared_ptr<const Interest>& interest, const OnData& onData, 
+  PendingInterest(const shared_ptr<const Interest>& interest, const OnData& onData,
                   const OnTimeout& onTimeout)
-    : interest_(interest),
-      onData_(onData), onTimeout_(onTimeout)
+    : interest_(interest)
+    , onData_(onData)
+    , m_onTimeout(onTimeout)
   {
     if (interest_->getInterestLifetime() >= time::milliseconds::zero())
-      timeout_ = time::steady_clock::now() + interest_->getInterestLifetime();
+      m_timeout = time::steady_clock::now() + interest_->getInterestLifetime();
     else
-      timeout_ = time::steady_clock::now() + DEFAULT_INTEREST_LIFETIME;
+      m_timeout = time::steady_clock::now() + DEFAULT_INTEREST_LIFETIME;
   }
-    
-  const shared_ptr<const Interest>& 
+
+  const shared_ptr<const Interest>&
   getInterest()
   {
     return interest_;
   }
-    
-  const OnData& 
+
+  const OnData&
   getOnData()
   {
     return onData_;
   }
-    
+
   /**
    * Check if this interest is timed out.
    * @return true if this interest timed out, otherwise false.
    */
-  bool 
+  bool
   isTimedOut(const time::steady_clock::TimePoint& now)
   {
-    return now >= timeout_;
+    return now >= m_timeout;
   }
 
   /**
-   * Call onTimeout_ (if defined).  This ignores exceptions from the onTimeout_.
+   * Call m_onTimeout (if defined).  This ignores exceptions from the m_onTimeout.
    */
-  void 
+  void
   callTimeout()
   {
-    if (onTimeout_) {
-      onTimeout_(*interest_);
+    if (m_onTimeout) {
+      m_onTimeout(*interest_);
     }
   }
-    
+
 private:
   shared_ptr<const Interest> interest_;
   const OnData onData_;
-  const OnTimeout onTimeout_;
-
-  /** The time when the interest times out in time::milliseconds according to getNowMilliseconds, or -1 for no timeout. */
-  time::steady_clock::TimePoint timeout_;
+  const OnTimeout m_onTimeout;
+  time::steady_clock::TimePoint m_timeout;
 };
 
 
@@ -86,18 +88,18 @@
  */
 struct MatchPendingInterestId
 {
-  MatchPendingInterestId(const PendingInterestId *pendingInterestId)
-    : id_(pendingInterestId)
+  MatchPendingInterestId(const PendingInterestId* pendingInterestId)
+    : m_id(pendingInterestId)
   {
   }
 
   bool
-  operator()(const shared_ptr<const PendingInterest> &pendingInterest) const
+  operator()(const shared_ptr<const PendingInterest>& pendingInterest) const
   {
-    return (reinterpret_cast<const PendingInterestId *>(pendingInterest.get()) == id_);
+    return (reinterpret_cast<const PendingInterestId*>(pendingInterest.get()) == m_id);
   }
 private:
-  const PendingInterestId *id_;
+  const PendingInterestId* m_id;
 };
 
 
diff --git a/src/detail/registered-prefix.hpp b/src/detail/registered-prefix.hpp
index 02a0ed7..36a55fa 100644
--- a/src/detail/registered-prefix.hpp
+++ b/src/detail/registered-prefix.hpp
@@ -13,10 +13,10 @@
 
 namespace ndn {
 
-class RegisteredPrefix {
+class RegisteredPrefix
+{
 public:
-  typedef function<void
-  (const Name&, const Interest&)> OnInterest;
+  typedef function<void (const Name&, const Interest&)> OnInterest;
 
   /**
    * Create a new PrefixEntry.
@@ -24,26 +24,26 @@
    * @param onInterest A function object to call when a matching data packet is received.
    */
   RegisteredPrefix(const Name& prefix, const OnInterest& onInterest)
-    : prefix_(new Name(prefix))
-    , onInterest_(onInterest)
+    : m_prefix(new Name(prefix))
+    , m_onInterest(onInterest)
   {
   }
-    
-  const Name& 
+
+  const Name&
   getPrefix() const
   {
-    return *prefix_;
+    return* m_prefix;
   }
-    
-  const OnInterest& 
+
+  const OnInterest&
   getOnInterest() const
   {
-    return onInterest_;
+    return m_onInterest;
   }
-    
+
 private:
-  shared_ptr<Name> prefix_;
-  const OnInterest onInterest_;
+  shared_ptr<Name> m_prefix;
+  const OnInterest m_onInterest;
 };
 
 
@@ -54,18 +54,18 @@
  */
 struct MatchRegisteredPrefixId
 {
-  MatchRegisteredPrefixId(const RegisteredPrefixId *registeredPrefixId)
-    : id_(registeredPrefixId)
+  MatchRegisteredPrefixId(const RegisteredPrefixId* registeredPrefixId)
+    : m_id(registeredPrefixId)
   {
   }
 
   bool
-  operator()(const shared_ptr<RegisteredPrefix> &registeredPrefix) const
+  operator()(const shared_ptr<RegisteredPrefix>& registeredPrefix) const
   {
-    return (reinterpret_cast<const RegisteredPrefixId *>(registeredPrefix.get()) == id_);
+    return (reinterpret_cast<const RegisteredPrefixId*>(registeredPrefix.get()) == m_id);
   }
 private:
-  const RegisteredPrefixId *id_;
+  const RegisteredPrefixId* m_id;
 };
 
 } // namespace ndn
diff --git a/src/encoding/block-helpers.hpp b/src/encoding/block-helpers.hpp
index c3ae196..e29a20c 100644
--- a/src/encoding/block-helpers.hpp
+++ b/src/encoding/block-helpers.hpp
@@ -25,7 +25,7 @@
 }
 
 inline uint64_t
-readNonNegativeInteger(const Block &block)
+readNonNegativeInteger(const Block& block)
 {
   Buffer::const_iterator begin = block.value_begin();
   return Tlv::readNonNegativeInteger(block.value_size(), begin, block.value_end());
@@ -41,7 +41,7 @@
 }
 
 inline Block
-dataBlock(uint32_t type, const char *data, size_t dataSize)
+dataBlock(uint32_t type, const char* data, size_t dataSize)
 {
   OBufferStream os;
   Tlv::writeVarNumber(os, type);
@@ -52,7 +52,7 @@
 }
 
 inline Block
-dataBlock(uint32_t type, const unsigned char *data, size_t dataSize)
+dataBlock(uint32_t type, const unsigned char* data, size_t dataSize)
 {
   return dataBlock(type, reinterpret_cast<const char*>(data), dataSize);
 }
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index a734c13..9c91aa8 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -110,7 +110,7 @@
   buf[0] = *tmp_begin;
   is.read(buf+1, length-1);
 
-  if(length != static_cast<uint64_t>(is.gcount()) + 1)
+  if (length != static_cast<uint64_t>(is.gcount()) + 1)
     {
       delete [] buf;
       throw Tlv::Error("Not enough data in the buffer to fully parse TLV");
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index eef9b3d..388bac5 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -385,7 +385,7 @@
 
 
 inline void
-Block::push_back(const Block &element)
+Block::push_back(const Block& element)
 {
   resetWire();
   m_subBlocks.push_back(element);
diff --git a/src/encoding/buffer.hpp b/src/encoding/buffer.hpp
index a97edc1..0b9c327 100644
--- a/src/encoding/buffer.hpp
+++ b/src/encoding/buffer.hpp
@@ -50,7 +50,7 @@
    * @param buf const pointer to buffer
    * @param length length of the buffer to copy
    */
-  Buffer(const void *buf, size_t length)
+  Buffer(const void* buf, size_t length)
     : std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(buf),
                            reinterpret_cast<const uint8_t*>(buf) + length)
   {
@@ -69,7 +69,7 @@
     : std::vector<uint8_t>(first, last)
   {
   }
-  
+
   /**
    * @brief Get pointer to the first byte of the buffer
    */
@@ -126,7 +126,7 @@
   get() const
   {
     return reinterpret_cast<const T*>(&front());
-  }  
+  }
 };
 
 /// @cond include_hidden
@@ -138,19 +138,19 @@
 public:
   typedef char char_type;
   typedef boost::iostreams::sink_tag category;
-  
+
   buffer_append_device(Buffer& container)
   : m_container(container)
   {
   }
-  
+
   std::streamsize
   write(const char_type* s, std::streamsize n)
   {
     std::copy(s, s+n, std::back_inserter(m_container));
     return n;
   }
-  
+
 protected:
   Buffer& m_container;
 };
diff --git a/src/encoding/cryptopp/asn_ext.cpp b/src/encoding/cryptopp/asn_ext.cpp
index 7741314..052226a 100644
--- a/src/encoding/cryptopp/asn_ext.cpp
+++ b/src/encoding/cryptopp/asn_ext.cpp
@@ -17,7 +17,8 @@
 namespace ndn {
 
 size_t
-DEREncodeGeneralTime(CryptoPP::BufferedTransformation &bt, const time::system_clock::TimePoint& time)
+DEREncodeGeneralTime(CryptoPP::BufferedTransformation& bt,
+                     const time::system_clock::TimePoint& time)
 {
   std::string str = time::toIsoString(time);
   // For example, 20131226T232254
@@ -32,7 +33,8 @@
 }
 
 void
-BERDecodeTime(CryptoPP::BufferedTransformation &bt, time::system_clock::TimePoint& time)
+BERDecodeTime(CryptoPP::BufferedTransformation& bt,
+              time::system_clock::TimePoint& time)
 {
   byte b;
   if (!bt.Get(b) || (b != GENERALIZED_TIME && b != UTC_TIME))
@@ -48,14 +50,14 @@
 
   std::string str;
   str.assign (time_str.begin(), time_str.end());
-  
+
   if (b == UTC_TIME) {
     if (boost::lexical_cast<int>(str.substr(0,2)) < 50)
       str = "20" + str;
     else
       str = "19" + str;
   }
- 
+
   time = time::fromIsoString(str.substr(0, 8) + "T" + str.substr(8, 6));
 }
 
diff --git a/src/encoding/cryptopp/asn_ext.hpp b/src/encoding/cryptopp/asn_ext.hpp
index 9140ed9..5d726dc 100644
--- a/src/encoding/cryptopp/asn_ext.hpp
+++ b/src/encoding/cryptopp/asn_ext.hpp
@@ -15,17 +15,28 @@
 
 namespace ndn {
 
-namespace Asn {
-struct Error : public std::runtime_error { Error(const std::string& what) : std::runtime_error(what) {} };
-}
+namespace asn {
+
+class Error : public std::runtime_error
+{
+public:
+  explicit
+  Error(const std::string& what)
+    : std::runtime_error(what)
+  {
+  }
+};
+
+} // namespace asn
 
 size_t
-DEREncodeGeneralTime(CryptoPP::BufferedTransformation& bt, const time::system_clock::TimePoint& time);
+DEREncodeGeneralTime(CryptoPP::BufferedTransformation& bt,
+                     const time::system_clock::TimePoint& time);
 
 void
-BERDecodeTime(CryptoPP::BufferedTransformation& bt, time::system_clock::TimePoint& time);
+BERDecodeTime(CryptoPP::BufferedTransformation& bt,
+              time::system_clock::TimePoint& time);
 
 } // namespace ndn
 
 #endif // NDN_ASN_EXT_HPP
-
diff --git a/src/encoding/encoding-buffer.hpp b/src/encoding/encoding-buffer.hpp
index 4251fa9..78b1628 100644
--- a/src/encoding/encoding-buffer.hpp
+++ b/src/encoding/encoding-buffer.hpp
@@ -12,10 +12,6 @@
 
 #include "../common.hpp"
 
-#include <list>
-#include <exception>
-#include <algorithm>
-
 #include "buffer.hpp"
 #include "tlv.hpp"
 #include "block.hpp"
@@ -48,11 +44,11 @@
    * The caller should make sure that that reserveFromBack does not exceed totalReserve,
    * otherwise behavior is undefined.
    */
-  EncodingImpl (size_t totalReserve = 8800,
-                size_t reserveFromBack = 400)
-    : m_buffer (new Buffer (totalReserve))
+  EncodingImpl(size_t totalReserve = 8800,
+               size_t reserveFromBack = 400)
+    : m_buffer(new Buffer(totalReserve))
   {
-    m_begin = m_end = m_buffer->end () - (reserveFromBack < totalReserve ? reserveFromBack : 0);
+    m_begin = m_end = m_buffer->end() - (reserveFromBack < totalReserve ? reserveFromBack : 0);
   }
 
   /**
@@ -66,24 +62,24 @@
    * after sign operation.
    */
   explicit
-  EncodingImpl (const Block& block)
+  EncodingImpl(const Block& block)
     : m_buffer(const_pointer_cast<Buffer>(block.m_buffer))
     , m_begin(m_buffer->begin() + (block.begin() - m_buffer->begin()))
     , m_end(m_buffer->begin()   + (block.end()   - m_buffer->begin()))
   {
   }
-  
-  inline size_t
-  size () const;
 
   inline size_t
-  capacity () const;
+  size() const;
+
+  inline size_t
+  capacity() const;
 
   inline uint8_t*
-  buf ();
+  buf();
 
   inline const uint8_t*
-  buf () const;
+  buf() const;
 
   /**
    * @brief Create Block from the underlying EncodingBuffer
@@ -93,59 +89,59 @@
    *                     length in the Block, otherwise ignored
    */
   inline Block
-  block (bool verifyLength = true) const;
+  block(bool verifyLength = true) const;
 
   inline void
-  resize (size_t sz, bool addInFront);
+  resize(size_t size, bool addInFront);
 
   inline Buffer::iterator
-  begin ();
+  begin();
 
   inline Buffer::iterator
-  end ();
+  end();
 
   inline Buffer::const_iterator
-  begin () const;
+  begin() const;
 
   inline Buffer::const_iterator
-  end () const;
+  end() const;
 
   inline size_t
-  prependByte (uint8_t val);
+  prependByte(uint8_t value);
 
   inline size_t
-  prependByteArray (const uint8_t *arr, size_t len);
+  prependByteArray(const uint8_t* array, size_t length);
 
   inline size_t
-  prependNonNegativeInteger (uint64_t varNumber);
+  prependNonNegativeInteger(uint64_t varNumber);
 
   inline size_t
-  prependVarNumber (uint64_t varNumber);
+  prependVarNumber(uint64_t varNumber);
 
   inline size_t
-  appendByte (uint8_t val);
+  appendByte(uint8_t value);
 
   inline size_t
-  appendByteArray (const uint8_t *arr, size_t len);
+  appendByteArray(const uint8_t* array, size_t length);
 
   inline size_t
-  appendNonNegativeInteger (uint64_t varNumber);
+  appendNonNegativeInteger(uint64_t varNumber);
 
   inline size_t
-  appendVarNumber (uint64_t varNumber);
+  appendVarNumber(uint64_t varNumber);
 
   // inline void
-  // removeByteFromFront ();
+  // removeByteFromFront();
 
   // inline void
-  // removeByteFromEnd ();
+  // removeByteFromEnd();
 
   // inline void
-  // removeVarNumberFromFront (uint64_t varNumber);
+  // removeVarNumberFromFront(uint64_t varNumber);
 
   // inline void
-  // removeVarNumberFromBack (uint64_t varNumber);
-  
+  // removeVarNumberFromBack(uint64_t varNumber);
+
 private:
   BufferPtr m_buffer;
 
@@ -165,34 +161,34 @@
 class EncodingImpl<encoding::Estimator>
 {
 public:
-  EncodingImpl (size_t totalReserve = 8800,
-                size_t reserveFromBack = 400)
+  EncodingImpl(size_t totalReserve = 8800,
+               size_t reserveFromBack = 400)
   {
   }
 
   inline size_t
-  prependByte (uint8_t val);
+  prependByte(uint8_t value);
 
   inline size_t
-  prependByteArray (const uint8_t *arr, size_t len);
+  prependByteArray(const uint8_t* array, size_t length);
 
   inline size_t
-  prependNonNegativeInteger (uint64_t varNumber);
+  prependNonNegativeInteger(uint64_t varNumber);
 
   inline size_t
-  prependVarNumber (uint64_t varNumber);
+  prependVarNumber(uint64_t varNumber);
 
   inline size_t
-  appendByte (uint8_t val);
+  appendByte(uint8_t value);
 
   inline size_t
-  appendByteArray (const uint8_t *arr, size_t len);
+  appendByteArray(const uint8_t* array, size_t length);
 
   inline size_t
-  appendNonNegativeInteger (uint64_t varNumber);
+  appendNonNegativeInteger(uint64_t varNumber);
 
   inline size_t
-  appendVarNumber (uint64_t varNumber);
+  appendVarNumber(uint64_t varNumber);
 };
 
 
@@ -201,31 +197,31 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 inline size_t
-EncodingImpl<encoding::Buffer>::size () const
+EncodingImpl<encoding::Buffer>::size() const
 {
   return m_end - m_begin;
 }
 
 inline size_t
-EncodingImpl<encoding::Buffer>::capacity () const
+EncodingImpl<encoding::Buffer>::capacity() const
 {
-  return m_buffer->size ();
+  return m_buffer->size();
 }
 
 inline uint8_t*
-EncodingImpl<encoding::Buffer>::buf ()
+EncodingImpl<encoding::Buffer>::buf()
 {
   return &(*m_begin);
 }
 
 inline const uint8_t*
-EncodingImpl<encoding::Buffer>::buf () const
+EncodingImpl<encoding::Buffer>::buf() const
 {
   return &(*m_begin);
 }
 
 inline Block
-EncodingImpl<encoding::Buffer>::block (bool verifyLength/* = true*/) const
+EncodingImpl<encoding::Buffer>::block(bool verifyLength/* = true*/) const
 {
   return Block(m_buffer,
                m_begin, m_end,
@@ -233,56 +229,56 @@
 }
 
 inline void
-EncodingImpl<encoding::Buffer>::resize (size_t sz, bool addInFront)
+EncodingImpl<encoding::Buffer>::resize(size_t size, bool addInFront)
 {
   if (addInFront)
     {
-      size_t diff_end = m_buffer->end () - m_end;
-      size_t diff_begin = m_buffer->end () - m_begin;
+      size_t diff_end = m_buffer->end() - m_end;
+      size_t diff_begin = m_buffer->end() - m_begin;
 
-      Buffer* buf = new Buffer (sz);
-      std::copy_backward (m_buffer->begin (), m_buffer->end (), buf->end ());
+      Buffer* buf = new Buffer(size);
+      std::copy_backward(m_buffer->begin(), m_buffer->end(), buf->end());
 
-      m_buffer.reset (buf);
+      m_buffer.reset(buf);
 
-      m_end = m_buffer->end () - diff_end;
-      m_begin = m_buffer->end () - diff_begin;
+      m_end = m_buffer->end() - diff_end;
+      m_begin = m_buffer->end() - diff_begin;
     }
   else
     {
-      size_t diff_end = m_end - m_buffer->begin ();
-      size_t diff_begin = m_begin - m_buffer->begin ();
+      size_t diff_end = m_end - m_buffer->begin();
+      size_t diff_begin = m_begin - m_buffer->begin();
 
-      Buffer* buf = new Buffer (sz);
-      std::copy (m_buffer->begin (), m_buffer->end (), buf->begin ());
+      Buffer* buf = new Buffer(size);
+      std::copy(m_buffer->begin(), m_buffer->end(), buf->begin());
 
-      m_buffer.reset (buf);
+      m_buffer.reset(buf);
 
-      m_end = m_buffer->begin () + diff_end;
-      m_begin = m_buffer->begin () + diff_begin;      
+      m_end = m_buffer->begin() + diff_end;
+      m_begin = m_buffer->begin() + diff_begin;
     }
 }
 
 inline Buffer::iterator
-EncodingImpl<encoding::Buffer>::begin ()
+EncodingImpl<encoding::Buffer>::begin()
 {
   return m_begin;
 }
 
 inline Buffer::iterator
-EncodingImpl<encoding::Buffer>::end ()
+EncodingImpl<encoding::Buffer>::end()
 {
   return m_end;
 }
 
 inline Buffer::const_iterator
-EncodingImpl<encoding::Buffer>::begin () const
+EncodingImpl<encoding::Buffer>::begin() const
 {
   return m_begin;
 }
 
 inline Buffer::const_iterator
-EncodingImpl<encoding::Buffer>::end () const
+EncodingImpl<encoding::Buffer>::end() const
 {
   return m_end;
 }
@@ -293,69 +289,69 @@
 //////////////////////////////////////////////////////////
 
 inline size_t
-EncodingImpl<encoding::Buffer>::prependByte (uint8_t val)
+EncodingImpl<encoding::Buffer>::prependByte(uint8_t value)
 {
-  if (m_begin == m_buffer->begin ())
-    resize (m_buffer->size () * 2, true);
+  if (m_begin == m_buffer->begin())
+    resize(m_buffer->size() * 2, true);
 
   m_begin--;
-  *m_begin = val;
+  *m_begin = value;
   return 1;
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::prependByte (uint8_t val)
+EncodingImpl<encoding::Estimator>::prependByte(uint8_t value)
 {
   return 1;
 }
 
 inline size_t
-EncodingImpl<encoding::Buffer>::prependByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Buffer>::prependByteArray(const uint8_t* array, size_t length)
 {
-  if ((m_buffer->begin () + len) > m_begin)
-    resize (m_buffer->size () * 2 + len, true);
+  if ((m_buffer->begin() + length) > m_begin)
+    resize(m_buffer->size() * 2 + length, true);
 
-  m_begin -= len;
-  std::copy (arr, arr + len, m_begin);
-  return len;
+  m_begin -= length;
+  std::copy(array, array + length, m_begin);
+  return length;
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::prependByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Estimator>::prependByteArray(const uint8_t* array, size_t length)
 {
-  return len;
+  return length;
 }
 
 inline size_t
-EncodingImpl<encoding::Buffer>::prependNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::prependNonNegativeInteger(uint64_t varNumber)
 {
   if (varNumber <= std::numeric_limits<uint8_t>::max()) {
-    return prependByte (static_cast<uint8_t> (varNumber));
+    return prependByte(static_cast<uint8_t>(varNumber));
   }
-  else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
-    uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
-    return prependByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
+  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+    uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+    return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
   }
-  else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
-    uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
-    return prependByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
+  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+    uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+    return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
   }
   else {
-    uint64_t value = htobe64 (varNumber);
-    return prependByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
+    uint64_t value = htobe64(varNumber);
+    return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
   }
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::prependNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::prependNonNegativeInteger(uint64_t varNumber)
 {
   if (varNumber <= std::numeric_limits<uint8_t>::max()) {
     return 1;
   }
-  else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
+  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
     return 2;
   }
-  else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
+  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
     return 4;
   }
   else {
@@ -364,42 +360,42 @@
 }
 
 inline size_t
-EncodingImpl<encoding::Buffer>::prependVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::prependVarNumber(uint64_t varNumber)
 {
   if (varNumber < 253) {
-    prependByte (static_cast<uint8_t> (varNumber));
+    prependByte(static_cast<uint8_t>(varNumber));
     return 1;
   }
-  else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
-    uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
-    prependByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
-    prependByte (253);
+  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+    uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+    prependByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
+    prependByte(253);
     return 3;
   }
-  else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
-    uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
-    prependByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
-    prependByte (254);
+  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+    uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+    prependByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
+    prependByte(254);
     return 5;
   }
   else {
-    uint64_t value = htobe64 (varNumber);
-    prependByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
-    prependByte (255);
+    uint64_t value = htobe64(varNumber);
+    prependByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
+    prependByte(255);
     return 9;
   }
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::prependVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::prependVarNumber(uint64_t varNumber)
 {
   if (varNumber < 253) {
     return 1;
   }
-  else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
+  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
     return 3;
   }
-  else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
+  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
     return 5;
   }
   else {
@@ -412,94 +408,94 @@
 /////////////////////////////////////////////////////////
 
 inline size_t
-EncodingImpl<encoding::Buffer>::appendByte (uint8_t val)
+EncodingImpl<encoding::Buffer>::appendByte(uint8_t value)
 {
-  if (m_end == m_buffer->end ())
-    resize (m_buffer->size () * 2, false);
+  if (m_end == m_buffer->end())
+    resize(m_buffer->size() * 2, false);
 
-  *m_end = val;
+  *m_end = value;
   m_end++;
   return 1;
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::appendByte (uint8_t val)
+EncodingImpl<encoding::Estimator>::appendByte(uint8_t value)
 {
   return 1;
 }
 
 inline size_t
-EncodingImpl<encoding::Buffer>::appendByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Buffer>::appendByteArray(const uint8_t* array, size_t length)
 {
-  if ((m_end + len) > m_buffer->end ())
-    resize (m_buffer->size () * 2 + len, false);
+  if ((m_end + length) > m_buffer->end())
+    resize(m_buffer->size() * 2 + length, false);
 
-  std::copy (arr, arr + len, m_end);
-  m_end += len;
-  return len;
+  std::copy(array, array + length, m_end);
+  m_end += length;
+  return length;
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::appendByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Estimator>::appendByteArray(const uint8_t* array, size_t length)
 {
-  return prependByteArray(arr, len);
+  return prependByteArray(array, length);
 }
 
 inline size_t
-EncodingImpl<encoding::Buffer>::appendNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::appendNonNegativeInteger(uint64_t varNumber)
 {
-  if (varNumber <= std::numeric_limits<uint8_t>::max ()) {
-    return appendByte (static_cast<uint8_t> (varNumber));
+  if (varNumber <= std::numeric_limits<uint8_t>::max()) {
+    return appendByte(static_cast<uint8_t>(varNumber));
   }
-  else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
-    uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
-    return appendByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
+  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+    uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+    return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
   }
-  else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
-    uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
-    return appendByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
+  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+    uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+    return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
   }
   else {
-    uint64_t value = htobe64 (varNumber);
-    return appendByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
+    uint64_t value = htobe64(varNumber);
+    return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
   }
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::appendNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::appendNonNegativeInteger(uint64_t varNumber)
 {
   return prependNonNegativeInteger(varNumber);
 }
 
 inline size_t
-EncodingImpl<encoding::Buffer>::appendVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::appendVarNumber(uint64_t varNumber)
 {
   if (varNumber < 253) {
-    appendByte (static_cast<uint8_t> (varNumber));
+    appendByte(static_cast<uint8_t>(varNumber));
     return 1;
   }
-  else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
-    appendByte (253);
-    uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
-    appendByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
+  else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+    appendByte(253);
+    uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+    appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
     return 3;
   }
-  else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
-    appendByte (254);
-    uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
-    appendByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
+  else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+    appendByte(254);
+    uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+    appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
     return 5;
   }
   else {
-    appendByte (255);
-    uint64_t value = htobe64 (varNumber);
-    appendByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
+    appendByte(255);
+    uint64_t value = htobe64(varNumber);
+    appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
     return 9;
   }
 }
 
 inline size_t
-EncodingImpl<encoding::Estimator>::appendVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::appendVarNumber(uint64_t varNumber)
 {
   return prependVarNumber(varNumber);
 }
@@ -508,56 +504,57 @@
 
 template<bool P>
 inline size_t
-prependNonNegativeIntegerBlock(EncodingImpl<P>& blk, uint32_t type, uint64_t number)
+prependNonNegativeIntegerBlock(EncodingImpl<P>& encoder, uint32_t type, uint64_t number)
 {
-  size_t var_len = blk.prependNonNegativeInteger(number);
-  size_t total_len = var_len;
-  total_len += blk.prependVarNumber(var_len);
-  total_len += blk.prependVarNumber(type);
+  size_t valueLength = encoder.prependNonNegativeInteger(number);
+  size_t totalLength = valueLength;
+  totalLength += encoder.prependVarNumber(valueLength);
+  totalLength += encoder.prependVarNumber(type);
 
-  return total_len;
+  return totalLength;
 }
 
 template<bool P>
 inline size_t
-prependByteArrayBlock(EncodingImpl<P>& blk, uint32_t type, const uint8_t* array, size_t arraySize)
+prependByteArrayBlock(EncodingImpl<P>& encoder, uint32_t type,
+                      const uint8_t* array, size_t arraySize)
 {
-  size_t var_len = blk.prependByteArray(array, arraySize);
-  size_t total_len = var_len;
-  total_len += blk.prependVarNumber(var_len);
-  total_len += blk.prependVarNumber(type);
+  size_t valueLength = encoder.prependByteArray(array, arraySize);
+  size_t totalLength = valueLength;
+  totalLength += encoder.prependVarNumber(valueLength);
+  totalLength += encoder.prependVarNumber(type);
 
-  return total_len;
+  return totalLength;
 }
 
 template<bool P>
 inline size_t
-prependBooleanBlock(EncodingImpl<P>& blk, uint32_t type)
+prependBooleanBlock(EncodingImpl<P>& encoder, uint32_t type)
 {
-  size_t total_len = blk.prependVarNumber(0);
-  total_len += blk.prependVarNumber(type);
+  size_t totalLength = encoder.prependVarNumber(0);
+  totalLength += encoder.prependVarNumber(type);
 
-  return total_len;
+  return totalLength;
 }
 
 
 template<bool P, class U>
 inline size_t
-prependNestedBlock(EncodingImpl<P>& blk, uint32_t type, const U& nestedBlock)
+prependNestedBlock(EncodingImpl<P>& encoder, uint32_t type, const U& nestedBlock)
 {
-  size_t var_len = nestedBlock.wireEncode(blk);
-  size_t total_len = var_len;
-  total_len += blk.prependVarNumber(var_len);
-  total_len += blk.prependVarNumber(type);
+  size_t valueLength = nestedBlock.wireEncode(encoder);
+  size_t totalLength = valueLength;
+  totalLength += encoder.prependVarNumber(valueLength);
+  totalLength += encoder.prependVarNumber(type);
 
-  return total_len;
+  return totalLength;
 }
 
 template<bool P>
 inline size_t
-prependBlock(EncodingImpl<P>& blk, const Block& block)
+prependBlock(EncodingImpl<P>& encoder, const Block& block)
 {
-  return blk.prependByteArray(block.wire(), block.size());
+  return encoder.prependByteArray(block.wire(), block.size());
 }
 
 
diff --git a/src/encoding/oid.cpp b/src/encoding/oid.cpp
index 5f36473..cff98cd 100644
--- a/src/encoding/oid.cpp
+++ b/src/encoding/oid.cpp
@@ -16,7 +16,7 @@
 
 namespace ndn {
 
-OID::OID(const char *oid)
+OID::OID(const char* oid)
 {
   construct(oid);
 }
@@ -27,21 +27,21 @@
 }
 
 void
-OID::construct(const std::string &oid)
+OID::construct(const std::string& oid)
 {
   string str = oid + ".";
 
   size_t pos = 0;
   size_t ppos = 0;
 
-  while(string::npos != pos){
+  while (string::npos != pos) {
     ppos = pos;
 
     pos = str.find_first_of('.', pos);
-    if(pos == string::npos)
+    if (pos == string::npos)
       break;
 
-    oid_.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
+    m_oid.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
 
     pos++;
   }
@@ -50,54 +50,53 @@
 string OID::toString() const
 {
   ostringstream convert;
-  
-  vector<int>::const_iterator it = oid_.begin();
-  for(; it < oid_.end(); it++){
-    if(it != oid_.begin())
+
+  for (vector<int>::const_iterator it = m_oid.begin(); it != m_oid.end(); ++it) {
+    if (it != m_oid.begin())
       convert << ".";
     convert << *it;
   }
-  
+
   return convert.str();
 }
 
 bool
 OID::equal(const OID& oid) const
 {
-  vector<int>::const_iterator i = oid_.begin();
-  vector<int>::const_iterator j = oid.oid_.begin();
-    
-  for (; i != oid_.end () && j != oid.oid_.end (); i++, j++) {
-    if(*i != *j)
+  vector<int>::const_iterator i = m_oid.begin();
+  vector<int>::const_iterator j = oid.m_oid.begin();
+
+  for (; i != m_oid.end () && j != oid.m_oid.end (); i++, j++) {
+    if (*i != *j)
       return false;
   }
 
-  if (i == oid_.end () && j == oid.oid_.end ())
+  if (i == m_oid.end () && j == oid.m_oid.end ())
     return true;
   else
     return false;
 }
 
 inline void
-EncodeValue(BufferedTransformation &bt, word32 v)
+EncodeValue(BufferedTransformation& bt, word32 v)
 {
-  for (unsigned int i=RoundUpToMultipleOf(STDMAX(7U,BitPrecision(v)), 7U)-7; i != 0; i-=7)
+  for (unsigned int i = RoundUpToMultipleOf(STDMAX(7U,BitPrecision(v)), 7U) - 7; i != 0; i -= 7)
     bt.Put((byte)(0x80 | ((v >> i) & 0x7f)));
   bt.Put((byte)(v & 0x7f));
 }
 
 inline size_t
-DecodeValue(BufferedTransformation &bt, word32 &v)
+DecodeValue(BufferedTransformation& bt, word32& v)
 {
-  byte b;
-  size_t i=0;
   v = 0;
+  size_t i = 0;
   while (true)
     {
+      byte b;
       if (!bt.Get(b))
         BERDecodeError();
       i++;
-      if (v >> (8*sizeof(v)-7))	// v about to overflow
+      if (v >> (8*sizeof(v) - 7)) // v about to overflow
         BERDecodeError();
       v <<= 7;
       v += b & 0x7f;
@@ -107,20 +106,22 @@
 }
 
 void
-OID::encode(CryptoPP::BufferedTransformation &out) const
+OID::encode(CryptoPP::BufferedTransformation& out) const
 {
-  assert(oid_.size() >= 2);
+  BOOST_ASSERT(m_oid.size() >= 2);
+
   ByteQueue temp;
-  temp.Put(byte(oid_[0] * 40 + oid_[1]));
-  for (size_t i=2; i<oid_.size(); i++)
-    EncodeValue(temp, oid_[i]);
+  temp.Put(byte(m_oid[0] * 40 + m_oid[1]));
+  for (size_t i = 2; i < m_oid.size(); i++)
+    EncodeValue(temp, m_oid[i]);
+
   out.Put(OBJECT_IDENTIFIER);
   DERLengthEncode(out, temp.CurrentSize());
   temp.TransferTo(out);
 }
 
 void
-OID::decode(CryptoPP::BufferedTransformation &in)
+OID::decode(CryptoPP::BufferedTransformation& in)
 {
   byte b;
   if (!in.Get(b) || b != OBJECT_IDENTIFIER)
@@ -132,11 +133,11 @@
 
   if (!in.Get(b))
     BERDecodeError();
-	
+
   length--;
-  oid_.resize(2);
-  oid_[0] = b / 40;
-  oid_[1] = b % 40;
+  m_oid.resize(2);
+  m_oid[0] = b / 40;
+  m_oid[1] = b % 40;
 
   while (length > 0)
     {
@@ -144,9 +145,9 @@
       size_t valueLen = DecodeValue(in, v);
       if (valueLen > length)
         BERDecodeError();
-      oid_.push_back(v);
+      m_oid.push_back(v);
       length -= valueLen;
     }
 }
 
-}
+} // namespace ndn
diff --git a/src/encoding/oid.hpp b/src/encoding/oid.hpp
index 308da8e..e7b1beb 100644
--- a/src/encoding/oid.hpp
+++ b/src/encoding/oid.hpp
@@ -17,31 +17,31 @@
 
 class OID {
 public:
-  OID () 
+  OID ()
   {
   }
-    
-  OID(const char *oid);
+
+  OID(const char* oid);
 
   OID(const std::string& oid);
 
   OID(const std::vector<int>& oid)
-  : oid_(oid)
+    : m_oid(oid)
   {
   }
 
-  const std::vector<int> &
+  const std::vector<int>&
   getIntegerList() const
   {
-    return oid_;
+    return m_oid;
   }
 
   void
   setIntegerList(const std::vector<int>& value){
-    oid_ = value;
+    m_oid = value;
   }
 
-  std::string 
+  std::string
   toString() const;
 
   bool operator == (const OID& oid) const
@@ -55,21 +55,21 @@
   }
 
   void
-  encode(CryptoPP::BufferedTransformation &out) const;
+  encode(CryptoPP::BufferedTransformation& out) const;
 
   void
-  decode(CryptoPP::BufferedTransformation &in);
+  decode(CryptoPP::BufferedTransformation& in);
 
 
 private:
   void
-  construct(const std::string &value);
-  
+  construct(const std::string& value);
+
   bool
   equal(const OID& oid) const;
 
 private:
-  std::vector<int> oid_;
+  std::vector<int> m_oid;
 };
 
 }
diff --git a/src/exclude.hpp b/src/exclude.hpp
index c38e9f9..9fb5c3a 100644
--- a/src/exclude.hpp
+++ b/src/exclude.hpp
@@ -44,6 +44,15 @@
   Exclude();
 
   /**
+   * @brief Create from wire encoding
+   */
+  explicit
+  Exclude(const Block& wire)
+  {
+    wireDecode(wire);
+  }
+
+  /**
    * @brief Fast encoding or block size estimation
    */
   template<bool T>
@@ -245,7 +254,7 @@
 inline size_t
 Exclude::wireEncode(EncodingImpl<T>& block) const
 {
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+
   // Any     ::= ANY-TYPE TLV-LENGTH(=0)
@@ -254,17 +263,17 @@
     {
       if (i->second)
         {
-          total_len += prependBooleanBlock(block, Tlv::Any);
+          totalLength += prependBooleanBlock(block, Tlv::Any);
         }
       if (!i->first.empty())
         {
-          total_len += i->first.wireEncode(block);
+          totalLength += i->first.wireEncode(block);
         }
     }
 
-  total_len += block.prependVarNumber(total_len);
-  total_len += block.prependVarNumber(Tlv::Exclude);
-  return total_len;
+  totalLength += block.prependVarNumber(totalLength);
+  totalLength += block.prependVarNumber(Tlv::Exclude);
+  return totalLength;
 }
 
 inline const Block&
diff --git a/src/face.cpp b/src/face.cpp
index 04e2570..3e5a4b1 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -271,12 +271,12 @@
       m_ioService->run();
       m_ioService->reset(); // so it is possible to run processEvents again (if necessary)
     }
-  catch(Face::ProcessEventsTimeout&)
+  catch (Face::ProcessEventsTimeout&)
     {
       // break
       m_ioService->reset();
     }
-  catch(const std::exception&)
+  catch (const std::exception&)
     {
       m_ioService->reset();
       m_pendingInterestTable.clear();
diff --git a/src/face.hpp b/src/face.hpp
index d168e73..2920a7d 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -54,7 +54,15 @@
 class Face : noncopyable
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string& what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
   /**
    * @brief Create a new Face for communication with an NDN Forwarder using the default UnixTransport.
@@ -110,7 +118,7 @@
    */
   void
   setController(const shared_ptr<Controller>& controller);
-  
+
   /**
    * @brief Express Interest
    *
@@ -140,7 +148,7 @@
   expressInterest(const Name& name,
                   const Interest& tmpl,
                   const OnData& onData, const OnTimeout& onTimeout = OnTimeout());
-  
+
   /**
    * Remove the pending interest entry with the pendingInterestId from the pending interest table.
    * This does not affect another pending interest with a different pendingInterestId, even it if has the same interest name.
@@ -149,7 +157,7 @@
    */
   void
   removePendingInterest(const PendingInterestId* pendingInterestId);
-  
+
   /**
    * Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
    * @param prefix A reference to a Name for the prefix to register.  This copies the Name.
@@ -166,7 +174,7 @@
                     const OnSetInterestFilterFailed& onSetInterestFilterFailed);
 
   /**
-   * Remove the registered prefix entry with the registeredPrefixId from the pending interest table.  
+   * Remove the registered prefix entry with the registeredPrefixId from the pending interest table.
    * This does not affect another registered prefix with a different registeredPrefixId, even it if has the same prefix name.
    * If there is no entry with the registeredPrefixId, do nothing.
    * @param registeredPrefixId The ID returned from registerPrefix.
@@ -182,7 +190,7 @@
    */
   void
   put(const Data& data);
- 
+
   /**
    * Process any data to receive or call timeout callbacks.
    *
@@ -199,14 +207,14 @@
    * @throw This may throw an exception for reading data or in the callback for processing the data.  If you
    * call this from an main event loop, you may want to catch and log/disregard all exceptions.
    */
-  void 
+  void
   processEvents(const time::milliseconds& timeout = time::milliseconds::zero(),
                 bool keepThread = false);
 
-  void 
+  void
   shutdown();
 
-  shared_ptr<boost::asio::io_service> 
+  shared_ptr<boost::asio::io_service>
   ioService() { return m_ioService; }
 
 private:
@@ -226,11 +234,11 @@
 
   bool
   isSupportedNdndProtocol(const std::string& protocol);
-  
+
   struct ProcessEventsTimeout {};
   typedef std::list<shared_ptr<PendingInterest> > PendingInterestTable;
   typedef std::list<shared_ptr<RegisteredPrefix> > RegisteredPrefixTable;
-  
+
   void
   asyncExpressInterest(const shared_ptr<const Interest>& interest,
                        const OnData& onData, const OnTimeout& onTimeout);
@@ -243,13 +251,13 @@
 
   void
   finalizeUnsetInterestFilter(RegisteredPrefixTable::iterator item);
-  
-  void 
+
+  void
   onReceiveElement(const Block& wire);
 
   void
   asyncShutdown();
-  
+
   static void
   fireProcessEventsTimeout(const boost::system::error_code& error);
 
@@ -258,7 +266,7 @@
 
   void
   processInterestFilters(Interest& interest);
-    
+
   void
   checkPitExpire();
 
@@ -268,7 +276,7 @@
   shared_ptr<monotonic_deadline_timer> m_pitTimeoutCheckTimer;
   bool m_pitTimeoutCheckTimerActive;
   shared_ptr<monotonic_deadline_timer> m_processEventsTimeoutTimer;
-  
+
   shared_ptr<Transport> m_transport;
 
   PendingInterestTable m_pendingInterestTable;
diff --git a/src/interest.cpp b/src/interest.cpp
index 314bdca..64dc817 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -11,8 +11,6 @@
 #include "util/random.hpp"
 #include "data.hpp"
 
-using namespace std;
-
 namespace ndn {
 
 const uint32_t&
diff --git a/src/interest.hpp b/src/interest.hpp
index 2e2b8af..3cfacf1 100644
--- a/src/interest.hpp
+++ b/src/interest.hpp
@@ -104,6 +104,9 @@
   {
   }
 
+  /**
+   * @brief Create from wire encoding
+   */
   explicit
   Interest(const Block& wire)
   {
@@ -462,7 +465,7 @@
 inline size_t
 Interest::wireEncode(EncodingImpl<T>& block) const
 {
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   // Interest ::= INTEREST-TYPE TLV-LENGTH
   //                Name
@@ -474,33 +477,35 @@
   // (reverse encoding)
 
   // InterestLifetime
-  if (getInterestLifetime() >= time::milliseconds::zero()
-      && getInterestLifetime() != DEFAULT_INTEREST_LIFETIME)
+  if (getInterestLifetime() >= time::milliseconds::zero() &&
+      getInterestLifetime() != DEFAULT_INTEREST_LIFETIME)
     {
-      total_len += prependNonNegativeIntegerBlock(block, Tlv::InterestLifetime, getInterestLifetime().count());
+      totalLength += prependNonNegativeIntegerBlock(block,
+                                                    Tlv::InterestLifetime,
+                                                    getInterestLifetime().count());
     }
 
   // Scope
   if (getScope() >= 0)
     {
-      total_len += prependNonNegativeIntegerBlock(block, Tlv::Scope, getScope());
+      totalLength += prependNonNegativeIntegerBlock(block, Tlv::Scope, getScope());
     }
 
   // Nonce
-  total_len += prependNonNegativeIntegerBlock(block, Tlv::Nonce, getNonce());
+  totalLength += prependNonNegativeIntegerBlock(block, Tlv::Nonce, getNonce());
 
   // Selectors
   if (!getSelectors().empty())
     {
-      total_len += getSelectors().wireEncode(block);
+      totalLength += getSelectors().wireEncode(block);
     }
 
   // Name
-  total_len += getName().wireEncode(block);
+  totalLength += getName().wireEncode(block);
 
-  total_len += block.prependVarNumber (total_len);
-  total_len += block.prependVarNumber (Tlv::Interest);
-  return total_len;
+  totalLength += block.prependVarNumber (totalLength);
+  totalLength += block.prependVarNumber (Tlv::Interest);
+  return totalLength;
 }
 
 inline const Block&
diff --git a/src/key-locator.hpp b/src/key-locator.hpp
index a139bf7..14a1b5e 100644
--- a/src/key-locator.hpp
+++ b/src/key-locator.hpp
@@ -37,7 +37,19 @@
   {
   }
 
-  KeyLocator(const Name& name);
+  KeyLocator(const Name& name)
+  {
+    setName(name);
+  }
+
+  /**
+   * @brief Create from wire encoding
+   */
+  explicit
+  KeyLocator(const Block& wire)
+  {
+    wireDecode(wire);
+  }
 
   ///////////////////////////////////////////////////////////////////////////////
 
@@ -53,7 +65,7 @@
 
   ///////////////////////////////////////////////////////////////////////////////
 
-   bool
+  bool
   empty() const
   {
     return m_type == KeyLocator_None;
@@ -87,12 +99,6 @@
   mutable Block m_wire;
 };
 
-inline
-KeyLocator::KeyLocator(const Name& name)
-{
-  setName(name);
-}
-
 template<bool T>
 inline size_t
 KeyLocator::wireEncode(EncodingImpl<T>& block) const
@@ -105,21 +111,21 @@
 
   // KeyLocatorDigest ::= KEY-LOCATOR-DIGEST-TYPE TLV-LENGTH BYTE+
 
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   switch (m_type) {
   case KeyLocator_None:
     break;
   case KeyLocator_Name:
-    total_len += m_name.wireEncode(block);
+    totalLength += m_name.wireEncode(block);
     break;
   default:
     throw Error("Unsupported KeyLocator type");
   }
 
-  total_len += block.prependVarNumber(total_len);
-  total_len += block.prependVarNumber(Tlv::KeyLocator);
-  return total_len;
+  totalLength += block.prependVarNumber(totalLength);
+  totalLength += block.prependVarNumber(Tlv::KeyLocator);
+  return totalLength;
 }
 
 inline const Block&
diff --git a/src/management/ndnd-controller.cpp b/src/management/ndnd-controller.cpp
index a283826..32a19cd 100644
--- a/src/management/ndnd-controller.cpp
+++ b/src/management/ndnd-controller.cpp
@@ -197,7 +197,7 @@
 
   Block::element_const_iterator val = content.elements_begin();
 
-  switch(val->type())
+  switch (val->type())
     {
     case tlv::ndnd::FaceInstance:
       {
@@ -243,7 +243,7 @@
 
   Block::element_const_iterator val = content.elements_begin();
 
-  switch(val->type())
+  switch (val->type())
     {
     case tlv::ndnd::ForwardingEntry:
       {
diff --git a/src/management/ndnd-face-instance.hpp b/src/management/ndnd-face-instance.hpp
index 60c07dc..530f10d 100644
--- a/src/management/ndnd-face-instance.hpp
+++ b/src/management/ndnd-face-instance.hpp
@@ -19,12 +19,12 @@
  */
 class FaceInstance {
 public:
-  FaceInstance(const std::string &action,
+  FaceInstance(const std::string& action,
                int64_t     faceId,
                uint32_t    ipProto,
-               const std::string &host,
-               const std::string &port,
-               const std::string &multicastInterface,
+               const std::string& host,
+               const std::string& port,
+               const std::string& multicastInterface,
                uint32_t    multicastTtl,
                const time::milliseconds& freshnessPeriod)
     : action_(action)
@@ -46,6 +46,15 @@
   {
   }
 
+  /**
+   * @brief Create from wire encoding
+   */
+  explicit
+  FaceInstance(const Block& wire)
+  {
+    wireDecode(wire);
+  }
+
   // Action
   const std::string&
   getAction() const { return action_; }
@@ -79,7 +88,7 @@
   getPort() const { return port_; }
 
   void
-  setPort(const std::string &port) { port_ = port; wire_.reset(); }
+  setPort(const std::string& port) { port_ = port; wire_.reset(); }
 
   // MulticastInterface
   const std::string&
@@ -113,7 +122,7 @@
   wireEncode() const;
 
   inline void
-  wireDecode(const Block &wire);
+  wireDecode(const Block& wire);
 
 private:
   std::string action_;
@@ -207,7 +216,7 @@
 }
 
 inline void
-FaceInstance::wireDecode(const Block &wire)
+FaceInstance::wireDecode(const Block& wire)
 {
   action_.clear();
   faceId_ = -1;
@@ -289,7 +298,7 @@
 }
 
 inline std::ostream&
-operator << (std::ostream &os, const FaceInstance &entry)
+operator << (std::ostream& os, const FaceInstance& entry)
 {
   os << "FaceInstance(";
 
diff --git a/src/management/ndnd-forwarding-entry.hpp b/src/management/ndnd-forwarding-entry.hpp
index 03272b1..a084964 100644
--- a/src/management/ndnd-forwarding-entry.hpp
+++ b/src/management/ndnd-forwarding-entry.hpp
@@ -40,6 +40,15 @@
   {
   }
 
+  /**
+   * @brief Create from wire encoding
+   */
+  explicit
+  ForwardingEntry(const Block& wire)
+  {
+    wireDecode(wire);
+  }
+
   const std::string&
   getAction() const { return action_; }
 
@@ -50,7 +59,7 @@
   getPrefix() const { return prefix_; }
 
   void
-  setPrefix(const Name &prefix) { prefix_ = prefix; wire_.reset(); }
+  setPrefix(const Name& prefix) { prefix_ = prefix; wire_.reset(); }
 
   int
   getFaceId() const { return faceId_; }
@@ -74,7 +83,7 @@
   wireEncode() const;
 
   inline void
-  wireDecode(const Block &wire);
+  wireDecode(const Block& wire);
 
 private:
   std::string action_;   /**< empty for none. */
@@ -135,7 +144,7 @@
 }
 
 inline void
-ForwardingEntry::wireDecode(const Block &wire)
+ForwardingEntry::wireDecode(const Block& wire)
 {
   action_.clear();
   prefix_.clear();
@@ -190,7 +199,7 @@
 }
 
 inline std::ostream&
-operator << (std::ostream &os, const ForwardingEntry &entry)
+operator << (std::ostream& os, const ForwardingEntry& entry)
 {
   os << "ForwardingEntry(";
 
diff --git a/src/management/ndnd-forwarding-flags.hpp b/src/management/ndnd-forwarding-flags.hpp
index f238d06..803dabc 100644
--- a/src/management/ndnd-forwarding-flags.hpp
+++ b/src/management/ndnd-forwarding-flags.hpp
@@ -24,7 +24,7 @@
   /**
    * Create a new ForwardingFlags with "active" and "childInherit" set and all other flags cleared.
    */
-  ForwardingFlags() 
+  ForwardingFlags()
     : active_(true)
     , childInherit_(true)
     , advertise_(false)
@@ -37,47 +37,56 @@
   }
 
   /**
+   * @brief Create from wire encoding
+   */
+  explicit
+  ForwardingFlags(const Block& wire)
+  {
+    wireDecode(wire);
+  }
+
+  /**
    * Get the value of the "active" flag.
    * @return true if the flag is set, false if it is cleared.
    */
   bool getActive() const { return active_; }
-  
+
   /**
    * Get the value of the "childInherit" flag.
    * @return true if the flag is set, false if it is cleared.
    */
   bool getChildInherit() const { return childInherit_; }
-  
+
   /**
    * Get the value of the "advertise" flag.
    * @return true if the flag is set, false if it is cleared.
    */
   bool getAdvertise() const { return advertise_; }
-  
+
   /**
    * Get the value of the "last" flag.
    * @return true if the flag is set, false if it is cleared.
    */
   bool getLast() const { return last_; }
-  
+
   /**
    * Get the value of the "capture" flag.
    * @return true if the flag is set, false if it is cleared.
    */
   bool getCapture() const { return capture_; }
-  
+
   /**
    * Get the value of the "local" flag.
    * @return true if the flag is set, false if it is cleared.
    */
   bool getLocal() const { return local_; }
-  
+
   /**
    * Get the value of the "tap" flag.
    * @return true if the flag is set, false if it is cleared.
    */
   bool getTap() const { return tap_; }
-  
+
   /**
    * Get the value of the "captureOk" flag.
    * @return true if the flag is set, false if it is cleared.
@@ -87,57 +96,57 @@
   /**
    * Set the value of the "active" flag
    * @param active true to set the flag, false to clear it.
-   */  
+   */
   void setActive(bool active) { this->active_ = active; wire_.reset(); }
-  
+
   /**
    * Set the value of the "childInherit" flag
    * @param childInherit true to set the flag, false to clear it.
-   */  
+   */
   void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); }
-  
+
   /**
    * Set the value of the "advertise" flag
    * @param advertise true to set the flag, false to clear it.
-   */  
+   */
   void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); }
-  
+
   /**
    * Set the value of the "last" flag
    * @param last true to set the flag, false to clear it.
-   */  
+   */
   void setLast(bool last) { this->last_ = last; wire_.reset(); }
-  
+
   /**
    * Set the value of the "capture" flag
    * @param capture true to set the flag, false to clear it.
-   */  
+   */
   void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); }
-  
+
   /**
    * Set the value of the "local" flag
    * @param local true to set the flag, false to clear it.
-   */  
+   */
   void setLocal(bool local) { this->local_ = local; wire_.reset(); }
-  
+
   /**
    * Set the value of the "tap" flag
    * @param tap true to set the flag, false to clear it.
-   */  
+   */
   void setTap(bool tap) { this->tap_ = tap; wire_.reset(); }
-  
+
   /**
    * Set the value of the "captureOk" flag
    * @param captureOk true to set the flag, false to clear it.
-   */  
+   */
   void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); }
 
   inline const Block&
   wireEncode() const;
 
   inline void
-  wireDecode(const Block &block);
-  
+  wireDecode(const Block& block);
+
 private:
   bool active_;
   bool childInherit_;
@@ -174,19 +183,19 @@
     result |= tlv::ndnd::FORW_TAP;
   if (captureOk_)
     result |= tlv::ndnd::FORW_CAPTURE_OK;
-  
+
   wire_ = nonNegativeIntegerBlock(tlv::ndnd::ForwardingFlags, result);
 
   return wire_;
 }
 
 inline void
-ForwardingFlags::wireDecode(const Block &wire)
+ForwardingFlags::wireDecode(const Block& wire)
 {
   wire_ = wire;
 
   uint32_t flags = readNonNegativeInteger(wire_);
-  
+
   active_       = (flags & tlv::ndnd::FORW_ACTIVE)        ? true : false;
   childInherit_ = (flags & tlv::ndnd::FORW_CHILD_INHERIT) ? true : false;
   advertise_    = (flags & tlv::ndnd::FORW_ADVERTISE)     ? true : false;
@@ -198,7 +207,7 @@
 }
 
 inline std::ostream&
-operator << (std::ostream &os, const ForwardingFlags &flags)
+operator << (std::ostream& os, const ForwardingFlags& flags)
 {
   if (flags.getActive())
     os << "ACTIVE ";
diff --git a/src/management/ndnd-status-response.hpp b/src/management/ndnd-status-response.hpp
index e58de7e..23597b9 100644
--- a/src/management/ndnd-status-response.hpp
+++ b/src/management/ndnd-status-response.hpp
@@ -20,30 +20,39 @@
   {
   }
 
-  StatusResponse(uint32_t code, const std::string &info)
+  StatusResponse(uint32_t code, const std::string& info)
     : code_(code)
     , info_(info)
   {
   }
-  
+
+  /**
+   * @brief Create from wire encoding
+   */
+  explicit
+  StatusResponse(const Block& wire)
+  {
+    wireDecode(wire);
+  }
+
   inline uint32_t
   getCode() const;
 
   inline void
   setCode(uint32_t code);
 
-  inline const std::string &
+  inline const std::string&
   getInfo() const;
 
   inline void
-  setInfo(const std::string &info);
+  setInfo(const std::string& info);
 
   inline const Block&
   wireEncode() const;
 
   inline void
-  wireDecode(const Block &block);
-  
+  wireDecode(const Block& block);
+
 private:
   uint32_t code_;
   std::string info_;
@@ -64,14 +73,14 @@
   wire_.reset();
 }
 
-inline const std::string &
+inline const std::string&
 StatusResponse::getInfo() const
 {
   return info_;
 }
 
 inline void
-StatusResponse::setInfo(const std::string &info)
+StatusResponse::setInfo(const std::string& info)
 {
   info_ = info;
   wire_.reset();
@@ -93,13 +102,13 @@
       wire_.push_back
         (dataBlock(tlv::ndnd::StatusText, info_.c_str(), info_.size()));
     }
-  
-  wire_.encode();  
+
+  wire_.encode();
   return wire_;
 }
 
 inline void
-StatusResponse::wireDecode(const Block &wire)
+StatusResponse::wireDecode(const Block& wire)
 {
   wire_ = wire;
   wire_.parse();
@@ -114,7 +123,7 @@
 }
 
 inline std::ostream&
-operator << (std::ostream &os, const StatusResponse &status)
+operator << (std::ostream& os, const StatusResponse& status)
 {
   os << status.getCode() << " " << status.getInfo();
   return os;
diff --git a/src/management/nfd-control-response.hpp b/src/management/nfd-control-response.hpp
index c959407..a4a5ae3 100644
--- a/src/management/nfd-control-response.hpp
+++ b/src/management/nfd-control-response.hpp
@@ -20,14 +20,22 @@
  */
 class ControlResponse {
 public:
-  struct Error : public Tlv::Error { Error(const std::string &what) : Tlv::Error(what) {} };
+  class Error : public Tlv::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : Tlv::Error(what)
+    {
+    }
+  };
 
   ControlResponse()
     : m_code(200)
   {
   }
 
-  ControlResponse(uint32_t code, const std::string &text)
+  ControlResponse(uint32_t code, const std::string& text)
     : m_code(code)
     , m_text(text)
   {
@@ -37,31 +45,31 @@
   {
     wireDecode(block);
   }
-  
+
   inline uint32_t
   getCode() const;
 
   inline void
   setCode(uint32_t code);
 
-  inline const std::string &
+  inline const std::string&
   getText() const;
 
   inline void
-  setText(const std::string &text);
+  setText(const std::string& text);
 
   inline const Block&
   getBody() const;
 
   inline void
   setBody(const Block& body);
-  
+
   inline const Block&
   wireEncode() const;
 
   inline void
-  wireDecode(const Block &block);
-  
+  wireDecode(const Block& block);
+
 protected:
   uint32_t m_code;
   std::string m_text;
@@ -83,14 +91,14 @@
   m_wire.reset();
 }
 
-inline const std::string &
+inline const std::string&
 ControlResponse::getText() const
 {
   return m_text;
 }
 
 inline void
-ControlResponse::setText(const std::string &text)
+ControlResponse::setText(const std::string& text)
 {
   m_text = text;
   m_wire.reset();
@@ -128,27 +136,27 @@
     {
       m_wire.push_back(m_body);
     }
-  
-  m_wire.encode();  
+
+  m_wire.encode();
   return m_wire;
 }
 
 inline void
-ControlResponse::wireDecode(const Block &wire)
+ControlResponse::wireDecode(const Block& wire)
 {
   m_wire = wire;
   m_wire.parse();
 
   if (m_wire.type() != tlv::nfd::ControlResponse)
-    throw Error("Requested decoding of ControlResponse, but Block is of different type");  
-  
+    throw Error("Requested decoding of ControlResponse, but Block is of different type");
+
   Block::element_const_iterator val = m_wire.elements_begin();
   if (val == m_wire.elements_end() ||
       val->type() != tlv::nfd::StatusCode)
     {
       throw Error("Incorrect ControlResponse format (StatusCode missing or not the first item)");
     }
-  
+
   m_code = readNonNegativeInteger(*val);
   ++val;
 
@@ -167,7 +175,7 @@
 }
 
 inline std::ostream&
-operator << (std::ostream &os, const ControlResponse &status)
+operator << (std::ostream& os, const ControlResponse& status)
 {
   os << status.getCode() << " " << status.getText();
   return os;
diff --git a/src/management/nfd-local-control-header.hpp b/src/management/nfd-local-control-header.hpp
index d09fe8a..9bbdebf 100644
--- a/src/management/nfd-local-control-header.hpp
+++ b/src/management/nfd-local-control-header.hpp
@@ -16,7 +16,15 @@
 class LocalControlHeader
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
   LocalControlHeader()
     : m_incomingFaceId(INVALID_FACE_ID)
@@ -25,6 +33,18 @@
   }
 
   /**
+   * @brief Create from wire encoding
+   *
+   * @sa wireDecode
+   */
+  explicit
+  LocalControlHeader(const Block& wire,
+                     bool encodeIncomingFaceId = true, bool encodeNextHopFaceId = true)
+  {
+    wireDecode(wire, encodeIncomingFaceId, encodeNextHopFaceId);
+  }
+
+  /**
    * @brief Create wire encoding with options LocalControlHeader and the supplied item
    *
    * The caller is responsible of checking whether LocalControlHeader contains
@@ -47,20 +67,20 @@
   inline Block
   wireEncode(const U& payload,
              bool encodeIncomingFaceId, bool encodeNextHopFaceId) const;
-  
+
   /**
    * @brief Decode from the wire format and set LocalControlHeader on the supplied item
    *
    * The supplied wire MUST contain LocalControlHeader.  Determination whether the optional
    * LocalControlHeader should be done before calling this method.
    */
-  inline void 
+  inline void
   wireDecode(const Block& wire,
              bool encodeIncomingFaceId = true, bool encodeNextHopFaceId = true);
 
   inline static const Block&
   getPayload(const Block& wire);
-  
+
   ///////////////////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////////////////
@@ -72,15 +92,15 @@
     return !((encodeIncomingFaceId && hasIncomingFaceId()) ||
              (encodeNextHopFaceId  && hasNextHopFaceId()));
   }
-  
+
   //
-  
+
   bool
   hasIncomingFaceId() const
   {
     return m_incomingFaceId != INVALID_FACE_ID;
   }
-  
+
   uint64_t
   getIncomingFaceId() const
   {
@@ -100,7 +120,7 @@
   {
     return m_nextHopFaceId != INVALID_FACE_ID;
   }
-  
+
   uint64_t
   getNextHopFaceId() const
   {
@@ -118,7 +138,7 @@
   inline size_t
   wireEncode(EncodingImpl<T>& block, size_t payloadSize,
              bool encodeIncomingFaceId, bool encodeNextHopFaceId) const;
-  
+
 private:
   uint64_t m_incomingFaceId;
   uint64_t m_nextHopFaceId;
@@ -133,23 +153,23 @@
 LocalControlHeader::wireEncode(EncodingImpl<T>& block, size_t payloadSize,
                                bool encodeIncomingFaceId, bool encodeNextHopFaceId) const
 {
-  size_t total_len = payloadSize;
+  size_t totalLength = payloadSize;
 
   if (encodeIncomingFaceId && hasIncomingFaceId())
     {
-      total_len += prependNonNegativeIntegerBlock(block,
-                                                  tlv::nfd::IncomingFaceId, getIncomingFaceId());
+      totalLength += prependNonNegativeIntegerBlock(block,
+                                                    tlv::nfd::IncomingFaceId, getIncomingFaceId());
     }
 
   if (encodeNextHopFaceId && hasNextHopFaceId())
     {
-      total_len += prependNonNegativeIntegerBlock(block,
-                                                  tlv::nfd::NextHopFaceId, getNextHopFaceId());
+      totalLength += prependNonNegativeIntegerBlock(block,
+                                                    tlv::nfd::NextHopFaceId, getNextHopFaceId());
     }
-  
-  total_len += block.prependVarNumber(total_len);
-  total_len += block.prependVarNumber(tlv::nfd::LocalControlHeader);
-  return total_len;
+
+  totalLength += block.prependVarNumber(totalLength);
+  totalLength += block.prependVarNumber(tlv::nfd::LocalControlHeader);
+  return totalLength;
 }
 
 template<class U>
@@ -164,7 +184,7 @@
   EncodingEstimator estimator;
   size_t length = wireEncode(estimator, payload.wireEncode().size(),
                              encodeIncomingFaceId, encodeNextHopFaceId);
-  
+
   EncodingBuffer buffer(length);
   wireEncode(buffer, payload.wireEncode().size(),
              encodeIncomingFaceId, encodeNextHopFaceId);
@@ -172,7 +192,7 @@
   return buffer.block(false);
 }
 
-inline void 
+inline void
 LocalControlHeader::wireDecode(const Block& wire,
                                bool encodeIncomingFaceId/* = true*/, bool encodeNextHopFaceId/* = true*/)
 {
@@ -186,7 +206,7 @@
        i != wire.elements_end();
        ++i)
     {
-      switch(i->type())
+      switch (i->type())
         {
         case tlv::nfd::IncomingFaceId:
           if (encodeIncomingFaceId)
diff --git a/src/management/nrd-controller.cpp b/src/management/nrd-controller.cpp
index 1d0e7a1..66156d2 100644
--- a/src/management/nrd-controller.cpp
+++ b/src/management/nrd-controller.cpp
@@ -115,7 +115,7 @@
       PrefixRegOptions options(response.getBody());
       return onSuccess(options);
     }
-  catch(ndn::Tlv::Error& e)
+  catch (ndn::Tlv::Error& e)
     {
       if (static_cast<bool>(onFail))
         return onFail(e.what());
diff --git a/src/management/nrd-prefix-reg-options.hpp b/src/management/nrd-prefix-reg-options.hpp
index c80d04b..2c37c4a 100644
--- a/src/management/nrd-prefix-reg-options.hpp
+++ b/src/management/nrd-prefix-reg-options.hpp
@@ -26,7 +26,15 @@
  */
 class PrefixRegOptions {
 public:
-  struct Error : public Tlv::Error { Error(const std::string& what) : Tlv::Error(what) {} };
+  class Error : public Tlv::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : Tlv::Error(what)
+    {
+    }
+  };
 
   PrefixRegOptions()
     : m_faceId(INVALID_FACE_ID)
@@ -36,6 +44,7 @@
   {
   }
 
+  explicit
   PrefixRegOptions(const Block& block)
   {
     wireDecode(block);
@@ -162,7 +171,7 @@
 inline size_t
 PrefixRegOptions::wireEncode(EncodingImpl<T>& block) const
 {
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   // PrefixRegOptions ::= PREFIX-REG-OPTIONS-TYPE TLV-LENGTH
   //                        Name
@@ -177,44 +186,44 @@
   // Protocol
   if (!m_protocol.empty())
     {
-      total_len += prependByteArrayBlock(block,
-                                         tlv::nrd::Protocol,
-                                         reinterpret_cast<const uint8_t*>(m_protocol.c_str()),
-                                         m_protocol.size());
+      totalLength += prependByteArrayBlock(block,
+                                           tlv::nrd::Protocol,
+                                           reinterpret_cast<const uint8_t*>(m_protocol.c_str()),
+                                           m_protocol.size());
     }
 
   // ExpirationPeriod
   if (m_expirationPeriod > time::milliseconds::zero())
     {
-      total_len += prependNonNegativeIntegerBlock(block,
-                                                  tlv::nrd::ExpirationPeriod,
-                                                  m_expirationPeriod.count());
+      totalLength += prependNonNegativeIntegerBlock(block,
+                                                    tlv::nrd::ExpirationPeriod,
+                                                    m_expirationPeriod.count());
     }
 
   // Cost
   if (m_cost != DEFAULT_COST)
     {
-      total_len += prependNonNegativeIntegerBlock(block, tlv::nrd::Cost, m_cost);
+      totalLength += prependNonNegativeIntegerBlock(block, tlv::nrd::Cost, m_cost);
     }
 
   // Flags
   if (m_flags != DEFAULT_FLAGS)
     {
-      total_len += prependNonNegativeIntegerBlock(block, tlv::nrd::Flags, m_flags);
+      totalLength += prependNonNegativeIntegerBlock(block, tlv::nrd::Flags, m_flags);
     }
 
   // FaceId
   if (m_faceId != INVALID_FACE_ID)
     {
-      total_len += prependNonNegativeIntegerBlock(block, tlv::nrd::FaceId, m_faceId);
+      totalLength += prependNonNegativeIntegerBlock(block, tlv::nrd::FaceId, m_faceId);
     }
 
   // Name
-  total_len += m_name.wireEncode(block);
+  totalLength += m_name.wireEncode(block);
 
-  total_len += block.prependVarNumber(total_len);
-  total_len += block.prependVarNumber(tlv::nrd::PrefixRegOptions);
-  return total_len;
+  totalLength += block.prependVarNumber(totalLength);
+  totalLength += block.prependVarNumber(tlv::nrd::PrefixRegOptions);
+  return totalLength;
 }
 
 inline const Block&
@@ -303,7 +312,7 @@
 }
 
 inline std::ostream&
-operator << (std::ostream &os, const PrefixRegOptions &option)
+operator << (std::ostream& os, const PrefixRegOptions& option)
 {
   os << "PrefixRegOptions(";
 
diff --git a/src/meta-info.hpp b/src/meta-info.hpp
index 8042f8b..4153911 100644
--- a/src/meta-info.hpp
+++ b/src/meta-info.hpp
@@ -28,6 +28,9 @@
   {
   }
 
+  /**
+   * @brief Create from wire encoding
+   */
   MetaInfo(const Block& block)
   {
     wireDecode(block);
@@ -118,30 +121,30 @@
   //                FreshnessPeriod?
   //                FinalBlockId?
 
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   // FinalBlockId
   if (!m_finalBlockId.empty())
     {
-      total_len += prependNestedBlock(blk, Tlv::FinalBlockId, m_finalBlockId);
+      totalLength += prependNestedBlock(blk, Tlv::FinalBlockId, m_finalBlockId);
     }
 
   // FreshnessPeriod
   if (m_freshnessPeriod >= time::milliseconds::zero())
     {
-      total_len += prependNonNegativeIntegerBlock(blk, Tlv::FreshnessPeriod,
-                                                  m_freshnessPeriod.count());
+      totalLength += prependNonNegativeIntegerBlock(blk, Tlv::FreshnessPeriod,
+                                                    m_freshnessPeriod.count());
     }
 
   // ContentType
   if (m_type != TYPE_DEFAULT)
     {
-      total_len += prependNonNegativeIntegerBlock(blk, Tlv::ContentType, m_type);
+      totalLength += prependNonNegativeIntegerBlock(blk, Tlv::ContentType, m_type);
     }
 
-  total_len += blk.prependVarNumber(total_len);
-  total_len += blk.prependVarNumber(Tlv::MetaInfo);
-  return total_len;
+  totalLength += blk.prependVarNumber(totalLength);
+  totalLength += blk.prependVarNumber(Tlv::MetaInfo);
+  return totalLength;
 }
 
 inline const Block&
diff --git a/src/name-component.hpp b/src/name-component.hpp
index 9ea09c5..5e5cb09 100644
--- a/src/name-component.hpp
+++ b/src/name-component.hpp
@@ -24,9 +24,17 @@
 class Component : public Block
 {
 public:
-  /// @brief Error that can be thrown from the block
-  struct Error : public std::runtime_error {
-    Error(const std::string& what) : std::runtime_error(what) {}
+  /**
+   * @brief Error that can be thrown from the block
+   */
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
   };
 
   /**
@@ -37,6 +45,8 @@
   /**
    * @brief Directly create component from wire block
    *
+   * Any block can be implicitly converted to name::Component
+   *
    * @throws Error if wire.type() is not Tlv::Component
    */
   Component(const Block& wire);
@@ -45,12 +55,14 @@
    * Create a new Name::Component, taking another pointer to the Blob value.
    * @param value A blob with a pointer to an immutable array.  The pointer is copied.
    */
+  explicit
   Component(const ConstBufferPtr& buffer);
 
   /**
    * Create a new Name::Component, copying the given value.
    * @param value The value byte array.
    */
+  explicit
   Component(const Buffer& value);
 
   /**
@@ -58,13 +70,13 @@
    * @param value Pointer to the value byte array.
    * @param valueLen Length of value.
    */
-  Component(const uint8_t *value, size_t valueLen);
+  Component(const uint8_t* value, size_t valueLen);
 
   template<class InputIterator>
   Component(InputIterator begin, InputIterator end);
 
   explicit
-  Component(const char *str);
+  Component(const char* str);
 
   explicit
   Component(const std::string& str);
@@ -77,6 +89,18 @@
   wireEncode(EncodingImpl<T>& block) const;
 
   /**
+   * @brief Encode to a wire format
+   */
+  inline const Block&
+  wireEncode() const;
+
+  /**
+   * @brief Decode from the wire format
+   */
+  inline void
+  wireDecode(const Block& wire);
+
+  /**
    * Make a Blob value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.
    * If the escaped string is "", "." or ".." then return a Blob with a null pointer,
    * which means the component should be skipped in a URI name.
@@ -86,7 +110,7 @@
    * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.
    */
   static Component
-  fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset);
+  fromEscapedString(const char* escapedString, size_t beginOffset, size_t endOffset);
 
   /**
    * Make a Blob value by decoding the escapedString according to the NDN URI Scheme.
@@ -96,7 +120,7 @@
    * @return The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.
    */
   static Component
-  fromEscapedString(const char *escapedString)
+  fromEscapedString(const char* escapedString)
   {
     return fromEscapedString(escapedString, 0, ::strlen(escapedString));
   }
@@ -309,7 +333,7 @@
 }
 
 inline
-Component::Component(const uint8_t *value, size_t valueLen)
+Component::Component(const uint8_t* value, size_t valueLen)
   : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(value, valueLen)))
 {
 }
@@ -322,7 +346,7 @@
 }
 
 inline
-Component::Component(const char *str)
+Component::Component(const char* str)
   : Block (Tlv::NameComponent, ConstBufferPtr(new Buffer(str, ::strlen(str))))
 {
 }
@@ -348,17 +372,17 @@
       return Component();
     else
       // Remove 3 periods.
-      return Component((const uint8_t *)&value[3], value.size() - 3);
+      return Component(reinterpret_cast<const uint8_t*>(&value[3]), value.size() - 3);
   }
   else
-    return Component((const uint8_t *)&value[0], value.size());
+    return Component(reinterpret_cast<const uint8_t*>(&value[0]), value.size());
 }
 
 
 inline void
 Component::toEscapedString(std::ostream& result) const
 {
-  const uint8_t *valuePtr = value();
+  const uint8_t* valuePtr = value();
   size_t valueSize = value_size();
 
   bool gotNonDot = false;
@@ -448,14 +472,46 @@
 inline size_t
 Component::wireEncode(EncodingImpl<T>& block) const
 {
-  size_t total_len = 0;
+  size_t totalLength = 0;
   if (value_size() > 0)
-    total_len += block.prependByteArray (value(), value_size());
-  total_len += block.prependVarNumber (value_size());
-  total_len += block.prependVarNumber (Tlv::NameComponent);
-  return total_len;
+    totalLength += block.prependByteArray (value(), value_size());
+  totalLength += block.prependVarNumber (value_size());
+  totalLength += block.prependVarNumber (Tlv::NameComponent);
+  return totalLength;
 }
 
+/**
+ * @brief Encode to a wire format
+ */
+inline const Block&
+Component::wireEncode() const
+{
+  if (this->hasWire())
+    return *this;
+
+  EncodingEstimator estimator;
+  size_t estimatedSize = wireEncode(estimator);
+
+  EncodingBuffer buffer(estimatedSize, 0);
+  wireEncode(buffer);
+
+  const_cast<Component&>(*this) = buffer.block();
+  return *this;
+}
+
+/**
+ * @brief Decode from the wire format
+ */
+inline void
+Component::wireDecode(const Block& wire)
+{
+  if (wire.type() != Tlv::NameComponent)
+    throw Error("wireDecode name component from non name component TLV wire block");
+
+  *this = wire;
+}
+
+
 } // namespace name
 } // namespace ndn
 
diff --git a/src/name.hpp b/src/name.hpp
index 5a8dfcf..03030f0 100644
--- a/src/name.hpp
+++ b/src/name.hpp
@@ -117,7 +117,7 @@
    * @param uri The null-terminated URI string.
    */
   void
-  set(const char *uri);
+  set(const char* uri);
 
   /**
    * Parse the uri according to the NDN URI Scheme and set the name with the components.
@@ -311,14 +311,20 @@
    * @brief Check if name is emtpy
    */
   bool
-  empty() const { return m_nameBlock.elements().empty(); }
+  empty() const
+  {
+    return m_nameBlock.elements().empty();
+  }
 
   /**
    * Get the number of components.
    * @return The number of components.
    */
   size_t
-  size() const { return m_nameBlock.elements_size(); }
+  size() const
+  {
+    return m_nameBlock.elements_size();
+  }
 
   /**
    * Get the component at the given index.
@@ -394,7 +400,10 @@
    * @return true if the names are equal, otherwise false.
    */
   bool
-  operator==(const Name& name) const { return equals(name); }
+  operator==(const Name& name) const
+  {
+    return equals(name);
+  }
 
   /**
    * Check if this name has the same component count and components as the given name.
@@ -402,7 +411,10 @@
    * @return true if the names are not equal, otherwise false.
    */
   bool
-  operator!=(const Name& name) const { return !equals(name); }
+  operator!=(const Name& name) const
+  {
+    return !equals(name);
+  }
 
   /**
    * Return true if this is less than or equal to the other Name in the NDN canonical ordering.
@@ -411,7 +423,10 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator<=(const Name& other) const { return compare(other) <= 0; }
+  operator<=(const Name& other) const
+  {
+    return compare(other) <= 0;
+  }
 
   /**
    * Return true if this is less than the other Name in the NDN canonical ordering.
@@ -420,7 +435,10 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator<(const Name& other) const { return compare(other) < 0; }
+  operator<(const Name& other) const
+  {
+    return compare(other) < 0;
+  }
 
   /**
    * Return true if this is less than or equal to the other Name in the NDN canonical ordering.
@@ -429,7 +447,10 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator>=(const Name& other) const { return compare(other) >= 0; }
+  operator>=(const Name& other) const
+  {
+    return compare(other) >= 0;
+  }
 
   /**
    * Return true if this is greater than the other Name in the NDN canonical ordering.
@@ -438,7 +459,10 @@
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   bool
-  operator>(const Name& other) const { return compare(other) > 0; }
+  operator>(const Name& other) const
+  {
+    return compare(other) > 0;
+  }
 
   //
   // Iterator interface to name components.
@@ -681,18 +705,18 @@
 inline size_t
 Name::wireEncode(EncodingImpl<T>& blk) const
 {
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   for (const_reverse_iterator i = rbegin();
        i != rend();
        ++i)
     {
-      total_len += i->wireEncode(blk);
+      totalLength += i->wireEncode(blk);
     }
 
-  total_len += blk.prependVarNumber(total_len);
-  total_len += blk.prependVarNumber(Tlv::Name);
-  return total_len;
+  totalLength += blk.prependVarNumber(totalLength);
+  totalLength += blk.prependVarNumber(Tlv::Name);
+  return totalLength;
 }
 
 inline const Block&
diff --git a/src/security/certificate-cache-ttl.cpp b/src/security/certificate-cache-ttl.cpp
index 8dea438..0a9002e 100644
--- a/src/security/certificate-cache-ttl.cpp
+++ b/src/security/certificate-cache-ttl.cpp
@@ -50,7 +50,7 @@
 }
 
 void
-CertificateCacheTtl::remove(const Name &certificateName)
+CertificateCacheTtl::remove(const Name& certificateName)
 {
   Name name = certificateName.getPrefix(-1);
   Cache::iterator it = m_cache.find(name);
@@ -59,7 +59,7 @@
 }
 
 ptr_lib::shared_ptr<const IdentityCertificate>
-CertificateCacheTtl::getCertificate(const Name & certificateName)
+CertificateCacheTtl::getCertificate(const Name& certificateName)
 {
   Cache::iterator it = m_cache.find(certificateName);
   if(it != m_cache.end())
diff --git a/src/security/certificate-cache-ttl.hpp b/src/security/certificate-cache-ttl.hpp
index 1e31e9c..4f65d17 100644
--- a/src/security/certificate-cache-ttl.hpp
+++ b/src/security/certificate-cache-ttl.hpp
@@ -27,14 +27,14 @@
   insertCertificate(ptr_lib::shared_ptr<const IdentityCertificate> certificate);
 
   virtual ptr_lib::shared_ptr<const IdentityCertificate>
-  getCertificate(const Name & certificateNameWithoutVersion);
+  getCertificate(const Name& certificateNameWithoutVersion);
 
 private:
   void
   insert(ptr_lib::shared_ptr<const IdentityCertificate> certificate);
 
   void
-  remove(const Name &certificateName);
+  remove(const Name& certificateName);
 
 protected:
   typedef std::map<Name, ptr_lib::shared_ptr<const IdentityCertificate> > Cache;
diff --git a/src/security/certificate-extension.cpp b/src/security/certificate-extension.cpp
index 7ee0de9..3a23a80 100644
--- a/src/security/certificate-extension.cpp
+++ b/src/security/certificate-extension.cpp
@@ -17,7 +17,7 @@
 namespace ndn {
 
 void
-CertificateExtension::encode(CryptoPP::BufferedTransformation &out) const
+CertificateExtension::encode(CryptoPP::BufferedTransformation& out) const
 {
   // Extension ::= SEQUENCE {
   //        extnID      OBJECT IDENTIFIER,
@@ -34,7 +34,7 @@
 }
 
 void
-CertificateExtension::decode(CryptoPP::BufferedTransformation &in)
+CertificateExtension::decode(CryptoPP::BufferedTransformation& in)
 {
   // Extension ::= SEQUENCE {
   //        extnID      OBJECT IDENTIFIER,
@@ -54,5 +54,5 @@
   }
   extension.MessageEnd();
 }
- 
+
 } // namespace ndn
diff --git a/src/security/certificate-extension.hpp b/src/security/certificate-extension.hpp
index 4eba4f2..1388107 100644
--- a/src/security/certificate-extension.hpp
+++ b/src/security/certificate-extension.hpp
@@ -23,9 +23,17 @@
 class CertificateExtension
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
-  CertificateExtension(CryptoPP::BufferedTransformation &in)
+  CertificateExtension(CryptoPP::BufferedTransformation& in)
   {
     decode(in);
   }
@@ -45,7 +53,7 @@
     : extensionId_(oid), isCritical_(isCritical), extensionValue_(value, valueSize)
   {
   }
-  
+
   /**
    * The virtual destructor.
    */
@@ -53,20 +61,20 @@
   ~CertificateExtension() {}
 
   void
-  encode(CryptoPP::BufferedTransformation &out) const;
+  encode(CryptoPP::BufferedTransformation& out) const;
 
   void
-  decode(CryptoPP::BufferedTransformation &in);
-  
-  inline const OID& 
+  decode(CryptoPP::BufferedTransformation& in);
+
+  inline const OID&
   getOid() const { return extensionId_; }
 
-  inline const bool 
+  inline const bool
   getIsCritical() const { return isCritical_; }
 
-  inline const Buffer& 
+  inline const Buffer&
   getValue() const { return extensionValue_; }
-    
+
 protected:
   OID extensionId_;
   bool isCritical_;
diff --git a/src/security/certificate-subject-description.cpp b/src/security/certificate-subject-description.cpp
index fc6478f..44cd8c5 100644
--- a/src/security/certificate-subject-description.cpp
+++ b/src/security/certificate-subject-description.cpp
@@ -18,17 +18,17 @@
 namespace ndn {
 
 void
-CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const
+CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation& out) const
 {
   // RelativeDistinguishedName ::=
   //     SET OF AttributeTypeAndValue
-  // 
+  //
   // AttributeTypeAndValue ::= SEQUENCE {
   //     type     AttributeType,
   //     value    AttributeValue   }
-  // 
+  //
   // AttributeType ::= OBJECT IDENTIFIER
-  // 
+  //
   // AttributeValue ::= ANY DEFINED BY AttributeType
   DERSequenceEncoder attributeTypeAndValue(out);
   {
@@ -39,17 +39,17 @@
 }
 
 void
-CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation &in)
+CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation& in)
 {
   // RelativeDistinguishedName ::=
   //     SET OF AttributeTypeAndValue
-  // 
+  //
   // AttributeTypeAndValue ::= SEQUENCE {
   //     type     AttributeType,
   //     value    AttributeValue   }
-  // 
+  //
   // AttributeType ::= OBJECT IDENTIFIER
-  // 
+  //
   // AttributeValue ::= ANY DEFINED BY AttributeType
 
   BERSequenceDecoder attributeTypeAndValue(in);
diff --git a/src/security/certificate-subject-description.hpp b/src/security/certificate-subject-description.hpp
index 5510f6e..859aed3 100644
--- a/src/security/certificate-subject-description.hpp
+++ b/src/security/certificate-subject-description.hpp
@@ -21,39 +21,39 @@
  */
 class CertificateSubjectDescription {
 public:
-  CertificateSubjectDescription(CryptoPP::BufferedTransformation &in)
+  CertificateSubjectDescription(CryptoPP::BufferedTransformation& in)
   {
     decode(in);
   }
-  
+
   /**
    * Create a new CertificateSubjectDescription.
    * @param oid The oid of the subject description entry.
    * @param value The value of the subject description entry.
    */
-  CertificateSubjectDescription(const OID &oid, const std::string &value)
+  CertificateSubjectDescription(const OID& oid, const std::string& value)
   : oid_(oid), value_(value)
   {
   }
 
   void
-  encode(CryptoPP::BufferedTransformation &out) const;
+  encode(CryptoPP::BufferedTransformation& out) const;
 
   void
-  decode(CryptoPP::BufferedTransformation &in);
-  
+  decode(CryptoPP::BufferedTransformation& in);
+
   std::string
   getOidString() const
   {
     return oid_.toString();
   }
 
-  const std::string &
+  const std::string&
   getValue() const
   {
     return value_;
   }
-  
+
 private:
   OID oid_;
   std::string value_;
diff --git a/src/security/certificate.cpp b/src/security/certificate.cpp
index eb45d6f..3c4ed2d 100644
--- a/src/security/certificate.cpp
+++ b/src/security/certificate.cpp
@@ -45,7 +45,7 @@
 bool
 Certificate::isTooEarly()
 {
-  if(time::system_clock::now() < notBefore_)
+  if (time::system_clock::now() < notBefore_)
     return true;
   else
     return false;
@@ -54,7 +54,7 @@
 bool
 Certificate::isTooLate()
 {
-  if(time::system_clock::now() > notAfter_)
+  if (time::system_clock::now() > notAfter_)
     return true;
   else
     return false;
@@ -143,7 +143,7 @@
     //        extnID      OBJECT IDENTIFIER,
     //        critical    BOOLEAN DEFAULT FALSE,
     //        extnValue   OCTET STRING  }
-    if(!extensionList_.empty())
+    if (!extensionList_.empty())
       {
         DERSequenceEncoder extensions(idCert);
         {
@@ -215,7 +215,7 @@
     //        critical    BOOLEAN DEFAULT FALSE,
     //        extnValue   OCTET STRING  }
     extensionList_.clear();
-    if(!idCert.EndReached())
+    if (!idCert.EndReached())
       {
         BERSequenceDecoder extensions(idCert);
         {
@@ -232,7 +232,7 @@
 }
 
 void
-Certificate::printCertificate(std::ostream &os) const
+Certificate::printCertificate(std::ostream& os) const
 {
   os << "Certificate name:" << endl;
   os << "  " << getName() << endl;
diff --git a/src/security/certificate.hpp b/src/security/certificate.hpp
index d27f7a4..3470134 100644
--- a/src/security/certificate.hpp
+++ b/src/security/certificate.hpp
@@ -20,7 +20,15 @@
 
 class Certificate : public Data {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
   typedef std::vector<CertificateSubjectDescription> SubjectDescriptionList;
   typedef std::vector<CertificateExtension> ExtensionList;
@@ -43,7 +51,7 @@
   ~Certificate();
 
   inline void
-  wireDecode(const Block &wire);
+  wireDecode(const Block& wire);
 
   /**
    * encode certificate info into content
@@ -122,7 +130,7 @@
   isTooLate();
 
   void
-  printCertificate(std::ostream &os) const;
+  printCertificate(std::ostream& os) const;
 
 protected:
   void
@@ -137,7 +145,7 @@
 };
 
 inline void
-Certificate::wireDecode(const Block &wire)
+Certificate::wireDecode(const Block& wire)
 {
   Data::wireDecode(wire);
   decode();
@@ -145,7 +153,7 @@
 
 
 inline std::ostream&
-operator <<(std::ostream &os, const Certificate &cert)
+operator <<(std::ostream& os, const Certificate& cert)
 {
   cert.printCertificate(os);
   return os;
diff --git a/src/security/conf/checker.hpp b/src/security/conf/checker.hpp
index 48664ea..3fa8d94 100644
--- a/src/security/conf/checker.hpp
+++ b/src/security/conf/checker.hpp
@@ -224,7 +224,7 @@
         return -1;
       }
 
-    switch(signature.getType())
+    switch (signature.getType())
       {
       case Signature::Sha256WithRsa:
         {
diff --git a/src/security/identity-certificate.cpp b/src/security/identity-certificate.cpp
index b4d5cb5..75693b0 100644
--- a/src/security/identity-certificate.cpp
+++ b/src/security/identity-certificate.cpp
@@ -20,21 +20,21 @@
   string idString("ID-CERT");
   int i = name.size() - 1;
   for (; i >= 0; i--) {
-    if(name.get(i).toEscapedString() == idString)
+    if (name.get(i).toEscapedString() == idString)
       break;
   }
 
   if (i < 0)
     return false;
-  
-  size_t keyIdx = 0;
+
   string keyString("KEY");
-  for (; keyIdx < name.size(); keyIdx++) {
-    if(name.get(keyIdx).toEscapedString() == keyString)
+  size_t keyIndex = 0;
+  for (; keyIndex < name.size(); keyIndex++) {
+    if (name.get(keyIndex).toEscapedString() == keyString)
       break;
   }
 
-  if (keyIdx >= name.size())
+  if (keyIndex >= name.size())
     return false;
 
   return true;
@@ -45,7 +45,7 @@
 {
   if (!isCorrectName(getName()))
     throw Error("Wrong Identity Certificate Name!");
-  
+
   publicKeyName_ = certificateNameToPublicKeyName(getName());
 }
 
@@ -69,9 +69,9 @@
       }
   }
 
-  if(!foundIdString)
+  if (!foundIdString)
     throw Error("Incorrect identity certificate name " + certificateName.toUri());
-    
+
   Name tmpName = certificateName.getSubName(0, idCertComponentIndex);
   string keyString("KEY");
   bool foundKeyString = false;
@@ -84,7 +84,7 @@
       }
   }
 
-  if(!foundKeyString)
+  if (!foundKeyString)
     throw Error("Incorrect identity certificate name " + certificateName.toUri());
 
   return tmpName
diff --git a/src/security/identity-certificate.hpp b/src/security/identity-certificate.hpp
index 6d6d334..01427d4 100644
--- a/src/security/identity-certificate.hpp
+++ b/src/security/identity-certificate.hpp
@@ -17,7 +17,15 @@
 class IdentityCertificate : public Certificate
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
   /**
    * The default constructor.
@@ -33,20 +41,20 @@
    */
   inline
   IdentityCertificate(const Data& data);
-  
+
   /**
    * The virtual destructor.
    */
-  inline virtual 
+  inline virtual
   ~IdentityCertificate();
-  
-  inline void
-  wireDecode(const Block &wire);
 
   inline void
-  setName(const Name &name);
-  
-  inline const Name &
+  wireDecode(const Block& wire);
+
+  inline void
+  setName(const Name& name);
+
+  inline const Name&
   getPublicKeyName () const;
 
   static bool
@@ -59,14 +67,14 @@
    */
   static Name
   certificateNameToPublicKeyName(const Name& certificateName);
-  
+
 private:
   static bool
   isCorrectName(const Name& name);
-  
+
   void
   setPublicKeyName();
-    
+
 protected:
   Name publicKeyName_;
 };
@@ -82,27 +90,27 @@
 {
   setPublicKeyName();
 }
-  
+
 inline
 IdentityCertificate::~IdentityCertificate()
 {
 }
 
 inline void
-IdentityCertificate::wireDecode(const Block &wire)
+IdentityCertificate::wireDecode(const Block& wire)
 {
   Certificate::wireDecode(wire);
   setPublicKeyName();
 }
 
 inline void
-IdentityCertificate::setName(const Name &name)
+IdentityCertificate::setName(const Name& name)
 {
   Certificate::setName(name);
   setPublicKeyName();
 }
 
-inline const Name &
+inline const Name&
 IdentityCertificate::getPublicKeyName () const
 {
   return publicKeyName_;
diff --git a/src/security/key-chain.hpp b/src/security/key-chain.hpp
index ac03ce4..70593a9 100644
--- a/src/security/key-chain.hpp
+++ b/src/security/key-chain.hpp
@@ -59,7 +59,7 @@
       {
         keyName = Info::getDefaultKeyNameForIdentity(identityName);
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         keyName = generateRSAKeyPairAsDefault(identityName, true);
       }
@@ -69,7 +69,7 @@
       {
         certName = Info::getDefaultCertificateNameForKey(keyName);
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         shared_ptr<IdentityCertificate> selfCert = selfSign(keyName);
         Info::addCertificateAsIdentityDefault(*selfCert);
@@ -129,17 +129,17 @@
                                      const std::vector<CertificateSubjectDescription>& subjectDescription)
 
   {
-    if(keyName.size() < 1)
+    if (keyName.size() < 1)
       return shared_ptr<IdentityCertificate>();
 
     std::string keyIdPrefix = keyName.get(-1).toEscapedString().substr(0, 4);
-    if(keyIdPrefix != "ksk-" && keyIdPrefix != "dsk-")
+    if (keyIdPrefix != "ksk-" && keyIdPrefix != "dsk-")
       return shared_ptr<IdentityCertificate>();
 
     shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>();
     Name certName;
 
-    if(signingIdentity.isPrefixOf(keyName))
+    if (signingIdentity.isPrefixOf(keyName))
       {
         certName.append(signingIdentity).append("KEY").append(keyName.getSubName(signingIdentity.size())).append("ID-CERT").appendVersion();
       }
@@ -157,13 +157,13 @@
       {
         publicKey = Info::getPublicKey(keyName);
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         return shared_ptr<IdentityCertificate>();
       }
     certificate->setPublicKeyInfo(*publicKey);
 
-    if(subjectDescription.empty())
+    if (subjectDescription.empty())
       {
         CertificateSubjectDescription subDescryptName("2.5.4.41", keyName.getPrefix(-1).toUri());
         certificate->addSubjectDescription(subDescryptName);
@@ -285,7 +285,7 @@
       {
         signingCertificateName = Info::getDefaultCertificateNameForIdentity(identityName);
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         signingCertificateName = createIdentity(identityName);
         // Ideally, no exception will be thrown out, unless something goes wrong in the TPM, which is a fatal error.
@@ -311,7 +311,7 @@
       {
         signingCertificateName = Info::getDefaultCertificateNameForIdentity(identityName);
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         signingCertificateName = createIdentity(identityName);
         // Ideally, no exception will be thrown out, unless something goes wrong in the TPM, which is a fatal error.
@@ -353,7 +353,7 @@
       {
         pubKey = Info::getPublicKey(keyName); // may throw an exception.
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         return shared_ptr<IdentityCertificate>();
       }
@@ -384,7 +384,7 @@
   selfSign (IdentityCertificate& cert)
   {
     Name keyName = IdentityCertificate::certificateNameToPublicKeyName(cert.getName());
-    if(!Tpm::doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
+    if (!Tpm::doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
       throw TpmError("private key does not exist!");
 
     SignatureSha256WithRsa signature;
@@ -407,10 +407,10 @@
   {
     try
       {
-        if(Info::getDefaultCertificateName() == certificateName)
+        if (Info::getDefaultCertificateName() == certificateName)
           return;
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         // Not a real error, just try to delete the certificate
       }
@@ -431,10 +431,10 @@
   {
     try
       {
-        if(Info::getDefaultKeyNameForIdentity(Info::getDefaultIdentity()) == keyName)
+        if (Info::getDefaultKeyNameForIdentity(Info::getDefaultIdentity()) == keyName)
           return;
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         // Not a real error, just try to delete the key
       }
@@ -456,10 +456,10 @@
   {
     try
       {
-        if(Info::getDefaultIdentity() == identity)
+        if (Info::getDefaultIdentity() == identity)
           return;
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         // Not a real error, just try to delete the identity
       }
@@ -496,7 +496,7 @@
       {
         pkcs8 = Tpm::exportPrivateKeyPkcs8FromTpm(keyName, passwordStr);
       }
-    catch(TpmError& e)
+    catch (TpmError& e)
       {
         throw InfoError("Fail to export PKCS8 of private key");
       }
@@ -506,7 +506,7 @@
       {
         cert = Info::getCertificate(Info::getDefaultCertificateNameForKey(keyName));
       }
-    catch(InfoError& e)
+    catch (InfoError& e)
       {
         cert = selfSign(keyName);
         Info::addCertificateAsIdentityDefault(*cert);
diff --git a/src/security/public-key.cpp b/src/security/public-key.cpp
index f6b2fdf..b9b7cf3 100644
--- a/src/security/public-key.cpp
+++ b/src/security/public-key.cpp
@@ -28,14 +28,14 @@
  * @param algorithm The algorithm of the public key.
  * @param keyDer The blob of the PublicKeyInfo in terms of DER.
  */
-PublicKey::PublicKey(const uint8_t *keyDerBuf, size_t keyDerSize)
+PublicKey::PublicKey(const uint8_t* keyDerBuf, size_t keyDerSize)
 {
   StringSource src(keyDerBuf, keyDerSize, true);
   decode(src);
 }
 
 void
-PublicKey::encode(CryptoPP::BufferedTransformation &out) const
+PublicKey::encode(CryptoPP::BufferedTransformation& out) const
 {
   // SubjectPublicKeyInfo ::= SEQUENCE {
   //     algorithm           AlgorithmIdentifier
@@ -45,7 +45,7 @@
 }
 
 void
-PublicKey::decode(CryptoPP::BufferedTransformation &in)
+PublicKey::decode(CryptoPP::BufferedTransformation& in)
 {
   // SubjectPublicKeyInfo ::= SEQUENCE {
   //     algorithm           AlgorithmIdentifier
@@ -86,7 +86,7 @@
 
     key_.assign(out.begin(), out.end());
   }
-  catch (CryptoPP::BERDecodeErr &err) {
+  catch (CryptoPP::BERDecodeErr& err) {
     throw Error("PublicKey decoding error");
   }
 }
@@ -97,15 +97,15 @@
 //   if (digestAlgorithm == DIGEST_ALGORITHM_SHA256) {
 //     uint8_t digest[SHA256_DIGEST_LENGTH];
 //     ndn_digestSha256(keyDer_.buf(), keyDer_.size(), digest);
-    
+
 //     return Blob(digest, sizeof(digest));
 //   }
 //   else
 //     throw UnrecognizedDigestAlgorithmException("Wrong format!");
 // }
 
-std::ostream &
-operator <<(std::ostream &os, const PublicKey &key)
+std::ostream&
+operator <<(std::ostream& os, const PublicKey& key)
 {
   CryptoPP::StringSource(key.get().buf(), key.get().size(), true,
                          new CryptoPP::Base64Encoder(new CryptoPP::FileSink(os), true, 64));
diff --git a/src/security/public-key.hpp b/src/security/public-key.hpp
index a332f02..8d6b7c5 100644
--- a/src/security/public-key.hpp
+++ b/src/security/public-key.hpp
@@ -18,8 +18,16 @@
 namespace ndn {
 
 class PublicKey {
-public:    
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
   /**
    * The default constructor.
@@ -49,36 +57,36 @@
   }
 
   void
-  encode(CryptoPP::BufferedTransformation &out) const;
+  encode(CryptoPP::BufferedTransformation& out) const;
 
   void
-  decode(CryptoPP::BufferedTransformation &in);
+  decode(CryptoPP::BufferedTransformation& in);
 
   // /*
   //  * Get the digest of the public key.
   //  * @param digestAlgorithm The digest algorithm. If omitted, use DIGEST_ALGORITHM_SHA256 by default.
   //  */
-  // Blob 
+  // Blob
   // getDigest(DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) const;
 
   inline bool
-  operator ==(const PublicKey &key) const
+  operator ==(const PublicKey& key) const
   {
     return key_ == key.key_;
   }
 
   inline bool
-  operator !=(const PublicKey &key) const
+  operator !=(const PublicKey& key) const
   {
     return key_ != key.key_;
   }
-  
+
 private:
   Buffer key_;
 };
 
-std::ostream &
-operator <<(std::ostream &os, const PublicKey &key);
+std::ostream&
+operator <<(std::ostream& os, const PublicKey& key);
 
 } // namespace ndn
 
diff --git a/src/security/sec-public-info-memory.cpp b/src/security/sec-public-info-memory.cpp
index 82affaa..f2a35ee 100644
--- a/src/security/sec-public-info-memory.cpp
+++ b/src/security/sec-public-info-memory.cpp
@@ -18,7 +18,7 @@
 {
 }
 
-bool 
+bool
 SecPublicInfoMemory::doesIdentityExist(const Name& identityName)
 {
   string identityUri = identityName.toUri();
@@ -31,11 +31,11 @@
   string identityUri = identityName.toUri();
   if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end())
     return;
-  
+
   identityStore_.push_back(identityUri);
 }
 
-bool 
+bool
 SecPublicInfoMemory::revokeIdentity()
 {
 #if 1
@@ -43,19 +43,19 @@
 #endif
 }
 
-bool 
+bool
 SecPublicInfoMemory::doesPublicKeyExist(const Name& keyName)
 {
   return keyStore_.find(keyName.toUri()) != keyStore_.end();
 }
 
-void 
+void
 SecPublicInfoMemory::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey)
 {
   Name identityName = keyName.getSubName(0, keyName.size() - 1);
 
   addIdentity(identityName);
-  
+
   keyStore_[keyName.toUri()] = make_shared<KeyRecord>(keyType, publicKey);
 }
 
@@ -65,7 +65,7 @@
   KeyStore::iterator record = keyStore_.find(keyName.toUri());
   if (record == keyStore_.end())
     throw Error("SecPublicInfoMemory::getPublicKey  " + keyName.toUri());
-  
+
   return make_shared<PublicKey> (record->second->getKey());
 }
 
@@ -75,7 +75,7 @@
   return certificateStore_.find(certificateName.toUri()) != certificateStore_.end();
 }
 
-void 
+void
 SecPublicInfoMemory::addCertificate(const IdentityCertificate& certificate)
 {
   const Name& certificateName = certificate.getName();
@@ -87,7 +87,7 @@
   certificateStore_[certificateName.toUri()] = make_shared<IdentityCertificate> (certificate);
 }
 
-shared_ptr<IdentityCertificate> 
+shared_ptr<IdentityCertificate>
 SecPublicInfoMemory::getCertificate(const Name& certificateName)
 {
   CertificateStore::iterator record = certificateStore_.find(certificateName.toUri());
@@ -97,13 +97,13 @@
   return record->second;
 }
 
-Name 
+Name
 SecPublicInfoMemory::getDefaultIdentity()
 {
   return Name(defaultIdentity_);
 }
 
-void 
+void
 SecPublicInfoMemory::setDefaultIdentityInternal(const Name& identityName)
 {
   string identityUri = identityName.toUri();
@@ -114,75 +114,75 @@
     defaultIdentity_.clear();
 }
 
-Name 
+Name
 SecPublicInfoMemory::getDefaultKeyNameForIdentity(const Name& identityName)
 {
   return defaultKeyName_;
 }
 
-void 
+void
 SecPublicInfoMemory::setDefaultKeyNameForIdentityInternal(const Name& keyName)
 {
   defaultKeyName_ = keyName;
 }
 
-Name 
+Name
 SecPublicInfoMemory::getDefaultCertificateNameForKey(const Name& keyName)
 {
   return defaultCert_;
 }
 
-void 
-SecPublicInfoMemory::setDefaultCertificateNameForKeyInternal(const Name& certificateName)  
+void
+SecPublicInfoMemory::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
 {
   defaultCert_ = certificateName;
 }
 
 
 void
-SecPublicInfoMemory::getAllIdentities(std::vector<Name> &nameList, bool isDefault)
+SecPublicInfoMemory::getAllIdentities(std::vector<Name>& nameList, bool isDefault)
 {
   throw Error("SecPublicInfoMemory::getAllIdentities not implemented");
 }
 
 void
-SecPublicInfoMemory::getAllKeyNames(std::vector<Name> &nameList, bool isDefault)
+SecPublicInfoMemory::getAllKeyNames(std::vector<Name>& nameList, bool isDefault)
 {
   throw Error("SecPublicInfoMemory::getAllKeyNames not implemented");
 }
 
 void
-SecPublicInfoMemory::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name> &nameList, bool isDefault)
+SecPublicInfoMemory::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault)
 {
   throw Error("SecPublicInfoMemory::getAllKeyNamesOfIdentity not implemented");
 }
-    
+
 void
-SecPublicInfoMemory::getAllCertificateNames(std::vector<Name> &nameList, bool isDefault)
+SecPublicInfoMemory::getAllCertificateNames(std::vector<Name>& nameList, bool isDefault)
 {
   throw Error("SecPublicInfoMemory::getAllCertificateNames not implemented");
 }
 
 void
-SecPublicInfoMemory::getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name> &nameList, bool isDefault)
+SecPublicInfoMemory::getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault)
 {
   throw Error("SecPublicInfoMemory::getAllCertificateNamesOfKey not implemented");
 }
 
 void
-SecPublicInfoMemory::deleteCertificateInfo(const Name &certName)
+SecPublicInfoMemory::deleteCertificateInfo(const Name& certName)
 {
   throw Error("SecPublicInfoMemory::deleteCertificateInfo not implemented");
 }
 
 void
-SecPublicInfoMemory::deletePublicKeyInfo(const Name &keyName)
+SecPublicInfoMemory::deletePublicKeyInfo(const Name& keyName)
 {
   throw Error("SecPublicInfoMemory::deletePublicKeyInfo not implemented");
 }
 
 void
-SecPublicInfoMemory::deleteIdentityInfo(const Name &identityName)
+SecPublicInfoMemory::deleteIdentityInfo(const Name& identityName)
 {
   throw Error("SecPublicInfoMemory::deleteIdentityInfo not implemented");
 }
diff --git a/src/security/sec-public-info-memory.hpp b/src/security/sec-public-info-memory.hpp
index 16001c8..58d8529 100644
--- a/src/security/sec-public-info-memory.hpp
+++ b/src/security/sec-public-info-memory.hpp
@@ -18,7 +18,15 @@
  */
 class SecPublicInfoMemory : public SecPublicInfo {
 public:
-  struct Error : public SecPublicInfo::Error { Error(const std::string &what) : SecPublicInfo::Error(what) {} };
+  class Error : public SecPublicInfo::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : SecPublicInfo::Error(what)
+    {
+    }
+  };
 
   virtual
   ~SecPublicInfoMemory();
@@ -32,10 +40,10 @@
   virtual bool
   revokeIdentity();
 
-  virtual bool 
+  virtual bool
   doesPublicKeyExist(const Name& keyName);
 
-  virtual void 
+  virtual void
   addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
 
   virtual ptr_lib::shared_ptr<PublicKey>
@@ -44,74 +52,74 @@
   virtual bool
   doesCertificateExist(const Name& certificateName);
 
-  virtual void 
+  virtual void
   addCertificate(const IdentityCertificate& certificate);
 
-  virtual ptr_lib::shared_ptr<IdentityCertificate> 
-  getCertificate(const Name &certificateName);
+  virtual ptr_lib::shared_ptr<IdentityCertificate>
+  getCertificate(const Name& certificateName);
 
 
-  virtual Name 
+  virtual Name
   getDefaultIdentity();
 
-  virtual Name 
+  virtual Name
   getDefaultKeyNameForIdentity(const Name& identityName);
 
-  virtual Name 
+  virtual Name
   getDefaultCertificateNameForKey(const Name& keyName);
 
   virtual void
-  getAllIdentities(std::vector<Name> &nameList, bool isDefault);
+  getAllIdentities(std::vector<Name>& nameList, bool isDefault);
 
   virtual void
-  getAllKeyNames(std::vector<Name> &nameList, bool isDefault);
+  getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
 
   virtual void
-  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name> &nameList, bool isDefault);
-    
-  virtual void
-  getAllCertificateNames(std::vector<Name> &nameList, bool isDefault);
+  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
 
   virtual void
-  getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name> &nameList, bool isDefault);
+  getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
+
+  virtual void
+  getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
 
 protected:
-  virtual void 
+  virtual void
   setDefaultIdentityInternal(const Name& identityName);
 
-  virtual void 
+  virtual void
   setDefaultKeyNameForIdentityInternal(const Name& keyName);
 
-  virtual void 
-  setDefaultCertificateNameForKeyInternal(const Name& certificateName);  
+  virtual void
+  setDefaultCertificateNameForKeyInternal(const Name& certificateName);
 
   virtual void
-  deleteCertificateInfo(const Name &certificateName);
+  deleteCertificateInfo(const Name& certificateName);
 
   virtual void
-  deletePublicKeyInfo(const Name &keyName);
+  deletePublicKeyInfo(const Name& keyName);
 
   virtual void
-  deleteIdentityInfo(const Name &identity);
+  deleteIdentityInfo(const Name& identity);
 
-  
+
 private:
   class KeyRecord {
   public:
-    KeyRecord(KeyType keyType, const PublicKey &key)
+    KeyRecord(KeyType keyType, const PublicKey& key)
     : keyType_(keyType), key_(key)
     {
     }
-    
+
     const KeyType getKeyType() const { return keyType_; }
-    
+
     const PublicKey& getKey() { return key_; }
-    
+
   private:
     KeyType   keyType_;
     PublicKey key_;
   };
-  
+
   std::vector<std::string> identityStore_; /**< A list of name URI. */
   std::string defaultIdentity_;            /**< The default identity in identityStore_, or "" if not defined. */
   Name defaultKeyName_;
@@ -119,9 +127,9 @@
 
   typedef std::map< std::string, ptr_lib::shared_ptr<KeyRecord> > KeyStore; /**< The map key is the keyName.toUri() */
   typedef std::map< std::string, ptr_lib::shared_ptr<IdentityCertificate> > CertificateStore; /**< The map key is the certificateName.toUri() */
-  
-  KeyStore keyStore_; 
-  CertificateStore certificateStore_;                    
+
+  KeyStore keyStore_;
+  CertificateStore certificateStore_;
 };
 
 } // namespace ndn
diff --git a/src/security/sec-public-info-sqlite3.cpp b/src/security/sec-public-info-sqlite3.cpp
index 712bf7d..b8b5af3 100644
--- a/src/security/sec-public-info-sqlite3.cpp
+++ b/src/security/sec-public-info-sqlite3.cpp
@@ -104,9 +104,9 @@
                             );
   if (res != SQLITE_OK)
     throw Error("identity DB cannot be opened/created");
-  
+
   //Check if Key table exists;
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT name FROM sqlite_master WHERE type='table' And name='Identity'", -1, &statement, 0);
   res = sqlite3_step(statement);
 
@@ -117,9 +117,9 @@
   sqlite3_finalize(statement);
 
   if (!idTableExists) {
-    char *errorMessage = 0;
+    char* errorMessage = 0;
     res = sqlite3_exec(m_database, INIT_ID_TABLE.c_str(), NULL, NULL, &errorMessage);
-      
+
     if (res != SQLITE_OK && errorMessage != 0) {
       _LOG_TRACE("Init \"error\" in Identity: " << errorMessage);
       sqlite3_free(errorMessage);
@@ -137,9 +137,9 @@
   sqlite3_finalize(statement);
 
   if (!keyTableExists) {
-    char *errorMessage = 0;
+    char* errorMessage = 0;
     res = sqlite3_exec(m_database, INIT_KEY_TABLE.c_str(), NULL, NULL, &errorMessage);
-      
+
     if (res != SQLITE_OK && errorMessage != 0) {
       _LOG_TRACE("Init \"error\" in KEY: " << errorMessage);
       sqlite3_free(errorMessage);
@@ -153,13 +153,13 @@
   bool idCertificateTableExists = false;
   if (res == SQLITE_ROW)
     idCertificateTableExists = true;
-  
+
   sqlite3_finalize(statement);
 
   if (!idCertificateTableExists) {
-    char *errorMessage = 0;
+    char* errorMessage = 0;
     res = sqlite3_exec(m_database, INIT_CERT_TABLE.c_str(), NULL, NULL, &errorMessage);
-      
+
     if (res != SQLITE_OK && errorMessage != 0) {
       _LOG_TRACE("Init \"error\" in ID-CERT: " << errorMessage);
       sqlite3_free(errorMessage);
@@ -171,59 +171,59 @@
 {
 }
 
-bool 
+bool
 SecPublicInfoSqlite3::doesIdentityExist(const Name& identityName)
 {
   bool result = false;
-  
-  sqlite3_stmt *statement;
+
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT count(*) FROM Identity WHERE identity_name=?", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
   int res = sqlite3_step(statement);
-  
+
   if (res == SQLITE_ROW) {
     int countAll = sqlite3_column_int(statement, 0);
     if (countAll > 0)
       result = true;
   }
- 
+
   sqlite3_finalize(statement);
 
   return result;
 }
 
-void 
+void
 SecPublicInfoSqlite3::addIdentity(const Name& identityName)
 {
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
 
   sqlite3_prepare_v2(m_database, "INSERT OR REPLACE INTO Identity (identity_name) values (?)", -1, &statement, 0);
-      
+
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
-  
+
   sqlite3_step(statement);
-  
+
   sqlite3_finalize(statement);
 }
 
-bool 
+bool
 SecPublicInfoSqlite3::revokeIdentity()
 {
   //TODO:
   return false;
 }
 
-bool 
+bool
 SecPublicInfoSqlite3::doesPublicKeyExist(const Name& keyName)
 {
-  if(keyName.empty())
+  if (keyName.empty())
     throw Error("Incorrect key name " + keyName.toUri());
 
   string keyId = keyName.get(-1).toEscapedString();
   Name identityName = keyName.getPrefix(-1);
 
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT count(*) FROM Key WHERE identity_name=? AND key_identifier=?", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
@@ -237,7 +237,7 @@
     if (countAll > 0)
       keyIdExist = true;
   }
- 
+
   sqlite3_finalize(statement);
 
   return keyIdExist;
@@ -246,7 +246,7 @@
 void
 SecPublicInfoSqlite3::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer)
 {
-  if(keyName.empty())
+  if (keyName.empty())
     return;
 
   string keyId = keyName.get(-1).toEscapedString();
@@ -254,7 +254,7 @@
 
   addIdentity(identityName);
 
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "INSERT OR REPLACE INTO Key (identity_name, key_identifier, key_type, public_key) values (?, ?, ?, ?)", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
@@ -270,7 +270,7 @@
 shared_ptr<PublicKey>
 SecPublicInfoSqlite3::getPublicKey(const Name& keyName)
 {
-  if (keyName.empty()) 
+  if (keyName.empty())
     {
       _LOG_DEBUG("SecPublicInfoSqlite3::getPublicKey  Empty keyName");
       throw Error("SecPublicInfoSqlite3::getPublicKey  Empty keyName");
@@ -278,8 +278,8 @@
 
   string keyId = keyName.get(-1).toEscapedString();
   Name identityName = keyName.getPrefix(-1);
-  
-  sqlite3_stmt *statement;
+
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT public_key FROM Key WHERE identity_name=? AND key_identifier=?", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
@@ -304,7 +304,7 @@
 bool
 SecPublicInfoSqlite3::doesCertificateExist(const Name& certificateName)
 {
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT count(*) FROM Certificate WHERE cert_name=?", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, certificateName.toUri(), SQLITE_TRANSIENT);
@@ -317,9 +317,9 @@
     if (countAll > 0)
       certExist = true;
   }
- 
+
   sqlite3_finalize(statement);
-  
+
   return certExist;
 }
 
@@ -329,14 +329,14 @@
 //   std::string certificateName = certificate.getName().toUri();
 //   Name keyName = IdentityCertificate::certificateNameToPublicKeyName(certificate.getName());
 
-//   if(keyName.empty())
+//   if (keyName.empty())
 //     return;
 
 //   std::string keyId = keyName.get(-1).toEscapedString();
 //   std::string identityName = keyName.getPrefix(-1).toUri();
 
-//   sqlite3_stmt *statement;
-//   sqlite3_prepare_v2(m_database, 
+//   sqlite3_stmt* statement;
+//   sqlite3_prepare_v2(m_database,
 //                       "INSERT OR REPLACE INTO Certificate (cert_name, cert_issuer, identity_name, key_identifier, not_before, not_after, certificate_data) "
 //                        "VALUES (?, ?, ?, ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)",
 //                       -1, &statement, 0);
@@ -351,12 +351,12 @@
 
 //       sqlite3_bind_text(statement, 2, signerName, SQLITE_STATIC);
 //     }
-//   catch(KeyLocator::Error& e)
+//   catch (KeyLocator::Error& e)
 //     {
 //       _LOG_DEBUG("SecPublicInfoSqlite3::addAnyCertificate unsupported keylocator type");
 //       return;
 //     }
-//   catch(SignatureSha256WithRsa::Error& e)
+//   catch (SignatureSha256WithRsa::Error& e)
 //     {
 //       _LOG_DEBUG("SecPublicInfoSqlite3::addAnyCertificate unsupported signature type");
 //       return;
@@ -378,11 +378,11 @@
 //   sqlite3_finalize(statement);
 // }
 
-void 
+void
 SecPublicInfoSqlite3::addCertificate(const IdentityCertificate& certificate)
 {
   const Name& certificateName = certificate.getName();
-  Name keyName = 
+  Name keyName =
     IdentityCertificate::certificateNameToPublicKeyName(certificate.getName()); // KeyName is from IdentityCertificate name, so should be qualified.
 
   addPublicKey(keyName, KEY_TYPE_RSA, certificate.getPublicKeyInfo()); //HACK!!! Assume the key type is RSA, we should check more.
@@ -391,8 +391,8 @@
   Name identity = keyName.getPrefix(-1);
 
   // Insert the certificate
-  sqlite3_stmt *statement;
-  sqlite3_prepare_v2(m_database, 
+  sqlite3_stmt* statement;
+  sqlite3_prepare_v2(m_database,
                       "INSERT OR REPLACE INTO Certificate (cert_name, cert_issuer, identity_name, key_identifier, not_before, not_after, certificate_data)\
                        values (?, ?, ?, ?, datetime(?, 'unixepoch'), datetime(?, 'unixepoch'), ?)",
                       -1, &statement, 0);
@@ -408,12 +408,12 @@
 
       sqlite3_bind_text(statement, 2, signerName, SQLITE_STATIC);
     }
-  catch(KeyLocator::Error& e)
+  catch (KeyLocator::Error& e)
     {
       _LOG_DEBUG("SecPublicInfoSqlite3::addAnyCertificate unsupported keylocator type");
       return;
     }
-  catch(SignatureSha256WithRsa::Error& e)
+  catch (SignatureSha256WithRsa::Error& e)
     {
       _LOG_DEBUG("SecPublicInfoSqlite3::addAnyCertificate unsupported signature type");
       return;
@@ -434,19 +434,19 @@
   sqlite3_finalize(statement);
 }
 
-shared_ptr<IdentityCertificate> 
-SecPublicInfoSqlite3::getCertificate(const Name &certificateName)
+shared_ptr<IdentityCertificate>
+SecPublicInfoSqlite3::getCertificate(const Name& certificateName)
 {
-  sqlite3_stmt *statement;
-  
-  sqlite3_prepare_v2(m_database, 
+  sqlite3_stmt* statement;
+
+  sqlite3_prepare_v2(m_database,
                      "SELECT certificate_data FROM Certificate WHERE cert_name=?",
                      -1, &statement, 0);
-  
+
   sqlite3_bind_text(statement, 1, certificateName.toUri(), SQLITE_TRANSIENT);
-  
+
   int res = sqlite3_step(statement);
-  
+
   if (res == SQLITE_ROW)
     {
       shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>();
@@ -461,16 +461,16 @@
       throw Error("SecPublicInfoSqlite3::getCertificate  certificate does not exist");
     }
 }
- 
 
-Name 
+
+Name
 SecPublicInfoSqlite3::getDefaultIdentity()
 {
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT identity_name FROM Identity WHERE default_identity=1", -1, &statement, 0);
 
   int res = sqlite3_step(statement);
-      
+
   if (res == SQLITE_ROW)
     {
       Name identity = Name(string(reinterpret_cast<const char *>(sqlite3_column_text(statement, 0)), sqlite3_column_bytes(statement, 0)));
@@ -484,35 +484,35 @@
     }
 }
 
-void 
+void
 SecPublicInfoSqlite3::setDefaultIdentityInternal(const Name& identityName)
 {
   addIdentity(identityName);
 
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
 
   //Reset previous default identity
   sqlite3_prepare_v2(m_database, "UPDATE Identity SET default_identity=0 WHERE default_identity=1", -1, &statement, 0);
 
   while (sqlite3_step(statement) == SQLITE_ROW)
     {}
-  
+
   sqlite3_finalize(statement);
 
   //Set current default identity
   sqlite3_prepare_v2(m_database, "UPDATE Identity SET default_identity=1 WHERE identity_name=?", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
-  
+
   sqlite3_step(statement);
 
   sqlite3_finalize(statement);
 }
 
-Name 
+Name
 SecPublicInfoSqlite3::getDefaultKeyNameForIdentity(const Name& identityName)
 {
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT key_identifier FROM Key WHERE identity_name=? AND default_key=1", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
@@ -521,7 +521,7 @@
 
   if (res == SQLITE_ROW)
     {
-      Name keyName = Name(identityName).append(string(reinterpret_cast<const char *>(sqlite3_column_text(statement, 0)), 
+      Name keyName = Name(identityName).append(string(reinterpret_cast<const char *>(sqlite3_column_text(statement, 0)),
                                                       sqlite3_column_bytes(statement, 0)));
       sqlite3_finalize(statement);
       return keyName;
@@ -533,16 +533,16 @@
     }
 }
 
-void 
+void
 SecPublicInfoSqlite3::setDefaultKeyNameForIdentityInternal(const Name& keyName)
 {
-  if(!doesPublicKeyExist(keyName))
+  if (!doesPublicKeyExist(keyName))
     throw Error("SecPublicInfoSqlite3::setDefaultKeyNameForIdentityInternal Key does not exist:" + keyName.toUri());
 
   string keyId = keyName.get(-1).toEscapedString();
   Name identityName = keyName.getPrefix(-1);
 
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
 
   //Reset previous default Key
   sqlite3_prepare_v2(m_database, "UPDATE Key SET default_key=0 WHERE default_key=1 and identity_name=?", -1, &statement, 0);
@@ -551,7 +551,7 @@
 
   while (sqlite3_step(statement) == SQLITE_ROW)
     {}
-  
+
   sqlite3_finalize(statement);
 
   //Set current default Key
@@ -559,22 +559,22 @@
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
   sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
-  
+
   sqlite3_step(statement);
 
   sqlite3_finalize(statement);
 }
 
-Name 
+Name
 SecPublicInfoSqlite3::getDefaultCertificateNameForKey(const Name& keyName)
 {
-  if(keyName.empty())
+  if (keyName.empty())
     throw Error("SecPublicInfoSqlite3::getDefaultCertificateNameForKey wrong key");
 
   string keyId = keyName.get(-1).toEscapedString();
   Name identityName = keyName.getPrefix(-1);
 
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
   sqlite3_prepare_v2(m_database, "SELECT cert_name FROM Certificate WHERE identity_name=? AND key_identifier=? AND default_cert=1", -1, &statement, 0);
 
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
@@ -595,17 +595,17 @@
     }
 }
 
-void 
+void
 SecPublicInfoSqlite3::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
 {
-  if(!doesCertificateExist(certificateName))
+  if (!doesCertificateExist(certificateName))
     throw Error("SecPublicInfoSqlite3::setDefaultCertificateNameForKeyInternal  certificate does not exist:" + certificateName.toUri());
 
   Name keyName = IdentityCertificate::certificateNameToPublicKeyName(certificateName);
   string keyId = keyName.get(-1).toEscapedString();
   Name identityName = keyName.getPrefix(-1);
 
-  sqlite3_stmt *statement;
+  sqlite3_stmt* statement;
 
   //Reset previous default Key
   sqlite3_prepare_v2(m_database, "UPDATE Certificate SET default_cert=0 WHERE default_cert=1 AND identity_name=? AND key_identifier=?", -1, &statement, 0);
@@ -615,7 +615,7 @@
 
   while (sqlite3_step(statement) == SQLITE_ROW)
     {}
-  
+
   sqlite3_finalize(statement);
 
   //Set current default Key
@@ -624,32 +624,32 @@
   sqlite3_bind_text(statement, 1, identityName.toUri(), SQLITE_TRANSIENT);
   sqlite3_bind_text(statement, 2, keyId, SQLITE_TRANSIENT);
   sqlite3_bind_text(statement, 3, certificateName.toUri(), SQLITE_TRANSIENT);
-  
+
   sqlite3_step(statement);
 
   sqlite3_finalize(statement);
 }
 
 void
-SecPublicInfoSqlite3::getAllIdentities(vector<Name> &nameList, bool isDefault)
+SecPublicInfoSqlite3::getAllIdentities(vector<Name>& nameList, bool isDefault)
 {
-  sqlite3_stmt *stmt;
-  if(isDefault)
+  sqlite3_stmt* stmt;
+  if (isDefault)
     sqlite3_prepare_v2 (m_database, "SELECT identity_name FROM Identity WHERE default_identity=1", -1, &stmt, 0);
   else
     sqlite3_prepare_v2 (m_database, "SELECT identity_name FROM Identity WHERE default_identity=0", -1, &stmt, 0);
 
   while(sqlite3_step (stmt) == SQLITE_ROW)
     nameList.push_back(Name(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0))));
-        
-  sqlite3_finalize (stmt);        
+
+  sqlite3_finalize (stmt);
 }
 
 void
-SecPublicInfoSqlite3::getAllKeyNames(vector<Name> &nameList, bool isDefault)
+SecPublicInfoSqlite3::getAllKeyNames(vector<Name>& nameList, bool isDefault)
 {
-  sqlite3_stmt *stmt;
-  if(isDefault)
+  sqlite3_stmt* stmt;
+  if (isDefault)
     sqlite3_prepare_v2 (m_database, "SELECT identity_name, key_identifier FROM Key WHERE default_key=1", -1, &stmt, 0);
   else
     sqlite3_prepare_v2 (m_database, "SELECT identity_name, key_identifier FROM Key WHERE default_key=0", -1, &stmt, 0);
@@ -659,19 +659,19 @@
       Name keyName(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
       keyName.append(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
       nameList.push_back(keyName);
-    } 
-  sqlite3_finalize (stmt);        
+    }
+  sqlite3_finalize (stmt);
 }
 
 void
-SecPublicInfoSqlite3::getAllKeyNamesOfIdentity(const Name& identity, vector<Name> &nameList, bool isDefault)
+SecPublicInfoSqlite3::getAllKeyNamesOfIdentity(const Name& identity, vector<Name>& nameList, bool isDefault)
 {
-  sqlite3_stmt *stmt;
-  if(isDefault)
+  sqlite3_stmt* stmt;
+  if (isDefault)
     sqlite3_prepare_v2 (m_database, "SELECT key_identifier FROM Key WHERE default_key=1 and identity_name=?", -1, &stmt, 0);
   else
     sqlite3_prepare_v2 (m_database, "SELECT key_identifier FROM Key WHERE default_key=0 and identity_name=?", -1, &stmt, 0);
-    
+
   sqlite3_bind_text(stmt, 1, identity.toUri().c_str(),  identity.toUri().size (),  SQLITE_TRANSIENT);
 
   while(sqlite3_step (stmt) == SQLITE_ROW)
@@ -679,15 +679,15 @@
       Name keyName(identity);
       keyName.append(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
       nameList.push_back(keyName);
-    } 
-  sqlite3_finalize (stmt);        
+    }
+  sqlite3_finalize (stmt);
 }
-    
+
 void
-SecPublicInfoSqlite3::getAllCertificateNames(vector<Name> &nameList, bool isDefault)
+SecPublicInfoSqlite3::getAllCertificateNames(vector<Name>& nameList, bool isDefault)
 {
-  sqlite3_stmt *stmt;
-  if(isDefault)
+  sqlite3_stmt* stmt;
+  if (isDefault)
     sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=1", -1, &stmt, 0);
   else
     sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=0", -1, &stmt, 0);
@@ -695,17 +695,17 @@
   while(sqlite3_step (stmt) == SQLITE_ROW)
     nameList.push_back(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
 
-  sqlite3_finalize (stmt);        
+  sqlite3_finalize (stmt);
 }
 
 void
-SecPublicInfoSqlite3::getAllCertificateNamesOfKey(const Name& keyName, vector<Name> &nameList, bool isDefault)
+SecPublicInfoSqlite3::getAllCertificateNamesOfKey(const Name& keyName, vector<Name>& nameList, bool isDefault)
 {
-  if(keyName.empty())
+  if (keyName.empty())
     return;
 
-  sqlite3_stmt *stmt;
-  if(isDefault)
+  sqlite3_stmt* stmt;
+  if (isDefault)
     sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=1 and identity_name=? and key_identifier=?", -1, &stmt, 0);
   else
     sqlite3_prepare_v2 (m_database, "SELECT cert_name FROM Certificate WHERE default_cert=0 and identity_name=? and key_identifier=?", -1, &stmt, 0);
@@ -718,16 +718,16 @@
   while(sqlite3_step (stmt) == SQLITE_ROW)
     nameList.push_back(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
 
-  sqlite3_finalize (stmt);        
+  sqlite3_finalize (stmt);
 }
 
 void
-SecPublicInfoSqlite3::deleteCertificateInfo(const Name &certName)
+SecPublicInfoSqlite3::deleteCertificateInfo(const Name& certName)
 {
-  if(certName.empty())
+  if (certName.empty())
     return;
-  
-  sqlite3_stmt *stmt;
+
+  sqlite3_stmt* stmt;
   sqlite3_prepare_v2(m_database, "DELETE FROM Certificate WHERE cert_name=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, certName.toUri().c_str(),  certName.toUri().size (),  SQLITE_TRANSIENT);
   sqlite3_step(stmt);
@@ -735,15 +735,15 @@
 }
 
 void
-SecPublicInfoSqlite3::deletePublicKeyInfo(const Name &keyName)
+SecPublicInfoSqlite3::deletePublicKeyInfo(const Name& keyName)
 {
-  if(keyName.empty())
+  if (keyName.empty())
     return;
 
   string identity = keyName.getPrefix(-1).toUri();
   string keyId = keyName.get(-1).toEscapedString();
 
-  sqlite3_stmt *stmt;
+  sqlite3_stmt* stmt;
   sqlite3_prepare_v2(m_database, "DELETE FROM Certificate WHERE identity_name=? and key_identifier=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size (), SQLITE_TRANSIENT);
   sqlite3_bind_text(stmt, 2, keyId.c_str(), keyId.size(), SQLITE_TRANSIENT);
@@ -758,11 +758,11 @@
 }
 
 void
-SecPublicInfoSqlite3::deleteIdentityInfo(const Name &identityName)
+SecPublicInfoSqlite3::deleteIdentityInfo(const Name& identityName)
 {
   string identity = identityName.toUri();
 
-  sqlite3_stmt *stmt;
+  sqlite3_stmt* stmt;
   sqlite3_prepare_v2(m_database, "DELETE FROM Certificate WHERE identity_name=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, identity.c_str(), identity.size (), SQLITE_TRANSIENT);
   sqlite3_step(stmt);
@@ -780,4 +780,3 @@
 }
 
 } // namespace ndn
-
diff --git a/src/security/sec-public-info-sqlite3.hpp b/src/security/sec-public-info-sqlite3.hpp
index feb07a5..b89859a 100644
--- a/src/security/sec-public-info-sqlite3.hpp
+++ b/src/security/sec-public-info-sqlite3.hpp
@@ -15,32 +15,40 @@
 struct sqlite3;
 
 namespace ndn {
-  
+
 class SecPublicInfoSqlite3 : public SecPublicInfo {
 public:
-  struct Error : public SecPublicInfo::Error { Error(const std::string &what) : SecPublicInfo::Error(what) {} };
+  class Error : public SecPublicInfo::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : SecPublicInfo::Error(what)
+    {
+    }
+  };
 
   SecPublicInfoSqlite3();
-  
-  virtual 
+
+  virtual
   ~SecPublicInfoSqlite3();
 
   /**********************
    * from SecPublicInfo *
    **********************/
-  virtual bool 
+  virtual bool
   doesIdentityExist(const Name& identityName);
 
   virtual void
   addIdentity(const Name& identityName);
 
-  virtual bool 
+  virtual bool
   revokeIdentity();
 
-  virtual bool 
+  virtual bool
   doesPublicKeyExist(const Name& keyName);
 
-  virtual void 
+  virtual void
   addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
 
   virtual ptr_lib::shared_ptr<PublicKey>
@@ -49,57 +57,57 @@
   virtual bool
   doesCertificateExist(const Name& certificateName);
 
-  virtual void 
+  virtual void
   addCertificate(const IdentityCertificate& certificate);
 
-  virtual ptr_lib::shared_ptr<IdentityCertificate> 
-  getCertificate(const Name &certificateName);
+  virtual ptr_lib::shared_ptr<IdentityCertificate>
+  getCertificate(const Name& certificateName);
 
 
 
-  virtual Name 
+  virtual Name
   getDefaultIdentity();
 
-  virtual Name 
+  virtual Name
   getDefaultKeyNameForIdentity(const Name& identityName);
 
-  virtual Name 
+  virtual Name
   getDefaultCertificateNameForKey(const Name& keyName);
 
   virtual void
-  getAllIdentities(std::vector<Name> &nameList, bool isDefault);
+  getAllIdentities(std::vector<Name>& nameList, bool isDefault);
 
   virtual void
-  getAllKeyNames(std::vector<Name> &nameList, bool isDefault);
+  getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
 
   virtual void
-  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name> &nameList, bool isDefault);
-    
-  virtual void
-  getAllCertificateNames(std::vector<Name> &nameList, bool isDefault);
+  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
 
   virtual void
-  getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name> &nameList, bool isDefault);
-  
+  getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
+
+  virtual void
+  getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
+
 protected:
-  virtual void 
+  virtual void
   setDefaultIdentityInternal(const Name& identityName);
 
   virtual void
   setDefaultKeyNameForIdentityInternal(const Name& keyName);
 
-  virtual void 
-  setDefaultCertificateNameForKeyInternal(const Name& certificateName);  
+  virtual void
+  setDefaultCertificateNameForKeyInternal(const Name& certificateName);
 
   virtual void
-  deleteCertificateInfo(const Name &certificateName);
+  deleteCertificateInfo(const Name& certificateName);
 
   virtual void
-  deletePublicKeyInfo(const Name &keyName);
+  deletePublicKeyInfo(const Name& keyName);
 
   virtual void
-  deleteIdentityInfo(const Name &identity);
-  
+  deleteIdentityInfo(const Name& identity);
+
 private:
   sqlite3 * m_database;
 };
diff --git a/src/security/sec-public-info.hpp b/src/security/sec-public-info.hpp
index 0861b67..5fe7b3c 100644
--- a/src/security/sec-public-info.hpp
+++ b/src/security/sec-public-info.hpp
@@ -24,12 +24,20 @@
  */
 class SecPublicInfo {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
   /**
    * @brief The virtual Destructor.
    */
-  virtual 
+  virtual
   ~SecPublicInfo() {}
 
   /**
@@ -38,7 +46,7 @@
    * @param identityName The identity name.
    * @return true if the identity exists, otherwise false.
    */
-  virtual bool 
+  virtual bool
   doesIdentityExist(const Name& identityName) = 0;
 
   /**
@@ -56,7 +64,7 @@
    *
    * @return true if the identity was revoked, otherwise false.
    */
-  virtual bool 
+  virtual bool
   revokeIdentity() = 0;
 
   /**
@@ -65,7 +73,7 @@
    * @param keyName The name of the key.
    * @return true if the key exists, otherwise false.
    */
-  virtual bool 
+  virtual bool
   doesPublicKeyExist(const Name& keyName) = 0;
 
   /**
@@ -75,7 +83,7 @@
    * @param keyType Type of the public key to be added.
    * @param publicKeyDer A blob of the public key DER to be added.
    */
-  virtual void 
+  virtual void
   addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer) = 0;
 
   /**
@@ -104,18 +112,18 @@
    *
    * @param certificate The certificate to be added.
    */
-  virtual void 
+  virtual void
   addCertificate(const IdentityCertificate& certificate) = 0;
 
   /**
    * @brief Get a certificate from the identity storage.
    *
    * @param certificateName The name of the requested certificate.
-   * @return The requested certificate.  
+   * @return The requested certificate.
    * @throws SecPublicInfo::Error if the certificate does not exist.
    */
-  virtual shared_ptr<IdentityCertificate> 
-  getCertificate(const Name &certificateName) = 0;
+  virtual shared_ptr<IdentityCertificate>
+  getCertificate(const Name& certificateName) = 0;
 
 
   /*****************************************
@@ -123,12 +131,12 @@
    *****************************************/
 
   /**
-   * @brief Get the default identity. 
+   * @brief Get the default identity.
    *
-   * @param return The name of default identity, 
+   * @param return The name of default identity,
    * @throws SecPublicInfo::Error if there is no default.
    */
-  virtual Name 
+  virtual Name
   getDefaultIdentity() = 0;
 
   /**
@@ -138,7 +146,7 @@
    * @return The default key name.
    * @throws SecPublicInfo::Error if there is no default.
    */
-  virtual Name 
+  virtual Name
   getDefaultKeyNameForIdentity(const Name& identityName) = 0;
 
   /**
@@ -148,7 +156,7 @@
    * @return The default certificate name.
    * @throws SecPublicInfo::Error if there is no default.
    */
-  virtual Name 
+  virtual Name
   getDefaultCertificateNameForKey(const Name& keyName) = 0;
 
   /**
@@ -158,7 +166,7 @@
    * @param isDefault If specified, only the default identity is returned.
    */
   virtual void
-  getAllIdentities(std::vector<Name> &nameList, bool isDefault) = 0;
+  getAllIdentities(std::vector<Name>& nameList, bool isDefault) = 0;
 
   /**
    * @brief Get all the key name in public info.
@@ -167,7 +175,7 @@
    * @param isDefault If specified, only the default keys are returned.
    */
   virtual void
-  getAllKeyNames(std::vector<Name> &nameList, bool isDefault) = 0;
+  getAllKeyNames(std::vector<Name>& nameList, bool isDefault) = 0;
 
   /**
    * @brief Get all the key name of a particular identity.
@@ -177,7 +185,7 @@
    * @param isDefault If specified, only the default key is returned.
    */
   virtual void
-  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name> &nameList, bool isDefault) = 0;
+  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault) = 0;
 
   /**
    * @brief Get all the certificate name in public info.
@@ -186,8 +194,8 @@
    * @param isDefault If specified, only the default certificates are returned.
    */
   virtual void
-  getAllCertificateNames(std::vector<Name> &nameList, bool isDefault) = 0;
-    
+  getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) = 0;
+
   /**
    * @brief Get all the certificate name of a particular key.
    *
@@ -196,25 +204,25 @@
    * @param isDefault If specified, only the default certificate is returned.
    */
   virtual void
-  getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name> &nameList, bool isDefault) = 0;
+  getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault) = 0;
 
 protected:
 
   /*****************************************
    *            Default Setter             *
    *****************************************/
-  
+
   /**
    * @brief Set the default identity.
    *
    * @param identityName The default identity name.
    */
-  virtual void 
+  virtual void
   setDefaultIdentityInternal(const Name& identityName) = 0;
-  
+
   /**
    * @brief Set the default key name for the corresponding identity.
-   * 
+   *
    * @param keyName The key name.
    * @throws SecPublicInfo::Error if the key does not exist.
    */
@@ -227,8 +235,8 @@
    * @param certificateName The certificate name.
    * @throws SecPublicInfo::Error if the certificatedoes not exist.
    */
-  virtual void 
-  setDefaultCertificateNameForKeyInternal(const Name& certificateName) = 0; 
+  virtual void
+  setDefaultCertificateNameForKeyInternal(const Name& certificateName) = 0;
 
   /*****************************************
    *            Delete Methods             *
@@ -240,7 +248,7 @@
    * @param certificateName The certificate name.
    */
   virtual void
-  deleteCertificateInfo(const Name &certificateName) = 0;
+  deleteCertificateInfo(const Name& certificateName) = 0;
 
   /**
    * @brief Delete a public key and related certificates.
@@ -248,7 +256,7 @@
    * @param keyName The key name.
    */
   virtual void
-  deletePublicKeyInfo(const Name &keyName) = 0;
+  deletePublicKeyInfo(const Name& keyName) = 0;
 
   /**
    * @brief Delete an identity and related public keys and certificates.
@@ -256,30 +264,30 @@
    * @param identity The identity name.
    */
   virtual void
-  deleteIdentityInfo(const Name &identity) = 0;
+  deleteIdentityInfo(const Name& identity) = 0;
 
 public:
-  
+
   /*****************************************
    *            Helper Methods             *
    *****************************************/
 
   /**
-   * @brief Set the default identity.  
+   * @brief Set the default identity.
    *
    * @param identityName The default identity name.
    * @throws SecPublicInfo::Error if the identity does not exist.
    */
-  inline void 
+  inline void
   setDefaultIdentity(const Name& identityName);
 
   /**
    * @brief Set the default key name for the corresponding identity.
-   * 
+   *
    * @param keyName The key name.
    * @throws SecPublicInfo::Error if either the identity or key does not exist.
    */
-  inline void 
+  inline void
   setDefaultKeyNameForIdentity(const Name& keyName);
 
   /**
@@ -288,8 +296,8 @@
    * @param certificateName The certificate name.
    * @throws SecPublicInfo::Error if either the certificate or key does not exist.
    */
-  inline void 
-  setDefaultCertificateNameForKey(const Name& certificateName); 
+  inline void
+  setDefaultCertificateNameForKey(const Name& certificateName);
 
   /**
    * @brief Generate a key name for the identity.
@@ -298,7 +306,7 @@
    * @param useKsk If true, generate a KSK name, otherwise a DSK name.
    * @return The generated key name.
    */
-  inline Name 
+  inline Name
   getNewKeyName(const Name& identityName, bool useKsk);
 
   /**
@@ -308,7 +316,7 @@
    * @return The default certificate name.
    * @throws SecPublicInfo::Error if no certificate is found.
    */
-  inline Name 
+  inline Name
   getDefaultCertificateNameForIdentity(const Name& identityName);
 
   /**
@@ -354,7 +362,7 @@
    */
   inline shared_ptr<IdentityCertificate>
   defaultCertificate();
-  
+
   /**
    * @brief try to get the default certificate of the default identity from the public info.
    */
@@ -379,14 +387,14 @@
   refreshDefaultCertificate();
 }
 
-inline void 
+inline void
 SecPublicInfo::setDefaultCertificateNameForKey(const Name& certificateName)
 {
   setDefaultCertificateNameForKeyInternal(certificateName);
   refreshDefaultCertificate();
 }
 
-inline Name 
+inline Name
 SecPublicInfo::getDefaultCertificateNameForIdentity(const Name& identityName)
 {
   return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName));
@@ -403,7 +411,7 @@
     oss << "dsk-";
 
   oss << time::toUnixTimestamp(time::system_clock::now()).count();
-  
+
   Name keyName = Name(identityName).append(oss.str());
 
   if (doesPublicKeyExist(keyName))
@@ -415,10 +423,10 @@
 inline Name
 SecPublicInfo::getDefaultCertificateName()
 {
-  if(!static_cast<bool>(m_defaultCertificate))
+  if (!static_cast<bool>(m_defaultCertificate))
     refreshDefaultCertificate();
 
-  if(!static_cast<bool>(m_defaultCertificate))
+  if (!static_cast<bool>(m_defaultCertificate))
     throw Error("No default certificate is set");
 
   return m_defaultCertificate->getName();
@@ -437,7 +445,7 @@
 {
   addCertificate(certificate);
   Name certName = certificate.getName();
-  setDefaultKeyNameForIdentityInternal(IdentityCertificate::certificateNameToPublicKeyName(certName)); 
+  setDefaultKeyNameForIdentityInternal(IdentityCertificate::certificateNameToPublicKeyName(certName));
   setDefaultCertificateNameForKeyInternal(certName);
   refreshDefaultCertificate();
 }
@@ -468,7 +476,7 @@
       Name certName = getDefaultCertificateNameForIdentity(getDefaultIdentity());
       m_defaultCertificate = getCertificate(certName);
     }
-  catch(SecPublicInfo::Error& e)
+  catch (SecPublicInfo::Error& e)
     {
       m_defaultCertificate.reset();
     }
diff --git a/src/security/sec-rule-relative.cpp b/src/security/sec-rule-relative.cpp
index 1fdfa7d..6133aac 100644
--- a/src/security/sec-rule-relative.cpp
+++ b/src/security/sec-rule-relative.cpp
@@ -20,7 +20,7 @@
 
 namespace ndn {
 
-SecRuleRelative::SecRuleRelative (const string& dataRegex, const string& signerRegex, const string& op, 
+SecRuleRelative::SecRuleRelative (const string& dataRegex, const string& signerRegex, const string& op,
                                   const string& dataExpand, const string& signerExpand, bool isPositive)
   : SecRule(isPositive),
     m_dataRegex(dataRegex),
@@ -31,68 +31,73 @@
     m_dataNameRegex(dataRegex, dataExpand),
     m_signerNameRegex(signerRegex, signerExpand)
 {
-  if(op != ">" && op != ">=" && op != "==")
+  if (op != ">" && op != ">=" && op != "==")
     throw Error("op is wrong!");
 }
 
 SecRuleRelative::~SecRuleRelative()
-{ }
+{
+}
 
-bool 
+bool
 SecRuleRelative::satisfy (const Data& data)
 {
   Name dataName = data.getName();
-  try{
+  try {
     SignatureSha256WithRsa sig(data.getSignature());
     Name signerName = sig.getKeyLocator().getName ();
-    return satisfy (dataName, signerName); 
-  }catch(SignatureSha256WithRsa::Error &e){
+    return satisfy (dataName, signerName);
+  }
+  catch (SignatureSha256WithRsa::Error& e){
     return false;
-  }catch(KeyLocator::Error &e){
+  }
+  catch (KeyLocator::Error& e){
     return false;
   }
 }
-  
-bool 
+
+bool
 SecRuleRelative::satisfy (const Name& dataName, const Name& signerName)
 {
-  if(!m_dataNameRegex.match(dataName))
+  if (!m_dataNameRegex.match(dataName))
     return false;
   Name expandDataName = m_dataNameRegex.expand();
 
-  if(!m_signerNameRegex.match(signerName))
+  if (!m_signerNameRegex.match(signerName))
     return false;
   Name expandSignerName =  m_signerNameRegex.expand();
-  
+
   bool matched = compare(expandDataName, expandSignerName);
-  
+
   return matched;
 }
 
-bool 
+bool
 SecRuleRelative::matchDataName (const Data& data)
 { return m_dataNameRegex.match(data.getName()); }
 
 bool
 SecRuleRelative::matchSignerName (const Data& data)
-{    
-  try{
+{
+  try {
     SignatureSha256WithRsa sig(data.getSignature());
     Name signerName = sig.getKeyLocator().getName ();
-    return m_signerNameRegex.match(signerName); 
-  }catch(SignatureSha256WithRsa::Error &e){
+    return m_signerNameRegex.match(signerName);
+  }
+  catch (SignatureSha256WithRsa::Error& e){
     return false;
-  }catch(KeyLocator::Error &e){
+  }
+  catch (KeyLocator::Error& e){
     return false;
   }
 }
 
-bool 
-SecRuleRelative::compare(const Name & dataName, const Name & signerName)
-{  
-  if((dataName == signerName) && ("==" == m_op || ">=" == m_op))
+bool
+SecRuleRelative::compare(const Name& dataName, const Name& signerName)
+{
+  if ((dataName == signerName) && ("==" == m_op || ">=" == m_op))
     return true;
-    
+
   Name::const_iterator i = dataName.begin ();
   Name::const_iterator j = signerName.begin ();
 
@@ -103,10 +108,10 @@
       else
         return false;
     }
-    
-  if(i == dataName.end())
+
+  if (i == dataName.end())
     return false;
-  else 
+  else
     return true;
 }
 
diff --git a/src/security/sec-rule-relative.hpp b/src/security/sec-rule-relative.hpp
index 59c8f09..7ea4c51 100644
--- a/src/security/sec-rule-relative.hpp
+++ b/src/security/sec-rule-relative.hpp
@@ -13,41 +13,49 @@
 #include "../util/regex.hpp"
 
 namespace ndn {
-  
+
 class SecRuleRelative : public SecRule
 {
 public:
-  struct Error : public SecRule::Error { Error(const std::string &what) : SecRule::Error(what) {} };
-  
-  SecRuleRelative(const std::string& dataRegex, const std::string& signerRegex, const std::string& op, 
+  class Error : public SecRule::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : SecRule::Error(what)
+    {
+    }
+  };
+
+  SecRuleRelative(const std::string& dataRegex, const std::string& signerRegex, const std::string& op,
                   const std::string& dataExpand, const std::string& signerExpand, bool isPositive);
-  
+
   virtual
   ~SecRuleRelative();
-  
-  virtual bool 
+
+  virtual bool
   matchDataName(const Data& data);
-  
-  virtual bool 
+
+  virtual bool
   matchSignerName(const Data& data);
-  
+
   virtual bool
   satisfy(const Data& data);
-  
+
   virtual bool
   satisfy(const Name& dataName, const Name& signerName);
-  
+
 private:
-  bool 
+  bool
   compare(const Name& dataName, const Name& signerName);
-  
+
 private:
   const std::string m_dataRegex;
   const std::string m_signerRegex;
   const std::string m_op;
   const std::string m_dataExpand;
   const std::string m_signerExpand;
-  
+
   Regex m_dataNameRegex;
   Regex m_signerNameRegex;
 };
diff --git a/src/security/sec-rule-specific.cpp b/src/security/sec-rule-specific.cpp
index 484a08e..a9fee4e 100644
--- a/src/security/sec-rule-specific.cpp
+++ b/src/security/sec-rule-specific.cpp
@@ -27,34 +27,36 @@
   , m_signerRegex(rule.m_signerRegex)
 {}
 
-bool 
+bool
 SecRuleSpecific::matchDataName(const Data& data)
 { return m_dataRegex->match(data.getName()); }
 
-bool 
+bool
 SecRuleSpecific::matchSignerName(const Data& data)
-{ 
-  try{
+{
+  try {
     SignatureSha256WithRsa sig(data.getSignature());
     Name signerName = sig.getKeyLocator().getName ();
-    return m_signerRegex->match(signerName); 
-  }catch(SignatureSha256WithRsa::Error &e){
+    return m_signerRegex->match(signerName);
+  }
+  catch (SignatureSha256WithRsa::Error& e) {
     return false;
-  }catch(KeyLocator::Error &e){
+  }
+  catch (KeyLocator::Error& e) {
     return false;
   }
 }
 
 bool
-SecRuleSpecific::satisfy(const Data & data)
-{ 
-  return (matchDataName(data) && matchSignerName(data)) ? true : false ; 
+SecRuleSpecific::satisfy(const Data& data)
+{
+  return (matchDataName(data) && matchSignerName(data)) ? true : false;
 }
 
 bool
-SecRuleSpecific::satisfy(const Name & dataName, const Name & signerName)
-{ 
-  return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); 
+SecRuleSpecific::satisfy(const Name& dataName, const Name& signerName)
+{
+  return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName));
 }
 
 } // namespace ndn
diff --git a/src/security/sec-rule.hpp b/src/security/sec-rule.hpp
index 496b33d..ecb9686 100644
--- a/src/security/sec-rule.hpp
+++ b/src/security/sec-rule.hpp
@@ -16,31 +16,39 @@
 class SecRule
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
-  
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
+
   SecRule(bool isPositive)
   : m_isPositive(isPositive)
   {}
-  
-  virtual 
-  ~SecRule() 
+
+  virtual
+  ~SecRule()
   {}
-  
-  virtual bool 
+
+  virtual bool
   matchDataName(const Data& data) = 0;
-  
-  virtual bool 
+
+  virtual bool
   matchSignerName(const Data& data) = 0;
-  
+
   virtual bool
   satisfy(const Data& data) = 0;
-  
+
   virtual bool
   satisfy(const Name& dataName, const Name& signerName) = 0;
-  
+
   inline bool
   isPositive();
-  
+
 protected:
   bool m_isPositive;
 };
@@ -50,7 +58,7 @@
 {
   return m_isPositive;
 }
-    
+
 } // namespace ndn
 
 #endif //NDN_SECURITY_SEC_RULE_HPP
diff --git a/src/security/sec-tpm-file.cpp b/src/security/sec-tpm-file.cpp
index 98e117f..3a05282 100644
--- a/src/security/sec-tpm-file.cpp
+++ b/src/security/sec-tpm-file.cpp
@@ -29,11 +29,11 @@
 public:
   Impl(const string& dir)
   {
-    if(dir.empty())
+    if (dir.empty())
       m_keystorePath = boost::filesystem::path(getenv("HOME")) / ".ndn" / "ndnsec-tpm-file";
     else
       m_keystorePath = dir;
-    
+
     boost::filesystem::create_directories (m_keystorePath);
   }
 
@@ -47,22 +47,22 @@
 
     boost::algorithm::trim(digest);
     std::replace(digest.begin(), digest.end(), '/', '%');
-    
+
     return m_keystorePath / (digest + extension);
   }
 
-  string 
+  string
   maintainMapping(const string& keyName)
   {
     string keyFileName = nameTransform(keyName, "").string();
-    
+
     ofstream outfile;
     string dirFile = (m_keystorePath / "mapping.txt").string();
-    
+
     outfile.open(dirFile.c_str(), std::ios_base::app);
     outfile << keyName << ' ' << keyFileName << '\n';
     outfile.close();
-    
+
     return keyFileName;
   }
 
@@ -77,19 +77,19 @@
 {}
 
 void
-SecTpmFile::generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize)
+SecTpmFile::generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize)
 {
   string keyURI = keyName.toUri();
 
-  if(doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
+  if (doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
     throw Error("public key exists");
-  if(doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
+  if (doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
     throw Error("private key exists");
 
   string keyFileName = m_impl->maintainMapping(keyURI);
 
   try{
-    switch(keyType){
+    switch (keyType){
     case KEY_TYPE_RSA:
       {
         using namespace CryptoPP;
@@ -97,18 +97,18 @@
 
 	InvertibleRSAFunction privateKey;
 	privateKey.Initialize(rng, keySize);
-	
+
 	string privateKeyFileName = keyFileName + ".pri";
 	Base64Encoder privateKeySink(new FileSink(privateKeyFileName.c_str()));
 	privateKey.DEREncode(privateKeySink);
 	privateKeySink.MessageEnd();
-	
+
 	RSAFunction publicKey(privateKey);
 	string publicKeyFileName = keyFileName + ".pub";
 	Base64Encoder publicKeySink(new FileSink(publicKeyFileName.c_str()));
 	publicKey.DEREncode(publicKeySink);
 	publicKeySink.MessageEnd();
-	
+
 	/*set file permission*/
 	chmod(privateKeyFileName.c_str(), 0000400);
 	chmod(publicKeyFileName.c_str(), 0000444);
@@ -117,37 +117,37 @@
     default:
       throw Error("Unsupported key type!");
     }
-  }catch(const CryptoPP::Exception& e){
+  }catch (const CryptoPP::Exception& e){
     throw Error(e.what());
   }
 }
 
 void
-SecTpmFile::deleteKeyPairInTpm(const Name &keyName)
+SecTpmFile::deleteKeyPairInTpm(const Name& keyName)
 {
   boost::filesystem::path publicKeyPath(m_impl->nameTransform(keyName.toUri(), ".pub"));
   boost::filesystem::path privateKeyPath(m_impl->nameTransform(keyName.toUri(), ".pri"));
 
-  if(boost::filesystem::exists(publicKeyPath))
+  if (boost::filesystem::exists(publicKeyPath))
     boost::filesystem::remove(publicKeyPath);
 
-  if(boost::filesystem::exists(privateKeyPath))
+  if (boost::filesystem::exists(privateKeyPath))
     boost::filesystem::remove(privateKeyPath);
 }
 
 shared_ptr<PublicKey>
-SecTpmFile::getPublicKeyFromTpm(const Name & keyName)
+SecTpmFile::getPublicKeyFromTpm(const Name&  keyName)
 {
   string keyURI = keyName.toUri();
 
-  if(!doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
+  if (!doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
     throw Error("Public Key already exist");
 
   ostringstream os;
   try{
     using namespace CryptoPP;
     FileSource(m_impl->nameTransform(keyURI, ".pub").string().c_str(), true, new Base64Decoder(new FileSink(os)));
-  }catch(const CryptoPP::Exception& e){
+  }catch (const CryptoPP::Exception& e){
     throw Error(e.what());
   }
 
@@ -158,9 +158,9 @@
 SecTpmFile::exportPrivateKeyPkcs1FromTpm(const Name& keyName)
 {
   OBufferStream privateKeyOs;
-  CryptoPP::FileSource(m_impl->nameTransform(keyName.toUri(), ".pri").string().c_str(), true, 
+  CryptoPP::FileSource(m_impl->nameTransform(keyName.toUri(), ".pri").string().c_str(), true,
                        new CryptoPP::Base64Decoder(new CryptoPP::FileSink(privateKeyOs)));
-  
+
   return privateKeyOs.buf();
 }
 
@@ -173,7 +173,7 @@
     CryptoPP::StringSource(buf, size, true,
                            new CryptoPP::Base64Encoder(new CryptoPP::FileSink(keyFileName.c_str())));
     return true;
-  }catch(...){
+  }catch (...){
     return false;
   }
 }
@@ -187,19 +187,19 @@
     CryptoPP::StringSource(buf, size, true,
                            new CryptoPP::Base64Encoder(new CryptoPP::FileSink(keyFileName.c_str())));
     return true;
-  }catch(...){
+  }catch (...){
     return false;
   }
 }
 
 Block
-SecTpmFile::signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm)
+SecTpmFile::signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm)
 {
   string keyURI = keyName.toUri();
 
-  if(!doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
+  if (!doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
     throw Error("private key doesn't exists");
- 
+
   try{
     using namespace CryptoPP;
     AutoSeededRandomPool rng;
@@ -211,22 +211,22 @@
     bytes.MessageEnd();
     RSA::PrivateKey privateKey;
     privateKey.Load(bytes);
-  
+
     //Sign message
-    switch(digestAlgorithm){
+    switch (digestAlgorithm){
     case DIGEST_ALGORITHM_SHA256:
       {
 	RSASS<PKCS1v15, SHA256>::Signer signer(privateKey);
-	
+
 	OBufferStream os;
 	StringSource(data, dataLength, true, new SignerFilter(rng, signer, new FileSink(os)));
-	
+
 	return Block(Tlv::SignatureValue, os.buf());
       }
     default:
       throw Error("Unsupported digest algorithm!");
     }
-  }catch(const CryptoPP::Exception& e){
+  }catch (const CryptoPP::Exception& e){
     throw Error(e.what());
   }
 }
@@ -239,7 +239,7 @@
   // string keyURI = keyName.toUri();
   // if (!isSymmetric)
   //   {
-  //     if(!doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
+  //     if (!doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE))
   //       throw Error("private key doesn't exist");
 
   //     try{
@@ -254,27 +254,27 @@
   //       RSA::PrivateKey privateKey;
   //       privateKey.Load(bytes);
   //       RSAES_PKCS1v15_Decryptor decryptor(privateKey);
-	
+
   //       OBufferStream os;
   //       StringSource(data, dataLength, true, new PK_DecryptorFilter(rng, decryptor, new FileSink(os)));
-	
+
   //       return os.buf();
   //     }
-  //     catch(const CryptoPP::Exception& e){
+  //     catch (const CryptoPP::Exception& e){
   //       throw Error(e.what());
   //     }
   //   }
   // else
   //   {
   //     throw Error("Symmetric encryption is not implemented!");
-  //     // if(!doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
+  //     // if (!doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
   //     // 	throw Error("symmetric key doesn't exist");
 
   //     // try{
   //     // 	string keyBits;
   //     // 	string symKeyFileName = m_impl->nameTransform(keyURI, ".key");
   //     // 	FileSource(symKeyFileName, true, new HexDecoder(new StringSink(keyBits)));
-	
+
   //     // 	using CryptoPP::AES;
   //     // 	AutoSeededRandomPool rnd;
   //     // 	byte iv[AES::BLOCKSIZE];
@@ -282,12 +282,12 @@
 
   //     // 	CFB_Mode<AES>::Decryption decryptor;
   //     // 	decryptor.SetKeyWithIV(reinterpret_cast<const uint8_t*>(keyBits.c_str()), keyBits.size(), iv);
-	
+
   //     // 	OBufferStream os;
   //     // 	StringSource(data, dataLength, true, new StreamTransformationFilter(decryptor,new FileSink(os)));
   //     // 	return os.buf();
 
-  //     // }catch(const CryptoPP::Exception& e){
+  //     // }catch (const CryptoPP::Exception& e){
   //     // 	throw Error(e.what());
   //     // }
   //   }
@@ -301,7 +301,7 @@
 
   // if (!isSymmetric)
   //   {
-  //     if(!doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
+  //     if (!doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC))
   //       throw Error("public key doesn't exist");
   //     try
   //       {
@@ -322,14 +322,14 @@
   //         StringSource(data, dataLength, true, new PK_EncryptorFilter(rng, encryptor, new FileSink(os)));
   //         return os.buf();
   //       }
-  //     catch(const CryptoPP::Exception& e){
+  //     catch (const CryptoPP::Exception& e){
   //       throw Error(e.what());
   //     }
   //   }
   // else
   //   {
   //     throw Error("Symmetric encryption is not implemented!");
-  //     // if(!doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
+  //     // if (!doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
   //     // 	throw Error("symmetric key doesn't exist");
 
   //     // try{
@@ -348,7 +348,7 @@
   //     // 	OBufferStream os;
   //     // 	StringSource(data, dataLength, true, new StreamTransformationFilter(encryptor, new FileSink(os)));
   //     // 	return os.buf();
-  //     // }catch(const CryptoPP::Exception& e){
+  //     // }catch (const CryptoPP::Exception& e){
   //     // 	throw Error(e.what());
   //     // }
   //   }
@@ -356,19 +356,19 @@
 
 
 void
-SecTpmFile::generateSymmetricKeyInTpm(const Name & keyName, KeyType keyType, int keySize)
+SecTpmFile::generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize)
 {
   throw Error("SecTpmFile::generateSymmetricKeyInTpm is not supported!");
   // string keyURI = keyName.toUri();
 
-  // if(doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
+  // if (doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
   //   throw Error("symmetric key exists");
 
   // string keyFileName = m_impl->maintainMapping(keyURI);
   // string symKeyFileName = keyFileName + ".key";
 
   // try{
-  //   switch(keyType){
+  //   switch (keyType){
   //   case KEY_TYPE_AES:
   //     {
   //       using namespace CryptoPP;
@@ -376,41 +376,41 @@
 
   //       SecByteBlock key(0x00, keySize);
   //       rng.GenerateBlock(key, keySize);
-	
+
   //       StringSource(key, key.size(), true, new HexEncoder(new FileSink(symKeyFileName.c_str())));
-	
+
   //       chmod(symKeyFileName.c_str(), 0000400);
   //       return;
   //     }
   //   default:
   //     throw Error("Unsupported symmetric key type!");
   //   }
-  // }catch(const CryptoPP::Exception& e){
+  // }catch (const CryptoPP::Exception& e){
   //   throw Error(e.what());
   // }
 }
 
 bool
-SecTpmFile::doesKeyExistInTpm(const Name & keyName, KeyClass keyClass)
+SecTpmFile::doesKeyExistInTpm(const Name& keyName, KeyClass keyClass)
 {
   string keyURI = keyName.toUri();
   if (keyClass == KEY_CLASS_PUBLIC)
     {
-      if(boost::filesystem::exists(m_impl->nameTransform(keyURI, ".pub")))
+      if (boost::filesystem::exists(m_impl->nameTransform(keyURI, ".pub")))
         return true;
       else
         return false;
     }
   if (keyClass == KEY_CLASS_PRIVATE)
     {
-      if(boost::filesystem::exists(m_impl->nameTransform(keyURI, ".pri")))
+      if (boost::filesystem::exists(m_impl->nameTransform(keyURI, ".pri")))
         return true;
       else
         return false;
     }
   if (keyClass == KEY_CLASS_SYMMETRIC)
     {
-      if(boost::filesystem::exists(m_impl->nameTransform(keyURI, ".key")))
+      if (boost::filesystem::exists(m_impl->nameTransform(keyURI, ".key")))
         return true;
       else
         return false;
@@ -421,11 +421,12 @@
 bool
 SecTpmFile::generateRandomBlock(uint8_t* res, size_t size)
 {
-  try{
+  try {
     CryptoPP::AutoSeededRandomPool rng;
     rng.GenerateBlock(res, size);
     return true;
-  }catch(const CryptoPP::Exception& e){
+  }
+  catch (const CryptoPP::Exception& e) {
     return false;
   }
 }
diff --git a/src/security/sec-tpm-file.hpp b/src/security/sec-tpm-file.hpp
index 8a108c5..fc1e410 100644
--- a/src/security/sec-tpm-file.hpp
+++ b/src/security/sec-tpm-file.hpp
@@ -18,9 +18,17 @@
 class SecTpmFile : public SecTpm
 {
 public:
-  struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} };
+  class Error : public SecTpm::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : SecTpm::Error(what)
+    {
+    }
+  };
 
-  SecTpmFile(const std::string & dir = "");
+  SecTpmFile(const std::string& dir = "");
 
   virtual
   ~SecTpmFile() {};
@@ -58,24 +66,24 @@
   }
 
   virtual void
-  generateKeyPairInTpm(const Name & keyName, KeyType keyType, int keySize);
+  generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
 
   virtual void
-  deleteKeyPairInTpm(const Name &keyName);
+  deleteKeyPairInTpm(const Name& keyName);
 
   virtual shared_ptr<PublicKey>
-  getPublicKeyFromTpm(const Name & keyName);
+  getPublicKeyFromTpm(const Name&  keyName);
 
   virtual Block
-  signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
+  signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
 
-  virtual ConstBufferPtr 
+  virtual ConstBufferPtr
   decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
 
   virtual ConstBufferPtr
   encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
 
-  virtual void 
+  virtual void
   generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
 
   virtual bool
@@ -84,7 +92,7 @@
   virtual bool
   generateRandomBlock(uint8_t* res, size_t size);
 
-  virtual void 
+  virtual void
   addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
   {}
 
@@ -97,7 +105,7 @@
 
   virtual bool
   importPrivateKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
-  
+
   virtual bool
   importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buf, size_t size);
 
diff --git a/src/security/sec-tpm-memory.cpp b/src/security/sec-tpm-memory.cpp
index 3c77c15..e196f88 100644
--- a/src/security/sec-tpm-memory.cpp
+++ b/src/security/sec-tpm-memory.cpp
@@ -174,11 +174,12 @@
 bool
 SecTpmMemory::generateRandomBlock(uint8_t* res, size_t size)
 {
-  try{
+  try {
     CryptoPP::AutoSeededRandomPool rng;
     rng.GenerateBlock(res, size);
     return true;
-  }catch(const CryptoPP::Exception& e){
+  }
+  catch (const CryptoPP::Exception& e) {
     return false;
   }
 }
diff --git a/src/security/sec-tpm-memory.hpp b/src/security/sec-tpm-memory.hpp
index 2c8cc2b..605d7c8 100644
--- a/src/security/sec-tpm-memory.hpp
+++ b/src/security/sec-tpm-memory.hpp
@@ -21,7 +21,15 @@
  */
 class SecTpmMemory : public SecTpm {
 public:
-  struct Error : public SecTpm::Error { Error(const std::string &what) : SecTpm::Error(what) {} };
+  class Error : public SecTpm::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : SecTpm::Error(what)
+    {
+    }
+  };
 
   virtual
   ~SecTpmMemory();
@@ -69,7 +77,7 @@
   getPublicKeyFromTpm(const Name& keyName);
 
   virtual void
-  deleteKeyPairInTpm(const Name &keyName);
+  deleteKeyPairInTpm(const Name& keyName);
 
   virtual Block
   signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
diff --git a/src/security/sec-tpm-osx.cpp b/src/security/sec-tpm-osx.cpp
index 96c9034..6a5250c 100644
--- a/src/security/sec-tpm-osx.cpp
+++ b/src/security/sec-tpm-osx.cpp
@@ -46,7 +46,7 @@
    * @return the internal key name
    */
   std::string
-  toInternalKeyName(const Name & keyName, KeyClass keyClass);
+  toInternalKeyName(const Name& keyName, KeyClass keyClass);
 
   /**
    * @brief Get key.
@@ -56,7 +56,7 @@
    * @returns pointer to the key
    */
   SecKeychainItemRef
-  getKey(const Name & keyName, KeyClass keyClass);
+  getKey(const Name& keyName, KeyClass keyClass);
 
   /**
    * @brief Convert keyType to MAC OS symmetric key key type
@@ -117,7 +117,7 @@
 SecTpmOsx::SecTpmOsx()
   : m_impl(new Impl)
 {
-  if(m_impl->m_inTerminal)
+  if (m_impl->m_inTerminal)
     SecKeychainSetUserInteractionAllowed (false);
   else
     SecKeychainSetUserInteractionAllowed (true);
@@ -153,7 +153,7 @@
 SecTpmOsx::setInTerminal(bool inTerminal)
 {
   m_impl->m_inTerminal = inTerminal;
-  if(inTerminal)
+  if (inTerminal)
     SecKeychainSetUserInteractionAllowed (false);
   else
     SecKeychainSetUserInteractionAllowed (true);
@@ -171,7 +171,7 @@
   SecKeychainStatus keychainStatus;
 
   OSStatus res = SecKeychainGetStatus(m_impl->m_keyChainRef, &keychainStatus);
-  if(res != errSecSuccess)
+  if (res != errSecSuccess)
     return true;
   else
     return ((kSecUnlockStateStatus & keychainStatus) == 0);
@@ -183,11 +183,11 @@
   OSStatus res;
 
   // If the default key chain is already unlocked, return immediately.
-  if(!locked())
+  if (!locked())
     return true;
 
   // If the default key chain is locked, unlock the key chain.
-  if(usePassword)
+  if (usePassword)
     {
       // Use the supplied password.
       res = SecKeychainUnlock(m_impl->m_keyChainRef,
@@ -195,7 +195,7 @@
                               password,
                               true);
     }
-  else if(m_impl->m_passwordSet)
+  else if (m_impl->m_passwordSet)
     {
       // If no password supplied, then use the configured password if exists.
       SecKeychainUnlock(m_impl->m_keyChainRef,
@@ -203,7 +203,7 @@
                         m_impl->m_password.c_str(),
                         true);
     }
-  else if(m_impl->m_inTerminal)
+  else if (m_impl->m_inTerminal)
     {
       // If no configured password, get password from terminal if inTerminal set.
       bool locked = true;
@@ -212,7 +212,7 @@
 
       while(locked)
         {
-          if(count > 2)
+          if (count > 2)
             break;
 
           char* getPassword = NULL;
@@ -229,7 +229,7 @@
 
           memset(getPassword, 0, strlen(getPassword));
 
-          if(res == errSecSuccess)
+          if (res == errSecSuccess)
             break;
         }
     }
@@ -243,10 +243,10 @@
 }
 
 void
-SecTpmOsx::generateKeyPairInTpmInternal(const Name & keyName, KeyType keyType, int keySize, bool retry)
+SecTpmOsx::generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool retry)
 {
 
-  if(doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC)){
+  if (doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC)){
     _LOG_DEBUG("keyName has existed");
     throw Error("keyName has existed");
   }
@@ -279,7 +279,7 @@
 
   if (res == errSecAuthFailed && !retry)
     {
-      if(unlockTpm(0, 0, false))
+      if (unlockTpm(0, 0, false))
         generateKeyPairInTpmInternal(keyName, keyType, keySize, true);
       else
         throw Error("Fail to unlock the keychain");
@@ -292,7 +292,7 @@
 }
 
 void
-SecTpmOsx::deleteKeyPairInTpmInternal(const Name &keyName, bool retry)
+SecTpmOsx::deleteKeyPairInTpmInternal(const Name& keyName, bool retry)
 {
   CFStringRef keyLabel = CFStringCreateWithCString(NULL,
                                                    keyName.toUri().c_str(),
@@ -311,16 +311,16 @@
 
   if (res == errSecAuthFailed && !retry)
     {
-      if(unlockTpm(0, 0, false))
+      if (unlockTpm(0, 0, false))
         deleteKeyPairInTpmInternal(keyName, true);
     }
 }
 
 void
-SecTpmOsx::generateSymmetricKeyInTpm(const Name & keyName, KeyType keyType, int keySize)
+SecTpmOsx::generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize)
 {
   throw Error("SecTpmOsx::generateSymmetricKeyInTpm is not supported");
-  // if(doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
+  // if (doesKeyExistInTpm(keyName, KEY_CLASS_SYMMETRIC))
   //   throw Error("keyName has existed!");
 
   // string keyNameUri =  m_impl->toInternalKeyName(keyName, KEY_CLASS_SYMMETRIC);
@@ -348,7 +348,7 @@
 }
 
 shared_ptr<PublicKey>
-SecTpmOsx::getPublicKeyFromTpm(const Name & keyName)
+SecTpmOsx::getPublicKeyFromTpm(const Name& keyName)
 {
   _LOG_TRACE("OSXPrivateKeyStorage::getPublickey");
 
@@ -384,11 +384,11 @@
                                NULL,
                                &exportedKey);
 
-  if(res != errSecSuccess)
+  if (res != errSecSuccess)
     {
-      if(res == errSecAuthFailed && !retry)
+      if (res == errSecAuthFailed && !retry)
         {
-          if(unlockTpm(0, 0, false))
+          if (unlockTpm(0, 0, false))
             return exportPrivateKeyPkcs1FromTpmInternal(keyName, true);
           else
             return shared_ptr<Buffer>();
@@ -493,11 +493,11 @@
 #pragma clang diagnostic pop
 #endif // __clang__
 
-  if(res != errSecSuccess)
+  if (res != errSecSuccess)
     {
-      if(res == errSecAuthFailed && !retry)
+      if (res == errSecAuthFailed && !retry)
         {
-          if(unlockTpm(0, 0, false))
+          if (unlockTpm(0, 0, false))
             return importPrivateKeyPkcs1IntoTpmInternal(keyName, buf, size, true);
           else
             return false;
@@ -522,7 +522,7 @@
                                                0,
                                                NULL);
 
-  if(res != errSecSuccess)
+  if (res != errSecSuccess)
     {
       return false;
     }
@@ -556,7 +556,7 @@
                                 m_impl->m_keyChainRef,
                                 &outItems);
 
-  if(res != errSecSuccess)
+  if (res != errSecSuccess)
     return false;
 
   SecKeychainItemRef publicKey = (SecKeychainItemRef)CFArrayGetValueAtIndex(outItems, 0);
@@ -575,7 +575,7 @@
                                                0,
                                                NULL);
 
-  if(res != errSecSuccess)
+  if (res != errSecSuccess)
     return false;
 
   CFRelease(importedKey);
@@ -583,7 +583,7 @@
 }
 
 Block
-SecTpmOsx::signInTpmInternal(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm, bool retry)
+SecTpmOsx::signInTpmInternal(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm, bool retry)
 {
   _LOG_TRACE("OSXPrivateKeyStorage::Sign");
 
@@ -631,9 +631,9 @@
   CFDataRef signature = (CFDataRef) SecTransformExecute(signer, &error);
   if (error)
     {
-      if(!retry)
+      if (!retry)
         {
-          if(unlockTpm(0, 0, false))
+          if (unlockTpm(0, 0, false))
             return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, true);
           else
             throw Error("Fail to unlock the keychain");
@@ -652,13 +652,13 @@
 }
 
 ConstBufferPtr
-SecTpmOsx::decryptInTpm(const uint8_t* data, size_t dataLength, const Name & keyName, bool sym)
+SecTpmOsx::decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool sym)
 {
   throw Error("SecTpmOsx::decryptInTpm is not supported");
   // _LOG_TRACE("OSXPrivateKeyStorage::Decrypt");
 
   // KeyClass keyClass;
-  // if(sym)
+  // if (sym)
   //   keyClass = KEY_CLASS_SYMMETRIC;
   // else
   //   keyClass = KEY_CLASS_PRIVATE;
@@ -696,9 +696,9 @@
 }
 
 void
-SecTpmOsx::addAppToACL(const Name & keyName, KeyClass keyClass, const string & appPath, AclType acl)
+SecTpmOsx::addAppToACL(const Name& keyName, KeyClass keyClass, const string& appPath, AclType acl)
 {
-  if(keyClass == KEY_CLASS_PRIVATE && acl == ACL_TYPE_PRIVATE)
+  if (keyClass == KEY_CLASS_PRIVATE && acl == ACL_TYPE_PRIVATE)
     {
       SecKeychainItemRef privateKey = m_impl->getKey(keyName, keyClass);
 
@@ -738,13 +738,13 @@
 }
 
 ConstBufferPtr
-SecTpmOsx::encryptInTpm(const uint8_t* data, size_t dataLength, const Name & keyName, bool sym)
+SecTpmOsx::encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool sym)
 {
   throw Error("SecTpmOsx::encryptInTpm is not supported");
   // _LOG_TRACE("OSXPrivateKeyStorage::Encrypt");
 
   // KeyClass keyClass;
-  // if(sym)
+  // if (sym)
   //   keyClass = KEY_CLASS_SYMMETRIC;
   // else
   //   keyClass = KEY_CLASS_PUBLIC;
@@ -775,7 +775,7 @@
 }
 
 bool
-SecTpmOsx::doesKeyExistInTpm(const Name & keyName, KeyClass keyClass)
+SecTpmOsx::doesKeyExistInTpm(const Name& keyName, KeyClass keyClass)
 {
   _LOG_TRACE("OSXPrivateKeyStorage::doesKeyExist");
 
@@ -798,7 +798,7 @@
   SecKeychainItemRef itemRef;
   OSStatus res = SecItemCopyMatching((CFDictionaryRef)attrDict, (CFTypeRef*)&itemRef);
 
-  if(res == errSecSuccess)
+  if (res == errSecSuccess)
     return true;
   else
     return false;
@@ -816,7 +816,7 @@
 ////////////////////////////////
 
 SecKeychainItemRef
-SecTpmOsx::Impl::getKey(const Name & keyName, KeyClass keyClass)
+SecTpmOsx::Impl::getKey(const Name& keyName, KeyClass keyClass)
 {
   string keyNameUri = toInternalKeyName(keyName, keyClass);
 
@@ -838,7 +838,7 @@
 
   OSStatus res = SecItemCopyMatching((CFDictionaryRef) attrDict, (CFTypeRef*)&keyItem);
 
-  if(res != errSecSuccess){
+  if (res != errSecSuccess){
     _LOG_DEBUG("Fail to find the key!");
     return NULL;
   }
@@ -847,11 +847,11 @@
 }
 
 string
-SecTpmOsx::Impl::toInternalKeyName(const Name & keyName, KeyClass keyClass)
+SecTpmOsx::Impl::toInternalKeyName(const Name& keyName, KeyClass keyClass)
 {
   string keyUri = keyName.toUri();
 
-  if(KEY_CLASS_SYMMETRIC == keyClass)
+  if (KEY_CLASS_SYMMETRIC == keyClass)
     return keyUri + "/symmetric";
   else
     return keyUri;
@@ -860,7 +860,7 @@
 const CFTypeRef
 SecTpmOsx::Impl::getAsymKeyType(KeyType keyType)
 {
-  switch(keyType){
+  switch (keyType){
   case KEY_TYPE_RSA:
     return kSecAttrKeyTypeRSA;
   default:
@@ -872,7 +872,7 @@
 const CFTypeRef
 SecTpmOsx::Impl::getSymKeyType(KeyType keyType)
 {
-  switch(keyType){
+  switch (keyType){
   case KEY_TYPE_AES:
     return kSecAttrKeyTypeAES;
   default:
@@ -884,7 +884,7 @@
 const CFTypeRef
 SecTpmOsx::Impl::getKeyClass(KeyClass keyClass)
 {
-  switch(keyClass){
+  switch (keyClass){
   case KEY_CLASS_PRIVATE:
     return kSecAttrKeyClassPrivate;
   case KEY_CLASS_PUBLIC:
@@ -900,7 +900,7 @@
 const CFStringRef
 SecTpmOsx::Impl::getDigestAlgorithm(DigestAlgorithm digestAlgo)
 {
-  switch(digestAlgo){
+  switch (digestAlgo){
     // case DIGEST_MD2:
     //   return kSecDigestMD2;
     // case DIGEST_MD5:
@@ -918,7 +918,7 @@
 long
 SecTpmOsx::Impl::getDigestSize(DigestAlgorithm digestAlgo)
 {
-  switch(digestAlgo){
+  switch (digestAlgo){
   case DIGEST_ALGORITHM_SHA256:
     return 256;
     // case DIGEST_SHA1:
diff --git a/src/security/sec-tpm-osx.hpp b/src/security/sec-tpm-osx.hpp
index f9cfc57..3dc6877 100644
--- a/src/security/sec-tpm-osx.hpp
+++ b/src/security/sec-tpm-osx.hpp
@@ -12,14 +12,22 @@
 #include "sec-tpm.hpp"
 
 namespace ndn {
-  
+
 class SecTpmOsx : public SecTpm {
 public:
-  struct Error : public SecTpm::Error { Error(const std::string& what) : SecTpm::Error(what) {} };
+  class Error : public SecTpm::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : SecTpm::Error(what)
+    {
+    }
+  };
 
   SecTpmOsx();
 
-  virtual 
+  virtual
   ~SecTpmOsx();
 
 
@@ -45,7 +53,7 @@
   virtual bool
   unlockTpm(const char* password, size_t passwordLength, bool usePassword);
 
-  virtual void 
+  virtual void
   generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize)
   {
     generateKeyPairInTpmInternal(keyName, keyType, keySize, false);
@@ -57,31 +65,31 @@
     deleteKeyPairInTpmInternal(keyName, false);
   }
 
-  virtual shared_ptr<PublicKey> 
+  virtual shared_ptr<PublicKey>
   getPublicKeyFromTpm(const Name& keyName);
-  
+
   virtual Block
   signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm)
   {
     return signInTpmInternal(data, dataLength, keyName, digestAlgorithm, false);
   }
 
-  virtual ConstBufferPtr 
+  virtual ConstBufferPtr
   decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
 
   virtual ConstBufferPtr
   encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric);
 
-  virtual void 
+  virtual void
   generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize);
 
   virtual bool
-  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass); 
+  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass);
 
   virtual bool
-  generateRandomBlock(uint8_t* res, size_t size); 
+  generateRandomBlock(uint8_t* res, size_t size);
 
-  virtual void 
+  virtual void
   addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl);
 
 protected:
@@ -107,10 +115,10 @@
    *       OSX-specifics        *
    ******************************/
   void
-  generateKeyPairInTpmInternal(const Name & keyName, KeyType keyType, int keySize, bool retry);
-  
+  generateKeyPairInTpmInternal(const Name& keyName, KeyType keyType, int keySize, bool retry);
+
   void
-  deleteKeyPairInTpmInternal(const Name &keyName, bool retry);
+  deleteKeyPairInTpmInternal(const Name& keyName, bool retry);
 
   ConstBufferPtr
   exportPrivateKeyPkcs1FromTpmInternal(const Name& keyName, bool retry);
@@ -119,13 +127,13 @@
   importPrivateKeyPkcs1IntoTpmInternal(const Name& keyName, const uint8_t* buf, size_t size, bool retry);
 
   Block
-  signInTpmInternal(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm, bool retry);
-  
+  signInTpmInternal(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm, bool retry);
+
 private:
   class Impl;
   shared_ptr<Impl> m_impl;
 };
-  
+
 } // namespace ndn
 
 #endif // NDN_SECURITY_SEC_TPM_OSX_HPP
diff --git a/src/security/sec-tpm.cpp b/src/security/sec-tpm.cpp
index e19196c..3638ca1 100644
--- a/src/security/sec-tpm.cpp
+++ b/src/security/sec-tpm.cpp
@@ -17,28 +17,28 @@
 SecTpm::exportPrivateKeyPkcs8FromTpm(const Name& keyName, const string& passwordStr)
 {
   using namespace CryptoPP;
-    
+
   uint8_t salt[8] = {0};
   uint8_t iv[8] = {0};
-    
+
   // derive key
-  if(!generateRandomBlock(salt, 8) || !generateRandomBlock(iv, 8))
+  if (!generateRandomBlock(salt, 8) || !generateRandomBlock(iv, 8))
     throw Error("Cannot generate salt or iv");
 
   uint32_t iterationCount = 2048;
-  
+
   PKCS5_PBKDF2_HMAC<SHA1> keyGenerator;
   size_t derivedLen = 24; //For DES-EDE3-CBC-PAD
   byte derived[24] = {0};
   byte purpose = 0;
-  
+
   try
     {
-      keyGenerator.DeriveKey(derived, derivedLen, purpose, 
-                             reinterpret_cast<const byte*>(passwordStr.c_str()), passwordStr.size(), 
+      keyGenerator.DeriveKey(derived, derivedLen, purpose,
+                             reinterpret_cast<const byte*>(passwordStr.c_str()), passwordStr.size(),
                              salt, 8, iterationCount);
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       throw Error("Cannot derived the encryption key");
     }
@@ -46,18 +46,18 @@
   //encrypt
   CBC_Mode< DES_EDE3 >::Encryption e;
   e.SetKeyWithIV(derived, derivedLen, iv);
-  
+
   ConstBufferPtr pkcs1PrivateKey = exportPrivateKeyPkcs1FromTpm(keyName);
-  if(!static_cast<bool>(pkcs1PrivateKey))
+  if (!static_cast<bool>(pkcs1PrivateKey))
     throw Error("Cannot export the private key, #1");
 
   OBufferStream encryptedOs;
   try
     {
-      StringSource stringSource(pkcs1PrivateKey->buf(), pkcs1PrivateKey->size(), true, 
+      StringSource stringSource(pkcs1PrivateKey->buf(), pkcs1PrivateKey->size(), true,
                                 new StreamTransformationFilter(e, new FileSink(encryptedOs)));
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       throw Error("Cannot export the private key, #2");
     }
@@ -71,7 +71,7 @@
   try
     {
       FileSink sink(pkcs8Os);
-      
+
       // EncryptedPrivateKeyInfo ::= SEQUENCE {
       //   encryptionAlgorithm  EncryptionAlgorithmIdentifier,
       //   encryptedData        OCTET STRING }
@@ -107,7 +107,7 @@
               pbkdf2Params.MessageEnd();
             }
             pbes2KDFs.MessageEnd();
-            
+
             // AlgorithmIdentifier ::= SEQUENCE {
             //   algorithm   OBJECT IDENTIFIER {{DES-EDE3-CBC-PAD}},
             //   parameters  OCTET STRING} {{iv}} }
@@ -121,14 +121,14 @@
           pbes2Params.MessageEnd();
         }
         encryptionAlgorithm.MessageEnd();
-        
+
         DEREncodeOctetString(encryptedPrivateKeyInfo, encryptedOs.buf()->buf(), encryptedOs.buf()->size());
       }
       encryptedPrivateKeyInfo.MessageEnd();
-      
+
       return pkcs8Os.buf();
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       throw Error("Cannot export the private key, #3");
     }
@@ -138,7 +138,7 @@
 SecTpm::importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buf, size_t size, const string& passwordStr)
 {
   using namespace CryptoPP;
-  
+
   OID pbes2Id;
   OID pbkdf2Id;
   SecByteBlock saltBlock;
@@ -146,12 +146,12 @@
   OID pbes2encsId;
   SecByteBlock ivBlock;
   SecByteBlock encryptedDataBlock;
-  
+
   try
     {
       //decode some decoding processes are not necessary for now, because we assume only one encryption scheme.
       StringSource source(buf, size, true);
-      
+
       // EncryptedPrivateKeyInfo ::= SEQUENCE {
       //   encryptionAlgorithm  EncryptionAlgorithmIdentifier,
       //   encryptedData        OCTET STRING }
@@ -187,7 +187,7 @@
               pbkdf2Params.MessageEnd();
             }
             pbes2KDFs.MessageEnd();
-            
+
             // AlgorithmIdentifier ::= SEQUENCE {
             //   algorithm   OBJECT IDENTIFIER {{DES-EDE3-CBC-PAD}},
             //   parameters  OCTET STRING} {{iv}} }
@@ -206,48 +206,48 @@
       }
       encryptedPrivateKeyInfo.MessageEnd();
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
 
-  
+
   PKCS5_PBKDF2_HMAC<SHA1> keyGenerator;
   size_t derivedLen = 24; //For DES-EDE3-CBC-PAD
   byte derived[24] = {0};
   byte purpose = 0;
-  
+
   try
     {
-      keyGenerator.DeriveKey(derived, derivedLen, 
-                             purpose, 
-                             reinterpret_cast<const byte*>(passwordStr.c_str()), passwordStr.size(), 
-                             saltBlock.BytePtr(), saltBlock.size(), 
+      keyGenerator.DeriveKey(derived, derivedLen,
+                             purpose,
+                             reinterpret_cast<const byte*>(passwordStr.c_str()), passwordStr.size(),
+                             saltBlock.BytePtr(), saltBlock.size(),
                              iterationCount);
     }
-  catch(CryptoPP::Exception& e)
-    {
-      return false;
-    }
-        
-  //decrypt
-  CBC_Mode< DES_EDE3 >::Decryption d;
-  d.SetKeyWithIV(derived, derivedLen, ivBlock.BytePtr());
-  
-  OBufferStream privateKeyOs;
-  try
-    {
-      StringSource encryptedSource(encryptedDataBlock.BytePtr(), encryptedDataBlock.size(), true, 
-                                   new StreamTransformationFilter(d,  new FileSink(privateKeyOs)));
-    }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
 
-  if(!importPrivateKeyPkcs1IntoTpm(keyName, privateKeyOs.buf()->buf(), privateKeyOs.buf()->size()))
+  //decrypt
+  CBC_Mode< DES_EDE3 >::Decryption d;
+  d.SetKeyWithIV(derived, derivedLen, ivBlock.BytePtr());
+
+  OBufferStream privateKeyOs;
+  try
+    {
+      StringSource encryptedSource(encryptedDataBlock.BytePtr(), encryptedDataBlock.size(), true,
+                                   new StreamTransformationFilter(d,  new FileSink(privateKeyOs)));
+    }
+  catch (CryptoPP::Exception& e)
+    {
+      return false;
+    }
+
+  if (!importPrivateKeyPkcs1IntoTpm(keyName, privateKeyOs.buf()->buf(), privateKeyOs.buf()->size()))
     return false;
-    
+
   //derive public key
   OBufferStream publicKeyOs;
 
@@ -256,19 +256,19 @@
       RSA::PrivateKey privateKey;
       privateKey.Load(StringStore(privateKeyOs.buf()->buf(), privateKeyOs.buf()->size()).Ref());
       RSAFunction publicKey(privateKey);
-  
+
       FileSink publicKeySink(publicKeyOs);
       publicKey.DEREncode(publicKeySink);
       publicKeySink.MessageEnd();
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
 
-  if(!importPublicKeyPkcs1IntoTpm(keyName, publicKeyOs.buf()->buf(), publicKeyOs.buf()->size()))
+  if (!importPublicKeyPkcs1IntoTpm(keyName, publicKeyOs.buf()->buf(), publicKeyOs.buf()->size()))
     return false;
-  
+
   return true;
 }
 
diff --git a/src/security/sec-tpm.hpp b/src/security/sec-tpm.hpp
index 97547a4..bb7e44b 100644
--- a/src/security/sec-tpm.hpp
+++ b/src/security/sec-tpm.hpp
@@ -24,14 +24,22 @@
  */
 class SecTpm {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
-  virtual 
+  virtual
   ~SecTpm() {}
 
   /**
    * @brief set password of TPM
-   * 
+   *
    * Password is used to unlock TPM when it is locked.
    * You should be cautious when using this method, because remembering password is kind of dangerous.
    *
@@ -49,7 +57,7 @@
 
   /**
    * @brief set inTerminal flag
-   * 
+   *
    * If the inTerminal flag is set, and password is not set, TPM may ask for password via terminal.
    * inTerminal flag is set by default.
    *
@@ -60,7 +68,7 @@
 
   /**
    * @brief get inTerminal flag
-   * 
+   *
    * @return inTerminal flag.
    */
   virtual bool
@@ -68,7 +76,7 @@
 
   /**
    * @brief check if TPM is locked.
-   * 
+   *
    * @return true if locked, false otherwise
    */
   virtual bool
@@ -93,16 +101,16 @@
    * @param keySize The size of the key pair.
    * @throws SecTpm::Error if fails.
    */
-  virtual void 
+  virtual void
   generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize) = 0;
-  
+
   /**
    * @brief Delete a key pair of asymmetric keys.
    *
    * @param keyName The name of the key pair.
    */
   virtual void
-  deleteKeyPairInTpm(const Name &keyName) = 0;
+  deleteKeyPairInTpm(const Name& keyName) = 0;
 
   /**
    * @brief Get a public key.
@@ -111,9 +119,9 @@
    * @return The public key.
    * @throws SecTpm::Error if public key does not exist in TPM.
    */
-  virtual shared_ptr<PublicKey> 
+  virtual shared_ptr<PublicKey>
   getPublicKeyFromTpm(const Name& keyName) = 0;
-  
+
   /**
    * @brief Sign data.
    *
@@ -123,10 +131,10 @@
    * @param digestAlgorithm the digest algorithm.
    * @return The signature block.
    * @throws SecTpm::Error if signing fails.
-   */  
+   */
   virtual Block
-  signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm) = 0;
-  
+  signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm) = 0;
+
   /**
    * @brief Decrypt data.
    *
@@ -137,7 +145,7 @@
    * @return The decrypted data.
    * @throws SecTpm::Error if decryption fails.
    */
-  virtual ConstBufferPtr 
+  virtual ConstBufferPtr
   decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) = 0;
 
   /**
@@ -161,7 +169,7 @@
    * @param keySize The size of the key.
    * @throws SecTpm::Error if key generating fails.
    */
-  virtual void 
+  virtual void
   generateSymmetricKeyInTpm(const Name& keyName, KeyType keyType, int keySize) = 0;
 
   /**
@@ -172,11 +180,11 @@
    * @return True if the key exists, otherwise false.
    */
   virtual bool
-  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) = 0;  
+  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) = 0;
 
   /**
    * @brief Generate a random block.
-   * 
+   *
    * @param res The pointer to the generated block.
    * @param size The random block size.
    * @return true for success, otherwise false.
@@ -192,12 +200,12 @@
    * @param appPath the absolute path to the application
    * @param acl the new acl of the key
    */
-  virtual void 
+  virtual void
   addAppToACL(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl) = 0;
 
   /**
    * @brief Export a private key in PKCS#8 format.
-   * 
+   *
    * @param keyName The private key name.
    * @param password The password to encrypt the private key.
    * @return The private key info (in PKCS8 format) if exist.
@@ -208,9 +216,9 @@
 
   /**
    * @brief Import a private key in PKCS#8 format.
-   * 
+   *
    * Also recover the public key and installed it in TPM.
-   * 
+   *
    * @param keyName The private key name.
    * @param key The encoded private key info.
    * @param password The password to encrypt the private key.
@@ -222,7 +230,7 @@
 protected:
   /**
    * @brief Export a private key in PKCS#1 format.
-   * 
+   *
    * @param keyName The private key name.
    * @return The private key info (in PKCS#1 format) if exist, otherwise a NULL pointer.
    */
@@ -231,7 +239,7 @@
 
   /**
    * @brief Import a private key in PKCS#1 format.
-   * 
+   *
    * @param keyName The private key name.
    * @param key The encoded private key info.
    * @return False if import fails.
@@ -241,7 +249,7 @@
 
   /**
    * @brief Import a public key in PKCS#1 format.
-   * 
+   *
    * @param keyName The public key name.
    * @param key The encoded public key info.
    * @return False if import fails.
@@ -267,22 +275,22 @@
   int result = false;
 
   char* pw0 = NULL;
-  
+
   pw0 = getpass(prompt.c_str());
-  if(!pw0) 
+  if (!pw0)
     return false;
   std::string password1 = pw0;
   memset(pw0, 0, strlen(pw0));
 
   pw0 = getpass("Confirm:");
-  if(!pw0)
+  if (!pw0)
     {
       char* pw1 = const_cast<char*>(password1.c_str());
       memset(pw1, 0, password1.size());
       return false;
     }
 
-  if(!password1.compare(pw0))
+  if (!password1.compare(pw0))
     {
       result = true;
       password.swap(password1);
@@ -292,7 +300,7 @@
   memset(pw1, 0, password1.size());
   memset(pw0, 0, strlen(pw0));
 
-  if(password.empty())
+  if (password.empty())
     return false;
 
   return result;
diff --git a/src/security/secured-bag.hpp b/src/security/secured-bag.hpp
index 3a8cd29..5848981 100644
--- a/src/security/secured-bag.hpp
+++ b/src/security/secured-bag.hpp
@@ -16,9 +16,17 @@
 class SecuredBag
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
-  SecuredBag() 
+  SecuredBag()
     : m_wire(tlv::security::IdentityPackage)
   {}
 
@@ -34,12 +42,12 @@
     m_wire.push_back(wireKey);
   }
 
-  virtual 
+  virtual
   ~SecuredBag()
   {}
-  
+
   void
-  wireDecode(const Block &wire)
+  wireDecode(const Block& wire)
   {
     m_wire = wire;
     m_wire.parse();
@@ -63,13 +71,13 @@
   {
     return m_cert;
   }
-  
+
   ConstBufferPtr
   getKey() const
   {
     return m_key;
   }
-  
+
 private:
   IdentityCertificate m_cert;
   ConstBufferPtr m_key;
diff --git a/src/security/signature-sha256.hpp b/src/security/signature-sha256.hpp
index 11b7cdf..8ef37a8 100644
--- a/src/security/signature-sha256.hpp
+++ b/src/security/signature-sha256.hpp
@@ -25,7 +25,7 @@
     m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::DigestSha256));
   }
 
-  SignatureSha256(const Signature &signature)
+  SignatureSha256(const Signature& signature)
     : Signature(signature)
   {
     if (getType() != Signature::Sha256)
diff --git a/src/security/validation-request.hpp b/src/security/validation-request.hpp
index f64082b..0bc0d59 100644
--- a/src/security/validation-request.hpp
+++ b/src/security/validation-request.hpp
@@ -16,7 +16,7 @@
  * An OnVerified function object is used to pass a callback to report a successful Interest validation.
  */
 typedef function< void (const shared_ptr<const Interest>&) > OnInterestValidated;
-  
+
 /**
  * An OnVerifyFailed function object is used to pass a callback to report a failed Interest validation.
  */
@@ -26,7 +26,7 @@
  * An OnVerified function object is used to pass a callback to report a successful Data validation.
  */
 typedef function< void (const shared_ptr<const Data>&) > OnDataValidated;
-  
+
 /**
  * An OnVerifyFailed function object is used to pass a callback to report a failed Data validation.
  */
@@ -35,9 +35,9 @@
 
 class ValidationRequest {
 public:
-  ValidationRequest(const Interest &interest, 
-                    const OnDataValidated &onValidated, 
-                    const OnDataValidationFailed &onDataValidated, 
+  ValidationRequest(const Interest& interest,
+                    const OnDataValidated& onValidated,
+                    const OnDataValidationFailed& onDataValidated,
                     int retry, int stepCount)
   : m_interest(interest)
   , m_onValidated(onValidated)
@@ -45,7 +45,7 @@
   , m_retry(retry)
   , m_stepCount(stepCount)
   {}
-    
+
   virtual
   ~ValidationRequest() {}
 
diff --git a/src/security/validator-null.hpp b/src/security/validator-null.hpp
index eb186c6..4d7b56b 100644
--- a/src/security/validator-null.hpp
+++ b/src/security/validator-null.hpp
@@ -18,22 +18,22 @@
   virtual
   ~ValidatorNull()
   {}
-  
+
 protected:
   virtual void
-  checkPolicy (const Data& data, 
-               int stepCount, 
-               const OnDataValidated &onValidated, 
-               const OnDataValidationFailed &onValidationFailed,
-               std::vector<shared_ptr<ValidationRequest> > &nextSteps)
+  checkPolicy (const Data& data,
+               int stepCount,
+               const OnDataValidated& onValidated,
+               const OnDataValidationFailed& onValidationFailed,
+               std::vector<shared_ptr<ValidationRequest> >& nextSteps)
   { onValidated(data.shared_from_this()); }
-  
+
   virtual void
-  checkPolicy (const Interest& interest, 
-               int stepCount, 
-               const OnInterestValidated &onValidated, 
-               const OnInterestValidationFailed &onValidationFailed,
-               std::vector<shared_ptr<ValidationRequest> > &nextSteps)
+  checkPolicy (const Interest& interest,
+               int stepCount,
+               const OnInterestValidated& onValidated,
+               const OnInterestValidationFailed& onValidationFailed,
+               std::vector<shared_ptr<ValidationRequest> >& nextSteps)
   { onValidated(interest.shared_from_this()); }
 };
 
diff --git a/src/selectors.hpp b/src/selectors.hpp
index dd37e56..361ad6a 100644
--- a/src/selectors.hpp
+++ b/src/selectors.hpp
@@ -42,6 +42,9 @@
   {
   }
 
+  /**
+   * @brief Create from wire encoding
+   */
   Selectors(const Block& wire)
   {
     wireDecode(wire);
@@ -207,7 +210,7 @@
 inline size_t
 Selectors::wireEncode(EncodingImpl<T>& block) const
 {
-  size_t total_len = 0;
+  size_t totalLength = 0;
 
   // Selectors ::= SELECTORS-TYPE TLV-LENGTH
   //                 MinSuffixComponents?
@@ -222,44 +225,44 @@
   // MustBeFresh
   if (getMustBeFresh())
     {
-      total_len += prependBooleanBlock(block, Tlv::MustBeFresh);
+      totalLength += prependBooleanBlock(block, Tlv::MustBeFresh);
     }
 
   // ChildSelector
   if (getChildSelector() >= 0)
     {
-      total_len += prependNonNegativeIntegerBlock(block, Tlv::ChildSelector, getChildSelector());
+      totalLength += prependNonNegativeIntegerBlock(block, Tlv::ChildSelector, getChildSelector());
     }
 
   // Exclude
   if (!getExclude().empty())
     {
-      total_len += getExclude().wireEncode(block);
+      totalLength += getExclude().wireEncode(block);
     }
 
   // PublisherPublicKeyLocator
   if (!getPublisherPublicKeyLocator().empty())
     {
-      total_len += getPublisherPublicKeyLocator().wireEncode(block);
+      totalLength += getPublisherPublicKeyLocator().wireEncode(block);
     }
 
   // MaxSuffixComponents
   if (getMaxSuffixComponents() >= 0)
     {
-      total_len += prependNonNegativeIntegerBlock(block, Tlv::MaxSuffixComponents,
-                                                  getMaxSuffixComponents());
+      totalLength += prependNonNegativeIntegerBlock(block, Tlv::MaxSuffixComponents,
+                                                    getMaxSuffixComponents());
     }
 
   // MinSuffixComponents
   if (getMinSuffixComponents() >= 0)
     {
-      total_len += prependNonNegativeIntegerBlock(block, Tlv::MinSuffixComponents,
-                                                  getMinSuffixComponents());
+      totalLength += prependNonNegativeIntegerBlock(block, Tlv::MinSuffixComponents,
+                                                    getMinSuffixComponents());
     }
 
-  total_len += block.prependVarNumber(total_len);
-  total_len += block.prependVarNumber(Tlv::Selectors);
-  return total_len;
+  totalLength += block.prependVarNumber(totalLength);
+  totalLength += block.prependVarNumber(Tlv::Selectors);
+  return totalLength;
 }
 
 inline const Block&
diff --git a/src/transport/transport.hpp b/src/transport/transport.hpp
index e678491..08740fb 100644
--- a/src/transport/transport.hpp
+++ b/src/transport/transport.hpp
@@ -17,16 +17,16 @@
   class Error : public std::runtime_error
   {
   public:
-    inline Error(const boost::system::error_code &code, const std::string &msg);
+    inline Error(const boost::system::error_code& code, const std::string& msg);
     inline Error(const std::string& msg);
   };
-  
-  typedef ptr_lib::function<void (const Block &wire)> ReceiveCallback;
+
+  typedef ptr_lib::function<void (const Block& wire)> ReceiveCallback;
   typedef ptr_lib::function<void ()> ErrorCallback;
-  
+
   inline
   Transport();
-  
+
   inline virtual
   ~Transport();
 
@@ -35,14 +35,14 @@
    *
    * @throws If connection cannot be established
    */
-  inline virtual void 
+  inline virtual void
   connect(boost::asio::io_service& io_service,
           const ReceiveCallback& receiveCallback);
-  
+
   /**
    * Close the connection.
    */
-  virtual void 
+  virtual void
   close() = 0;
 
   /**
@@ -51,7 +51,7 @@
    * @param data A pointer to the buffer of data to send.
    * @param dataLength The number of bytes in data.
    */
-  virtual void 
+  virtual void
   send(const Block& wire) = 0;
 
   /**
@@ -60,7 +60,7 @@
    * Two non-consecutive memory blocks will be send out together, e.g., as part of the
    * same message in datagram-oriented transports.
    */
-  virtual void 
+  virtual void
   send(const Block& header, const Block& payload) = 0;
 
   virtual void
@@ -68,8 +68,8 @@
 
   virtual void
   resume() = 0;
-  
-  inline bool 
+
+  inline bool
   isConnected();
 
   inline bool
@@ -78,7 +78,7 @@
 protected:
   inline void
   receive(const Block& wire);
-  
+
 protected:
   boost::asio::io_service* m_ioService;
   bool m_isConnected;
@@ -111,7 +111,7 @@
 {
 }
 
-inline void 
+inline void
 Transport::connect(boost::asio::io_service& ioService,
                    const ReceiveCallback& receiveCallback)
 {
@@ -119,7 +119,7 @@
   m_receiveCallback = receiveCallback;
 }
 
-inline bool 
+inline bool
 Transport::isConnected()
 {
   return m_isConnected;
diff --git a/src/util/command-interest-generator.hpp b/src/util/command-interest-generator.hpp
index 18bc960..8b51cd9 100644
--- a/src/util/command-interest-generator.hpp
+++ b/src/util/command-interest-generator.hpp
@@ -62,7 +62,7 @@
     .append(name::Component::fromNumber(random::generateWord64()));
   interest.setName(commandInterestName);
 
-  if(certificateName.empty())
+  if (certificateName.empty())
     m_keyChain.sign(interest);
   else
     m_keyChain.sign(interest, certificateName);
diff --git a/src/util/crypto.cpp b/src/util/crypto.cpp
index 1621005..d8e803a 100644
--- a/src/util/crypto.cpp
+++ b/src/util/crypto.cpp
@@ -10,17 +10,17 @@
 
 namespace ndn {
 
-void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest)
+void ndn_digestSha256(const uint8_t* data, size_t dataLength, uint8_t* digest)
 {
   try
     {
       using namespace CryptoPP;
-      
+
       CryptoPP::SHA256 hash;
       OBufferStream os;
       StringSource(data, dataLength, true, new HashFilter(hash, new ArraySink(digest, crypto::SHA256_DIGEST_SIZE)));
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return;
     }
@@ -30,18 +30,18 @@
 namespace crypto {
 
 ConstBufferPtr
-sha256(const uint8_t *data, size_t dataLength)
+sha256(const uint8_t* data, size_t dataLength)
 {
   try
     {
       using namespace CryptoPP;
-      
+
       SHA256 hash;
       OBufferStream os;
       StringSource(data, dataLength, true, new HashFilter(hash, new FileSink(os)));
       return os.buf();
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return ConstBufferPtr();
     }
diff --git a/src/util/crypto.hpp b/src/util/crypto.hpp
index 58555a2..82e769f 100644
--- a/src/util/crypto.hpp
+++ b/src/util/crypto.hpp
@@ -18,7 +18,7 @@
  * @param dataLength The length of data.
  * @param digest A pointer to a buffer of size crypto::SHA256_DIGEST_SIZE to receive the data.
  */
-void ndn_digestSha256(const uint8_t *data, size_t dataLength, uint8_t *digest);
+void ndn_digestSha256(const uint8_t* data, size_t dataLength, uint8_t* digest);
 
 namespace crypto {
 
@@ -33,7 +33,7 @@
  * @return A pointer to a buffer of SHA256_DIGEST.
  */
 ConstBufferPtr
-sha256(const uint8_t *data, size_t dataLength);
+sha256(const uint8_t* data, size_t dataLength);
 
 } // namespace crypto
 
diff --git a/src/util/io.hpp b/src/util/io.hpp
index 6026f06..ff6852b 100644
--- a/src/util/io.hpp
+++ b/src/util/io.hpp
@@ -19,7 +19,15 @@
 namespace ndn {
 namespace io {
 
-struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+class Error : public std::runtime_error
+{
+public:
+  explicit
+  Error(const std::string& what)
+    : std::runtime_error(what)
+  {
+  }
+};
 
 enum IoEncoding {
   NO_ENCODING,
@@ -27,8 +35,8 @@
   HEX
 };
 
-template<typename T> 
-shared_ptr<T> 
+template<typename T>
+shared_ptr<T>
 load(std::istream& is, IoEncoding encoding = BASE_64)
 {
   typedef typename T::Error TypeError;
@@ -39,54 +47,54 @@
       shared_ptr<T> object = make_shared<T>();
 
       OBufferStream os;
-      
-      switch(encoding)
-	{
-	case NO_ENCODING:
-	  {
-	    FileSource ss(is, true, new FileSink(os));
-	    break;
-	  }
-	case BASE_64:
-	  {
-	    FileSource ss(is, true, new Base64Decoder(new FileSink(os)));
-	    break;
-	  }
-	case HEX:
-	  {
-	    FileSource ss(is, true, new HexDecoder(new FileSink(os)));
-	    break;
-	  }
-	default:
-	  return shared_ptr<T>(); 
-	}
+
+      switch (encoding)
+        {
+        case NO_ENCODING:
+          {
+            FileSource ss(is, true, new FileSink(os));
+            break;
+          }
+        case BASE_64:
+          {
+            FileSource ss(is, true, new Base64Decoder(new FileSink(os)));
+            break;
+          }
+        case HEX:
+          {
+            FileSource ss(is, true, new HexDecoder(new FileSink(os)));
+            break;
+          }
+        default:
+          return shared_ptr<T>();
+        }
 
       object->wireDecode(Block(os.buf()));
       return object;
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return shared_ptr<T>();
     }
-  catch(Block::Error& e)
+  catch (Block::Error& e)
     {
       return shared_ptr<T>();
     }
-  catch(TypeError& e)
+  catch (TypeError& e)
     {
       return shared_ptr<T>();
     }
 }
 
-template<typename T> 
-shared_ptr<T> 
+template<typename T>
+shared_ptr<T>
 load(const std::string& file, IoEncoding encoding = BASE_64)
 {
   std::ifstream is(file.c_str());
   return load<T>(is, encoding);
 }
 
-template<typename T> 
+template<typename T>
 void
 save(const T& object, std::ostream& os, IoEncoding encoding = BASE_64)
 {
@@ -96,38 +104,41 @@
       using namespace CryptoPP;
 
       Block block = object.wireEncode();
-      
-      switch(encoding)
-	{
-	case NO_ENCODING:
-	  {
-	    StringSource ss(block.wire(), block.size(), true, new FileSink(os));
-	    break;
-	  }
-	case BASE_64:
-	  {
-	    StringSource ss(block.wire(), block.size(), true, new Base64Encoder(new FileSink(os), true, 64));
-	    break;
-	  }
-	case HEX:
-	  {
-	    StringSource ss(block.wire(), block.size(), true, new HexEncoder(new FileSink(os)));
-	    break;
-	  }
-	default:
-	  return; 
-	}
+
+      switch (encoding)
+        {
+        case NO_ENCODING:
+          {
+            StringSource ss(block.wire(), block.size(), true,
+                            new FileSink(os));
+            break;
+          }
+        case BASE_64:
+          {
+            StringSource ss(block.wire(), block.size(), true,
+                            new Base64Encoder(new FileSink(os), true, 64));
+            break;
+          }
+        case HEX:
+          {
+            StringSource ss(block.wire(), block.size(), true,
+                            new HexEncoder(new FileSink(os)));
+            break;
+          }
+        default:
+          return;
+        }
       return;
     }
-  catch(CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       throw Error(e.what());
     }
-  catch(Block::Error& e)
+  catch (Block::Error& e)
     {
       throw Error(e.what());
     }
-  catch(TypeError& e)
+  catch (TypeError& e)
     {
       throw Error(e.what());
     }
@@ -145,4 +156,3 @@
 } // namespace ndn
 
 #endif // NDN_UTIL_IO_HPP
-
diff --git a/src/util/regex/regex-backref-matcher.hpp b/src/util/regex/regex-backref-matcher.hpp
index e2eabe8..aa00605 100644
--- a/src/util/regex/regex-backref-matcher.hpp
+++ b/src/util/regex/regex-backref-matcher.hpp
@@ -18,17 +18,17 @@
 {
 public:
   RegexBackrefMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
-    
+
   virtual ~RegexBackrefMatcher(){}
 
-  void 
+  void
   lateCompile()
   {
     compile();
   }
 
 protected:
-  virtual void 
+  virtual void
   compile();
 };
 
@@ -44,11 +44,11 @@
   // compile();
 }
 
-inline void 
+inline void
 RegexBackrefMatcher::compile()
 {
   int lastIndex = m_expr.size() - 1;
-  if('(' == m_expr[0] && ')' == m_expr[lastIndex]){
+  if ('(' == m_expr[0] && ')' == m_expr[lastIndex]){
     // m_backRefManager->pushRef(this);
 
     shared_ptr<RegexMatcher> matcher(new RegexPatternListMatcher(m_expr.substr(1, lastIndex - 1), m_backrefManager));
@@ -63,5 +63,3 @@
 } // namespace ndn
 
 #endif // NDN_UTIL_REGEX_REGEX_BACKREF_MATCHER_HPP
-
-
diff --git a/src/util/regex/regex-component-matcher.hpp b/src/util/regex/regex-component-matcher.hpp
index 50cb8de..34bcba7 100644
--- a/src/util/regex/regex-component-matcher.hpp
+++ b/src/util/regex/regex-component-matcher.hpp
@@ -25,13 +25,13 @@
    * @param backRefManager The back reference manager
    * @param exact The flag to provide exact match
    */
-  RegexComponentMatcher(const std::string& expr, 
-                        ptr_lib::shared_ptr<RegexBackrefManager> backRefManager, 
+  RegexComponentMatcher(const std::string& expr,
+                        ptr_lib::shared_ptr<RegexBackrefManager> backRefManager,
                         bool exact = true);
-    
+
   virtual ~RegexComponentMatcher() {};
 
-  virtual bool 
+  virtual bool
   match(const Name & name, const int & offset, const int &len = 1);
 
 protected:
@@ -39,20 +39,20 @@
    * @brief Compile the regular expression to generate the more matchers when necessary
    * @returns true if compiling succeeds
    */
-  virtual void 
+  virtual void
   compile();
-    
+
 private:
   bool m_exact;
   boost::regex m_componentRegex;
   std::vector<ptr_lib::shared_ptr<RegexPseudoMatcher> > m_pseudoMatcher;
-    
+
 };
 
 
 inline
-RegexComponentMatcher::RegexComponentMatcher (const std::string& expr, 
-                                              ptr_lib::shared_ptr<RegexBackrefManager> backRefManager, 
+RegexComponentMatcher::RegexComponentMatcher (const std::string& expr,
+                                              ptr_lib::shared_ptr<RegexBackrefManager> backRefManager,
                                               bool exact)
   : RegexMatcher (expr, EXPR_COMPONENT, backRefManager),
     m_exact(exact)
@@ -62,7 +62,7 @@
   // _LOG_TRACE ("Exit RegexComponentMatcher Constructor: ");
 }
 
-inline void 
+inline void
 RegexComponentMatcher::compile ()
 {
   // _LOG_TRACE ("Enter RegexComponentMatcher::compile");
@@ -78,7 +78,7 @@
       m_pseudoMatcher.push_back(pMatcher);
       m_backrefManager->pushRef(ptr_lib::static_pointer_cast<RegexMatcher>(pMatcher));
     }
-    
+
 
   // _LOG_TRACE ("Exit RegexComponentMatcher::compile");
 }
@@ -90,17 +90,17 @@
 
   m_matchResult.clear();
 
-  if("" == m_expr)
+  if ("" == m_expr)
     {
       m_matchResult.push_back(name.get(offset));
       return true;
     }
 
-  if(true == m_exact)
+  if (true == m_exact)
     {
       boost::smatch subResult;
       std::string targetStr = name.get(offset).toEscapedString();
-      if(boost::regex_match(targetStr, subResult, m_componentRegex))
+      if (boost::regex_match(targetStr, subResult, m_componentRegex))
         {
           for (size_t i = 1; i < m_componentRegex.mark_count(); i++)
             {
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index 4039388..5aed58f 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -24,19 +24,19 @@
    * @param exact The flag to provide exact match
    * @param backRefNum The starting back reference number
    */
-  RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);    
+  RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
 
   virtual ~RegexComponentSetMatcher();
 
-  virtual bool 
+  virtual bool
   match(const Name& name, const int& offset, const int& len = 1);
 
-protected:    
+protected:
   /**
    * @brief Compile the regular expression to generate the more matchers when necessary
    * @returns true if compiling succeeds
    */
-  virtual void 
+  virtual void
   compile();
 
 private:
@@ -45,7 +45,7 @@
 
   void
   compileSingleComponent();
-    
+
   void
   compileMultipleComponents(const int start, const int lastIndex);
 
@@ -57,7 +57,8 @@
 
 
 inline
-RegexComponentSetMatcher::RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager)
+RegexComponentSetMatcher::RegexComponentSetMatcher(const std::string& expr,
+                                                   shared_ptr<RegexBackrefManager> backRefManager)
   : RegexMatcher(expr, EXPR_COMPONENT_SET, backRefManager),
     m_include(true)
 {
@@ -75,20 +76,20 @@
   //   delete *it;
 }
 
-inline void 
+inline void
 RegexComponentSetMatcher::compile()
 {
-  switch(m_expr[0]){
+  switch (m_expr[0]){
   case '<':
     return compileSingleComponent();
   case '[':
     {
       int lastIndex = m_expr.size() - 1;
-      if(']' != m_expr[lastIndex])
+      if (']' != m_expr[lastIndex])
         throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compile(): ")
                                   + " No matched ']' " + m_expr);
-      
-      if('^' == m_expr[1]){
+
+      if ('^' == m_expr[1]){
         m_include = false;
         compileMultipleComponents(2, lastIndex);
       }
@@ -102,52 +103,55 @@
   }
 }
 
-inline void 
+inline void
 RegexComponentSetMatcher::compileSingleComponent()
 {
   size_t end = extractComponent(1);
 
   if (m_expr.size() != end)
     {
-      throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compileSingleComponent: ")
-                                + m_expr);
+      throw RegexMatcher::Error(
+        std::string("Error: RegexComponentSetMatcher.compileSingleComponent: ") + m_expr);
     }
   else
     {
       shared_ptr<RegexComponentMatcher> component =
         make_shared<RegexComponentMatcher>(m_expr.substr(1, end - 2), m_backrefManager);
-      
-      m_components.insert(component);      
+
+      m_components.insert(component);
     }
 }
 
-inline void 
+inline void
 RegexComponentSetMatcher::compileMultipleComponents(const int start, const int lastIndex)
 {
   int index = start;
   int tmp_index = start;
-    
+
   while(index < lastIndex){
-    if('<' != m_expr[index])
-      throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ")
-                                + "Component expr error " + m_expr);
-      
+    if ('<' != m_expr[index])
+      throw RegexMatcher::Error(
+        std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
+        "Component expr error " + m_expr);
+
     tmp_index = index + 1;
     index = extractComponent(tmp_index);
 
     shared_ptr<RegexComponentMatcher> component =
-      make_shared<RegexComponentMatcher>(m_expr.substr(tmp_index, index - tmp_index - 1), m_backrefManager);
-    
+      make_shared<RegexComponentMatcher>(m_expr.substr(tmp_index, index - tmp_index - 1),
+                                         m_backrefManager);
+
     m_components.insert(component);
   }
-    
-  if(index != lastIndex)
-    throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ")
-                              + "Not sufficient expr to parse " + m_expr);        
+
+  if (index != lastIndex)
+    throw RegexMatcher::Error(
+      std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
+      "Not sufficient expr to parse " + m_expr);
 }
 
-inline bool 
-RegexComponentSetMatcher::match(const Name & name, const int & offset, const int & len)
+inline bool
+RegexComponentSetMatcher::match(const Name& name, const int& offset, const int& len)
 {
   bool matched = false;
 
@@ -161,13 +165,13 @@
        it != m_components.end();
        ++it)
     {
-      if((*it)->match(name, offset, len))
+      if ((*it)->match(name, offset, len))
         {
           matched = true;
           break;
         }
     }
-    
+
   m_matchResult.clear();
 
   if (m_include ? matched : !matched)
@@ -175,18 +179,18 @@
       m_matchResult.push_back(name.get(offset));
       return true;
     }
-  else 
+  else
     return false;
 }
 
-inline int 
+inline int
 RegexComponentSetMatcher::extractComponent(int index)
 {
   int lcount = 1;
   int rcount = 0;
 
   while(lcount > rcount){
-    switch(m_expr[index]){
+    switch (m_expr[index]){
     case '<':
       lcount++;
       break;
diff --git a/src/util/regex/regex-matcher.hpp b/src/util/regex/regex-matcher.hpp
index 0d34311..d62ab41 100644
--- a/src/util/regex/regex-matcher.hpp
+++ b/src/util/regex/regex-matcher.hpp
@@ -18,7 +18,15 @@
 class RegexMatcher
 {
 public:
-  struct Error : public std::runtime_error { Error(const std::string& what) : std::runtime_error(what) {} };
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
   enum RegexExprType{
     EXPR_TOP,
@@ -26,52 +34,52 @@
     EXPR_PATTERNLIST,
 
     EXPR_REPEAT_PATTERN,
-      
+
     EXPR_BACKREF,
     EXPR_COMPONENT_SET,
     EXPR_COMPONENT,
 
     EXPR_PSEUDO
-  };    
+  };
 
-  RegexMatcher(const std::string& expr, 
-               const RegexExprType& type,  
+  RegexMatcher(const std::string& expr,
+               const RegexExprType& type,
                shared_ptr<RegexBackrefManager> backrefManager = shared_ptr<RegexBackrefManager>());
 
-  virtual 
+  virtual
   ~RegexMatcher();
 
-  virtual bool 
+  virtual bool
   match(const Name& name, const int& offset, const int& len);
 
   /**
    * @brief get the matched name components
    * @returns the matched name components
    */
-  const std::vector<name::Component>& 
+  const std::vector<name::Component>&
   getMatchResult() const
   { return m_matchResult; }
 
   const std::string&
   getExpr() const
-  { return m_expr; } 
+  { return m_expr; }
 
 protected:
   /**
    * @brief Compile the regular expression to generate the more matchers when necessary
    * @returns true if compiling succeeds
    */
-  virtual void 
+  virtual void
   compile() = 0;
 
 private:
-  bool 
+  bool
   recursiveMatch(size_t mId, const Name& name, size_t offset, size_t len);
 
 
 protected:
   const std::string m_expr;
-  const RegexExprType m_type; 
+  const RegexExprType m_type;
   shared_ptr<RegexBackrefManager> m_backrefManager;
   std::vector<shared_ptr<RegexMatcher> > m_matcherList;
   std::vector<name::Component> m_matchResult;
@@ -84,14 +92,14 @@
 namespace ndn {
 
 inline
-RegexMatcher::RegexMatcher(const std::string& expr, 
-                           const RegexExprType& type,  
-                           shared_ptr<RegexBackrefManager> backrefManager) 
-  : m_expr(expr), 
+RegexMatcher::RegexMatcher(const std::string& expr,
+                           const RegexExprType& type,
+                           shared_ptr<RegexBackrefManager> backrefManager)
+  : m_expr(expr),
     m_type(type),
     m_backrefManager(backrefManager)
 {
-  if(NULL == m_backrefManager)
+  if (NULL == m_backrefManager)
     m_backrefManager = make_shared<RegexBackrefManager>();
 }
 
@@ -100,7 +108,7 @@
 {
 }
 
-inline bool 
+inline bool
 RegexMatcher::match (const Name& name, const int& offset, const int& len)
 {
   // _LOG_TRACE ("Enter RegexMatcher::match");
@@ -108,7 +116,7 @@
 
   m_matchResult.clear();
 
-  if(recursiveMatch(0, name, offset, len))
+  if (recursiveMatch(0, name, offset, len))
     {
       for(int i = offset; i < offset + len ; i++)
         m_matchResult.push_back(name.get(i));
@@ -122,23 +130,23 @@
   // _LOG_TRACE ("Exit RegexMatcher::match");
   return result;
 }
-  
-inline bool 
+
+inline bool
 RegexMatcher::recursiveMatch(size_t mId, const Name& name, size_t offset, size_t len)
 {
   // _LOG_TRACE ("Enter RegexMatcher::recursiveMatch");
 
   int tried = len;
 
-  if(mId >= m_matcherList.size())
+  if (mId >= m_matcherList.size())
     return (len != 0 ? false : true);
-    
+
   shared_ptr<RegexMatcher> matcher = m_matcherList[mId];
 
   while(tried >= 0)
     {
-      if(matcher->match(name, offset, tried) && recursiveMatch(mId + 1, name, offset + tried, len - tried))
-        return true;      
+      if (matcher->match(name, offset, tried) && recursiveMatch(mId + 1, name, offset + tried, len - tried))
+        return true;
       tried--;
     }
 
diff --git a/src/util/regex/regex-pattern-list-matcher.hpp b/src/util/regex/regex-pattern-list-matcher.hpp
index 3ae74f1..12e3c68 100644
--- a/src/util/regex/regex-pattern-list-matcher.hpp
+++ b/src/util/regex/regex-pattern-list-matcher.hpp
@@ -20,21 +20,21 @@
 {
 public:
   RegexPatternListMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
-    
+
   virtual ~RegexPatternListMatcher(){};
 
-protected:    
-  virtual void 
+protected:
+  virtual void
   compile();
 
 private:
-  bool 
+  bool
   extractPattern(int index, int* next);
-    
-  int 
+
+  int
   extractSubPattern(const char left, const char right, size_t index);
-    
-  int 
+
+  int
   extractRepetition(size_t index);
 
 private:
@@ -53,38 +53,38 @@
 {
   compile();
 }
-  
-inline void 
+
+inline void
 RegexPatternListMatcher::compile()
 {
   const int len = m_expr.size();
   int index = 0;
   int subHead = index;
-    
+
   while(index < len){
     subHead = index;
 
-    if(!extractPattern(subHead, &index))
+    if (!extractPattern(subHead, &index))
       throw RegexMatcher::Error("RegexPatternListMatcher compile: cannot compile");
   }
 }
 
-inline bool 
+inline bool
 RegexPatternListMatcher::extractPattern(int index, int* next)
 {
   // std::string errMsg = "Error: RegexPatternListMatcher.ExtractSubPattern(): ";
-    
+
   const int start = index;
   int end = index;
   int indicator = index;
 
-  switch(m_expr[index]){
+  switch (m_expr[index]){
   case '(':
     index++;
     index = extractSubPattern('(', ')', index);
     indicator = index;
     end = extractRepetition(index);
-    if(indicator == end){
+    if (indicator == end){
       shared_ptr<RegexMatcher> matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(start, end - start), m_backrefManager);
       m_backrefManager->pushRef(matcher);
       boost::dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
@@ -94,7 +94,7 @@
     else
       m_matcherList.push_back(make_shared<RegexRepeatMatcher>(m_expr.substr(start, end - start), m_backrefManager, indicator - start));
     break;
-      
+
   case '<':
     index++;
     index = extractSubPattern ('<', '>', index);
@@ -119,8 +119,8 @@
 
   return true;
 }
-  
-inline int 
+
+inline int
 RegexPatternListMatcher::extractSubPattern(const char left, const char right, size_t index)
 {
   size_t lcount = 1;
@@ -128,13 +128,13 @@
 
   while(lcount > rcount){
 
-    if(index >= m_expr.size())
+    if (index >= m_expr.size())
       throw RegexMatcher::Error("Error: parenthesis mismatch");
 
-    if(left == m_expr[index])
+    if (left == m_expr[index])
       lcount++;
 
-    if(right == m_expr[index])
+    if (right == m_expr[index])
       rcount++;
 
     index++;
@@ -142,25 +142,25 @@
   return index;
 }
 
-inline int 
+inline int
 RegexPatternListMatcher::extractRepetition(size_t index)
 {
   size_t exprSize = m_expr.size();
 
-  if(index == exprSize)
+  if (index == exprSize)
     return index;
-    
-  if(('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])){
+
+  if (('+' == m_expr[index] || '?' == m_expr[index] || '*' == m_expr[index])){
     return ++index;
   }
-    
-  if('{' == m_expr[index]){
+
+  if ('{' == m_expr[index]){
     while('}' != m_expr[index]){
       index++;
-      if(index == exprSize)
+      if (index == exprSize)
         break;
     }
-    if(index == exprSize)
+    if (index == exprSize)
       throw RegexMatcher::Error(std::string("Error: RegexPatternListMatcher.ExtractRepetition(): ")
                                 + "Missing right brace bracket");
     else
diff --git a/src/util/regex/regex-repeat-matcher.hpp b/src/util/regex/regex-repeat-matcher.hpp
index fb42042..5eefbd1 100644
--- a/src/util/regex/regex-repeat-matcher.hpp
+++ b/src/util/regex/regex-repeat-matcher.hpp
@@ -20,10 +20,10 @@
 {
 public:
   RegexRepeatMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager, int indicator);
-    
+
   virtual ~RegexRepeatMatcher(){}
 
-  virtual bool 
+  virtual bool
   match(const Name& name, const int& offset, const int& len);
 
 protected:
@@ -31,19 +31,19 @@
    * @brief Compile the regular expression to generate the more matchers when necessary
    * @returns true if compiling succeeds
    */
-  virtual void 
+  virtual void
   compile();
 
 private:
-  bool 
+  bool
   parseRepetition();
 
-  bool 
+  bool
   recursiveMatch (int repeat,
-                  const Name & name,
-                  const int & offset,
-                  const int &len);
-  
+                  const Name& name,
+                  const int& offset,
+                  const int&len);
+
 private:
   int m_indicator;
   int m_repeatMin;
@@ -67,14 +67,14 @@
   // _LOG_TRACE ("Exit RegexRepeatMatcher Constructor");
 }
 
-inline void 
+inline void
 RegexRepeatMatcher::compile()
 {
   // _LOG_TRACE ("Enter RegexRepeatMatcher::compile");
-    
+
   shared_ptr<RegexMatcher> matcher;
 
-  if('(' == m_expr[0]){
+  if ('(' == m_expr[0]){
     matcher = make_shared<RegexBackrefMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
     m_backrefManager->pushRef(matcher);
     boost::dynamic_pointer_cast<RegexBackrefMatcher>(matcher)->lateCompile();
@@ -83,40 +83,40 @@
     matcher = make_shared<RegexComponentSetMatcher>(m_expr.substr(0, m_indicator), m_backrefManager);
   }
   m_matcherList.push_back(matcher);
-      
+
   parseRepetition();
 
   // _LOG_TRACE ("Exit RegexRepeatMatcher::compile");
 
 }
 
-inline bool 
+inline bool
 RegexRepeatMatcher::parseRepetition()
 {
   // _LOG_DEBUG ("Enter RegexRepeatMatcher::ParseRepetition()" << m_expr << " indicator: " << m_indicator);
-    
+
   int exprSize = m_expr.size();
   int intMax = std::numeric_limits<int>::max();
-    
-  if(exprSize == m_indicator){
+
+  if (exprSize == m_indicator){
     m_repeatMin = 1;
     m_repeatMax = 1;
 
     return true;
   }
   else{
-    if(exprSize == (m_indicator + 1)){
-      if('?' == m_expr[m_indicator]){
+    if (exprSize == (m_indicator + 1)){
+      if ('?' == m_expr[m_indicator]){
         m_repeatMin = 0;
         m_repeatMax = 1;
         return true;
       }
-      if('+' == m_expr[m_indicator]){
+      if ('+' == m_expr[m_indicator]){
         m_repeatMin = 1;
         m_repeatMax = intMax;
         return true;
       }
-      if('*' == m_expr[m_indicator]){
+      if ('*' == m_expr[m_indicator]){
         m_repeatMin = 0;
         m_repeatMax = intMax;
         return true;
@@ -128,36 +128,36 @@
       int min = 0;
       int max = 0;
 
-      if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))){
+      if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,[0-9]+\\}"))){
         int separator = repeatStruct.find_first_of(',', 0);
         min = atoi(repeatStruct.substr(1, separator - 1).c_str());
         max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
       }
-      else if(boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))){
+      else if (boost::regex_match(repeatStruct, boost::regex("\\{,[0-9]+\\}"))){
         int separator = repeatStruct.find_first_of(',', 0);
         min = 0;
         max = atoi(repeatStruct.substr(separator + 1, rsSize - separator - 2).c_str());
       }
-      else if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))){
+      else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+,\\}"))){
         int separator = repeatStruct.find_first_of(',', 0);
         min = atoi(repeatStruct.substr(1, separator).c_str());
         max = intMax;
       }
-      else if(boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))){
+      else if (boost::regex_match(repeatStruct, boost::regex("\\{[0-9]+\\}"))){
         min = atoi(repeatStruct.substr(1, rsSize - 1).c_str());
         max = min;
       }
       else
         throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
                                   + "Unrecognized format "+ m_expr);
-        
-      if(min > intMax || max > intMax || min > max)
+
+      if (min > intMax || max > intMax || min > max)
         throw RegexMatcher::Error(std::string("Error: RegexRepeatMatcher.ParseRepetition(): ")
                                   + "Wrong number " + m_expr);
-          
+
       m_repeatMin = min;
       m_repeatMax = max;
-        
+
       return true;
     }
   }
@@ -165,7 +165,7 @@
 }
 
 inline bool
-RegexRepeatMatcher::match(const Name & name, const int & offset, const int & len)
+RegexRepeatMatcher::match(const Name& name, const int& offset, const int& len)
 {
   // _LOG_TRACE ("Enter RegexRepeatMatcher::match");
 
@@ -185,8 +185,8 @@
     return false;
 }
 
-inline bool 
-RegexRepeatMatcher::recursiveMatch(int repeat, const Name & name, const int & offset, const int & len)
+inline bool
+RegexRepeatMatcher::recursiveMatch(int repeat, const Name& name, const int& offset, const int& len)
 {
   // _LOG_TRACE ("Enter RegexRepeatMatcher::recursiveMatch");
 
@@ -213,7 +213,7 @@
       // _LOG_DEBUG("Match Succeed: No more components && reach m_repeatMin");
       return true;
     }
-    
+
   while(tried >= 0)
     {
       // _LOG_DEBUG("Attempt tried: " << tried);
diff --git a/src/util/regex/regex-top-matcher.cpp b/src/util/regex/regex-top-matcher.cpp
index d3b8271..78cb389 100644
--- a/src/util/regex/regex-top-matcher.cpp
+++ b/src/util/regex/regex-top-matcher.cpp
@@ -27,19 +27,19 @@
   // delete m_backRefManager;
 }
 
-void 
+void
 RegexTopMatcher::compile()
 {
   std::string errMsg = "Error: RegexTopMatcher.Compile(): ";
 
   std::string expr = m_expr;
 
-  if('$' != expr[expr.size() - 1])
+  if ('$' != expr[expr.size() - 1])
     expr = expr + "<.*>*";
   else
     expr = expr.substr(0, expr.size()-1);
 
-  if('^' != expr[0])
+  if ('^' != expr[0])
     m_secondaryMatcher = make_shared<RegexPatternListMatcher>(boost::cref("<.*>*" + expr),
                                                               boost::cref(m_secondaryBackRefManager));
   else
@@ -49,14 +49,14 @@
                                                           boost::cref(m_primaryBackRefManager));
 }
 
-bool 
-RegexTopMatcher::match(const Name & name)
+bool
+RegexTopMatcher::match(const Name& name)
 {
   m_secondaryUsed = false;
 
   m_matchResult.clear();
 
-  if(m_primaryMatcher->match(name, 0, name.size()))
+  if (m_primaryMatcher->match(name, 0, name.size()))
     {
       m_matchResult = m_primaryMatcher->getMatchResult();
       return true;
@@ -72,25 +72,25 @@
       return false;
     }
 }
-  
-bool 
-RegexTopMatcher::match (const Name & name, const int & offset, const int & len)
+
+bool
+RegexTopMatcher::match (const Name& name, const int& offset, const int& len)
 {
   return match(name);
 }
 
-Name 
+Name
 RegexTopMatcher::expand (const std::string& expandStr)
 {
   Name result;
-    
+
   shared_ptr<RegexBackrefManager> backRefManager = (m_secondaryUsed ? m_secondaryBackRefManager : m_primaryBackRefManager);
-    
+
   int backRefNum = backRefManager->size();
 
   std::string expand;
-    
-  if(expandStr != "")
+
+  if (expandStr != "")
     expand = expandStr;
   else
     expand = m_expand;
@@ -99,22 +99,22 @@
   while (offset < expand.size())
     {
       std::string item = getItemFromExpand(expand, offset);
-      if(item[0] == '<')
+      if (item[0] == '<')
         {
           result.append(item.substr(1, item.size() - 2));
         }
-      if(item[0] == '\\')
+      if (item[0] == '\\')
         {
 
           int index = atoi(item.substr(1, item.size() - 1).c_str());
 
-          if(0 == index){
+          if (0 == index){
             std::vector<name::Component>::iterator it = m_matchResult.begin();
             std::vector<name::Component>::iterator end = m_matchResult.end();
             for(; it != end; it++)
               result.append (*it);
           }
-          else if(index <= backRefNum)
+          else if (index <= backRefNum)
             {
               std::vector<name::Component>::const_iterator it = backRefManager->getBackRef (index - 1)->getMatchResult ().begin();
               std::vector<name::Component>::const_iterator end = backRefManager->getBackRef (index - 1)->getMatchResult ().end();
@@ -123,7 +123,7 @@
             }
           else
             throw RegexMatcher::Error("Exceed the range of back reference!");
-        }   
+        }
     }
   return result;
 }
@@ -133,38 +133,38 @@
 {
   size_t begin = offset;
 
-  if(expand[offset] == '\\')
+  if (expand[offset] == '\\')
     {
       offset++;
-      if(offset >= expand.size())
+      if (offset >= expand.size())
         throw RegexMatcher::Error("wrong format of expand string!");
 
       while(expand[offset] <= '9' and expand[offset] >= '0'){
         offset++;
-        if(offset > expand.size())
+        if (offset > expand.size())
           throw RegexMatcher::Error("wrong format of expand string!");
       }
-      if(offset > begin + 1)
+      if (offset > begin + 1)
         return expand.substr(begin, offset - begin);
       else
         throw RegexMatcher::Error("wrong format of expand string!");
     }
-  else if(expand[offset] == '<')
+  else if (expand[offset] == '<')
     {
       offset++;
-      if(offset >= expand.size())
+      if (offset >= expand.size())
         throw RegexMatcher::Error("wrong format of expand string!");
-        
+
       size_t left = 1;
       size_t right = 0;
       while(right < left)
         {
-          if(expand[offset] == '<')
+          if (expand[offset] == '<')
             left++;
-          if(expand[offset] == '>')
-            right++;            
+          if (expand[offset] == '>')
+            right++;
           offset++;
-          if(offset >= expand.size())
+          if (offset >= expand.size())
             throw RegexMatcher::Error("wrong format of expand string!");
         }
       return expand.substr(begin, offset - begin);
@@ -178,7 +178,7 @@
 {
   Name::const_iterator it = name.begin();
   std::string regexStr("^");
-    
+
   for(; it != name.end(); it++)
     {
       regexStr.append("<");
@@ -186,7 +186,7 @@
       regexStr.append(">");
     }
 
-  if(hasAnchor)
+  if (hasAnchor)
     regexStr.append("$");
 
   return make_shared<RegexTopMatcher>(boost::cref(regexStr));
@@ -199,7 +199,7 @@
   for(size_t i = 0; i < str.size(); i++)
     {
       char c = str[i];
-      switch(c)
+      switch (c)
         {
         case '.':
         case '[':
diff --git a/src/util/string-helper.hpp b/src/util/string-helper.hpp
index 9e2329c..7059f0a 100644
--- a/src/util/string-helper.hpp
+++ b/src/util/string-helper.hpp
@@ -13,19 +13,19 @@
 
 namespace ndn {
 
-static const char *WHITESPACE_CHARS = " \n\r\t";
+static const char* WHITESPACE_CHARS = " \n\r\t";
 
 /**
  * Return the hex representation of the bytes in array.
  * @param array The array of bytes.
  * @return Hex string.
  */
-inline std::string 
+inline std::string
 toHex(const uint8_t* array, size_t arraySize)
 {
   if (array == 0 || arraySize == 0)
     return "";
-  
+
   std::ostringstream result;
   result.flags(std::ios::hex | std::ios::uppercase);
   for (size_t i = 0; i < arraySize; ++i) {
@@ -42,7 +42,7 @@
  * Modify str in place to erase whitespace on the left.
  * @param str
  */
-inline void 
+inline void
 trimLeft(std::string& str)
 {
   size_t found = str.find_first_not_of(WHITESPACE_CHARS);
@@ -52,14 +52,14 @@
   }
   else
     // All whitespace
-    str.clear();    
+    str.clear();
 }
 
 /**
  * Modify str in place to erase whitespace on the right.
  * @param str
  */
-inline void 
+inline void
 trimRight(std::string& str)
 {
   size_t found = str.find_last_not_of(WHITESPACE_CHARS);
@@ -76,7 +76,7 @@
  * Modify str in place to erase whitespace on the left and right.
  * @param str
  */
-inline void 
+inline void
 trim(std::string& str)
 {
   trimLeft(str);
@@ -86,9 +86,9 @@
 /**
  * Convert the hex character to an integer from 0 to 15, or -1 if not a hex character.
  * @param c
- * @return 
+ * @return
  */
-inline int 
+inline int
 fromHexChar(uint8_t c)
 {
   if (c >= '0' && c <= '9')
@@ -105,22 +105,22 @@
  * Return a copy of str, converting each escaped "%XX" to the char value.
  * @param str
  */
-inline std::string 
+inline std::string
 unescape(const std::string& str)
 {
   std::ostringstream result;
-  
+
   for (size_t i = 0; i < str.size(); ++i) {
     if (str[i] == '%' && i + 2 < str.size()) {
       int hi = fromHexChar(str[i + 1]);
       int lo = fromHexChar(str[i + 2]);
-      
+
       if (hi < 0 || lo < 0)
         // Invalid hex characters, so just keep the escaped string.
         result << str[i] << str[i + 1] << str[i + 2];
       else
         result << (uint8_t)(16 * hi + lo);
-      
+
       // Skip ahead past the escaped value.
       i += 2;
     }
@@ -128,7 +128,7 @@
       // Just copy through.
       result << str[i];
   }
-  
+
   return result.str();
 }
 
diff --git a/tools/ndncatchunks3.cpp b/tools/ndncatchunks3.cpp
index 59a75ad..460ed52 100644
--- a/tools/ndncatchunks3.cpp
+++ b/tools/ndncatchunks3.cpp
@@ -20,27 +20,29 @@
 
 #include "face.hpp"
 
+namespace ndn {
+
 class Consumer
 {
 public:
-  Consumer(const std::string& data_name,
-           size_t pipe_size, size_t total_seg,
+  Consumer(const std::string& dataName,
+           size_t pipeSize, size_t nTotalSegments,
            int scope = -1, bool mustBeFresh = true)
-    : m_data_name(data_name)
-    , m_pipe_size(pipe_size)
-    , m_total_seg(total_seg)
-    , m_next_seg(0)
-    , m_total_size(0)
-    , m_output(false)
+    : m_dataName(dataName)
+    , m_pipeSize(pipeSize)
+    , m_nTotalSegments(nTotalSegments)
+    , m_nextSegment(0)
+    , m_totalSize(0)
+    , m_isOutputEnabled(false)
     , m_scope(scope)
     , m_mustBeFresh(mustBeFresh)
   {
   }
 
   inline void
-  enable_output()
+  enableOutput()
   {
-    m_output = true;
+    m_isOutputEnabled = true;
   }
 
   void
@@ -48,18 +50,18 @@
 
 private:
   void
-  on_data(const ndn::Interest& interest, ndn::Data& data);
+  onData(const Interest& interest, Data& data);
 
   void
-  on_timeout(const ndn::Interest& interest);
+  onTimeout(const Interest& interest);
 
-  ndn::Face m_face;
-  ndn::Name m_data_name;
-  size_t m_pipe_size;
-  size_t m_total_seg;
-  size_t m_next_seg;
-  size_t m_total_size;
-  bool m_output;  // set to false by default
+  Face m_face;
+  Name m_dataName;
+  size_t m_pipeSize;
+  size_t m_nTotalSegments;
+  size_t m_nextSegment;
+  size_t m_totalSize;
+  bool m_isOutputEnabled;  // set to false by default
 
   int m_scope;
   bool m_mustBeFresh;
@@ -70,18 +72,18 @@
 {
   try
     {
-      for (size_t i = 0; i < m_pipe_size; i++)
-	{
-          ndn::Interest interest(ndn::Name(m_data_name).appendSegment(m_next_seg++));
-	  interest.setInterestLifetime(ndn::time::milliseconds(4000));
-	  if (m_scope >= 0)
+      for (size_t i = 0; i < m_pipeSize; i++)
+        {
+          Interest interest(Name(m_dataName).appendSegment(m_nextSegment++));
+          interest.setInterestLifetime(time::milliseconds(4000));
+          if (m_scope >= 0)
             interest.setScope(m_scope);
-	  interest.setMustBeFresh(m_mustBeFresh);
+          interest.setMustBeFresh(m_mustBeFresh);
 
-	  m_face.expressInterest(interest,
-                                 ndn::bind(&Consumer::on_data, this, _1, _2),
-                                 ndn::bind(&Consumer::on_timeout, this, _1));
-	}
+          m_face.expressInterest(interest,
+                                 bind(&Consumer::onData, this, _1, _2),
+                                 bind(&Consumer::onTimeout, this, _1));
+        }
 
       // processEvents will block until the requested data received or timeout occurs
       m_face.processEvents();
@@ -93,85 +95,86 @@
 }
 
 void
-Consumer::on_data(const ndn::Interest& interest, ndn::Data& data)
+Consumer::onData(const Interest& interest, Data& data)
 {
-  const ndn::Block& content = data.getContent();
-  const ndn::Name& name = data.getName();
+  const Block& content = data.getContent();
+  const Name& name = data.getName();
 
-  if (m_output)
+  if (m_isOutputEnabled)
     {
       std::cout.write(reinterpret_cast<const char*>(content.value()), content.value_size());
     }
 
-  m_total_size += content.value_size();
+  m_totalSize += content.value_size();
 
-  if (name[-1].toSegment() + 1 == m_total_seg)
+  if (name[-1].toSegment() + 1 == m_nTotalSegments)
     {
       std::cerr << "Last segment received." << std::endl;
-      std::cerr << "Total # bytes of content received: " << m_total_size << std::endl;
+      std::cerr << "Total # bytes of content received: " << m_totalSize << std::endl;
     }
   else
     {
       // Send interest for next segment
-      ndn::Interest interest(ndn::Name(m_data_name).appendSegment(m_next_seg++));
+      Interest interest(Name(m_dataName).appendSegment(m_nextSegment++));
       if (m_scope >= 0)
         interest.setScope(m_scope);
-      interest.setInterestLifetime(ndn::time::milliseconds(4000));
+      interest.setInterestLifetime(time::milliseconds(4000));
       interest.setMustBeFresh(m_mustBeFresh);
 
       m_face.expressInterest(interest,
-                             ndn::bind(&Consumer::on_data, this, _1, _2),
-                             ndn::bind(&Consumer::on_timeout, this, _1));
+                             bind(&Consumer::onData, this, _1, _2),
+                             bind(&Consumer::onTimeout, this, _1));
     }
 }
 
 
 void
-Consumer::on_timeout(const ndn::Interest& interest)
+Consumer::onTimeout(const Interest& interest)
 {
   //XXX: currently no retrans
-  std::cerr << "TIMEOUT: last interest sent for segment #" << (m_next_seg - 1) << std::endl;
+  std::cerr << "TIMEOUT: last interest sent for segment #" << (m_nextSegment - 1) << std::endl;
 }
 
 
 int
 usage(const std::string &filename)
 {
-  std::cerr << "Usage: \n    " << filename << " [-p pipe_size] [-c total_segment] [-o] /ndn/name\n";
+  std::cerr << "Usage: \n    "
+            << filename << " [-p pipeSize] [-c nTotalSegmentsment] [-o] /ndn/name\n";
   return 1;
 }
 
 
 int
-main(int argc, char **argv)
+main(int argc, char** argv)
 {
   std::string name;
-  int pipe_size = 1;
-  int total_seg = std::numeric_limits<int>::max();
+  int pipeSize = 1;
+  int nTotalSegments = std::numeric_limits<int>::max();
   bool output = false;
 
   int opt;
   while ((opt = getopt(argc, argv, "op:c:")) != -1)
     {
-      switch(opt)
-	{
+      switch (opt)
+        {
         case 'p':
-	  pipe_size = atoi(optarg);
-	  if (pipe_size <= 0)
-	    pipe_size = 1;
-	  std::cerr << "main(): set pipe size = " << pipe_size << std::endl;
-	  break;
-	case 'c':
-	  total_seg = atoi(optarg);
-	  if (total_seg <= 0)
-	    total_seg = 1;
-	  std::cerr << "main(): set total seg = " << total_seg << std::endl;
-	  break;
-	case 'o':
-	  output = true;
-	  break;
+          pipeSize = atoi(optarg);
+          if (pipeSize <= 0)
+            pipeSize = 1;
+          std::cerr << "main(): set pipe size = " << pipeSize << std::endl;
+          break;
+        case 'c':
+          nTotalSegments = atoi(optarg);
+          if (nTotalSegments <= 0)
+            nTotalSegments = 1;
+          std::cerr << "main(): set total seg = " << nTotalSegments << std::endl;
+          break;
+        case 'o':
+          output = true;
+          break;
         default:
-	  return usage(argv[0]);
+          return usage(argv[0]);
         }
     }
 
@@ -185,12 +188,20 @@
       return usage(argv[0]);
     }
 
-  Consumer consumer(name, pipe_size, total_seg);
+  Consumer consumer(name, pipeSize, nTotalSegments);
 
   if (output)
-    consumer.enable_output();
+    consumer.enableOutput();
 
   consumer.run();
 
   return 0;
 }
+
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::main(argc, argv);
+}
diff --git a/tools/ndnputchunks3.cpp b/tools/ndnputchunks3.cpp
index bb6435b..e03e6cf 100644
--- a/tools/ndnputchunks3.cpp
+++ b/tools/ndnputchunks3.cpp
@@ -21,28 +21,30 @@
 #include "face.hpp"
 #include "security/key-chain.hpp"
 
-#define MAX_SEG_SIZE 4096
+namespace ndn {
+
+const size_t MAX_SEG_SIZE = 4096;
 
 class Producer
 {
 public:
   Producer(const char* name)
     : m_name(name)
-    , m_verbose(false)
+    , m_isVerbose(false)
   {
     int segnum = 0;
     char* buf = new char[MAX_SEG_SIZE];
     do
       {
         std::cin.read(buf, MAX_SEG_SIZE);
-        int got = std::cin.gcount ();
+        int got = std::cin.gcount();
 
         if (got > 0)
           {
-            ndn::shared_ptr<ndn::Data> data =
-              ndn::make_shared<ndn::Data>(ndn::Name(m_name).appendSegment(segnum));
+            shared_ptr<Data> data =
+              make_shared<Data>(Name(m_name).appendSegment(segnum));
 
-            data->setFreshnessPeriod(ndn::time::milliseconds(10000)); // 10 sec
+            data->setFreshnessPeriod(time::milliseconds(10000)); // 10 sec
             data->setContent(reinterpret_cast<const uint8_t*>(buf), got);
 
             m_keychain.sign(*data);
@@ -52,14 +54,14 @@
       }
     while (static_cast<bool>(std::cin));
 
-    if (m_verbose)
+    if (m_isVerbose)
       std::cerr << "Created " << segnum << " chunks for prefix [" << m_name << "]" << std::endl;
   }
 
   void
-  onInterest(const ndn::Name& name, const ndn::Interest& interest)
+  onInterest(const Name& name, const Interest& interest)
   {
-    if (m_verbose)
+    if (m_isVerbose)
       std::cerr << "<< I: " << interest << std::endl;
 
     size_t segnum = static_cast<size_t>(interest.getName().rbegin()->toSegment());
@@ -71,7 +73,7 @@
   }
 
   void
-  onRegisterFailed(const ndn::Name& prefix, const std::string& reason)
+  onRegisterFailed(const Name& prefix, const std::string& reason)
   {
     std::cerr << "ERROR: Failed to register prefix in local hub's daemon (" << reason << ")" << std::endl;
     m_face.shutdown();
@@ -87,23 +89,23 @@
       }
 
     m_face.setInterestFilter(m_name,
-                             ndn::bind(&Producer::onInterest, this, _1, _2),
-                             ndn::bind(&Producer::onRegisterFailed, this, _1, _2));
+                             bind(&Producer::onInterest, this, _1, _2),
+                             bind(&Producer::onRegisterFailed, this, _1, _2));
     m_face.processEvents();
   }
 
 private:
-  ndn::Name m_name;
-  ndn::Face m_face;
-  ndn::KeyChain m_keychain;
+  Name m_name;
+  Face m_face;
+  KeyChain m_keychain;
 
-  std::vector< ndn::shared_ptr<ndn::Data> > m_store;
+  std::vector< shared_ptr<Data> > m_store;
 
-  bool m_verbose;
+  bool m_isVerbose;
 };
 
 int
-main(int argc, char *argv[])
+main(int argc, char** argv)
 {
   if (argc < 2)
     {
@@ -113,17 +115,18 @@
 
   try
     {
-      ndn::time::steady_clock::TimePoint startTime = ndn::time::steady_clock::now();
+      time::steady_clock::TimePoint startTime = time::steady_clock::now();
 
       std::cerr << "Preparing the input..." << std::endl;
       Producer producer(argv[1]);
-      std::cerr << "Ready... (took " << (ndn::time::steady_clock::now() - startTime) << std::endl;
+      std::cerr << "Ready... (took " << (time::steady_clock::now() - startTime) << std::endl;
 
       while (true)
         {
           try
             {
-              producer.run(); // this will exit when daemon dies... so try to connect again if possible
+              // this will exit when daemon dies... so try to connect again if possible
+              producer.run();
             }
           catch (std::exception& e)
             {
@@ -139,3 +142,11 @@
     }
   return 0;
 }
+
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::main(argc, argv);
+}