diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index ecd9453..7f8169d 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -71,7 +71,7 @@
   FinalBlockId  = 26,
   SignatureType = 27,
   KeyLocator    = 28,
-  KeyLocatorDigest = 29,
+  KeyDigest     = 29,
 
   AppPrivateBlock1 = 128,
   AppPrivateBlock2 = 32767
diff --git a/src/key-locator.cpp b/src/key-locator.cpp
new file mode 100644
index 0000000..ba17771
--- /dev/null
+++ b/src/key-locator.cpp
@@ -0,0 +1,185 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "key-locator.hpp"
+#include "encoding/block-helpers.hpp"
+
+namespace ndn {
+
+KeyLocator::KeyLocator()
+  : m_type(KeyLocator_None)
+{
+}
+
+KeyLocator::KeyLocator(const Block& wire)
+{
+  wireDecode(wire);
+}
+
+KeyLocator::KeyLocator(const Name& name)
+{
+  setName(name);
+}
+
+template<bool T>
+size_t
+KeyLocator::wireEncode(EncodingImpl<T>& block) const
+{
+  // KeyLocator ::= KEY-LOCATOR-TYPE TLV-LENGTH (Name | KeyDigest)
+  // KeyDigest ::= KEY-DIGEST-TYPE TLV-LENGTH BYTE+
+
+  size_t totalLength = 0;
+
+  switch (m_type) {
+  case KeyLocator_None:
+    break;
+  case KeyLocator_Name:
+    totalLength += m_name.wireEncode(block);
+    break;
+  case KeyLocator_KeyDigest:
+    totalLength += block.prependBlock(m_keyDigest);
+    break;
+  default:
+    throw Error("Unsupported KeyLocator type");
+  }
+
+  totalLength += block.prependVarNumber(totalLength);
+  totalLength += block.prependVarNumber(tlv::KeyLocator);
+  return totalLength;
+}
+
+template size_t
+KeyLocator::wireEncode<true>(EncodingImpl<true>& estimator) const;
+
+template size_t
+KeyLocator::wireEncode<false>(EncodingImpl<false>& encoder) const;
+
+const Block&
+KeyLocator::wireEncode() const
+{
+  if (m_wire.hasWire())
+    return m_wire;
+
+  EncodingEstimator estimator;
+  size_t estimatedSize = wireEncode(estimator);
+
+  EncodingBuffer buffer(estimatedSize, 0);
+  wireEncode(buffer);
+
+  m_wire = buffer.block();
+  return m_wire;
+}
+
+void
+KeyLocator::wireDecode(const Block& wire)
+{
+  if (wire.type() != tlv::KeyLocator)
+    throw Error("Unexpected TLV type during KeyLocator decoding");
+
+  m_wire = wire;
+  m_wire.parse();
+
+  if (m_wire.elements().empty()) {
+    m_type = KeyLocator_None;
+    return;
+  }
+
+  switch (m_wire.elements_begin()->type()) {
+  case tlv::Name:
+    m_type = KeyLocator_Name;
+    m_name.wireDecode(*m_wire.elements_begin());
+    break;
+  case tlv::KeyDigest:
+    m_type = KeyLocator_KeyDigest;
+    m_keyDigest = *m_wire.elements_begin();
+    break;
+  default:
+    m_type = KeyLocator_Unknown;
+    break;
+  }
+}
+
+KeyLocator&
+KeyLocator::clear()
+{
+  m_wire.reset();
+  m_type = KeyLocator_None;
+  m_name.clear();
+  m_keyDigest.reset();
+  return *this;
+}
+
+const Name&
+KeyLocator::getName() const
+{
+  if (m_type != KeyLocator_Name)
+    throw Error("KeyLocator type is not Name");
+
+  return m_name;
+}
+
+KeyLocator&
+KeyLocator::setName(const Name& name)
+{
+  this->clear();
+  m_type = KeyLocator_Name;
+  m_name = name;
+  return *this;
+}
+
+const Block&
+KeyLocator::getKeyDigest() const
+{
+  if (m_type != KeyLocator_KeyDigest)
+    throw Error("KeyLocator type is not KeyDigest");
+
+  return m_keyDigest;
+}
+
+KeyLocator&
+KeyLocator::setKeyDigest(const Block& keyDigest)
+{
+  if (keyDigest.type() != tlv::KeyDigest)
+    throw Error("expecting KeyDigest block");
+
+  this->clear();
+  m_type = KeyLocator_KeyDigest;
+  m_keyDigest = keyDigest;
+  return *this;
+}
+
+KeyLocator&
+KeyLocator::setKeyDigest(const ConstBufferPtr& keyDigest)
+{
+  // WARNING: ConstBufferPtr is shared_ptr<const Buffer>
+  // This function takes a constant reference of a shared pointer.
+  // It MUST NOT change the reference count of that shared pointer.
+
+  return this->setKeyDigest(dataBlock(tlv::KeyDigest, keyDigest->get(), keyDigest->size()));
+}
+
+bool
+KeyLocator::operator==(const KeyLocator& other) const
+{
+  return wireEncode() == other.wireEncode();
+}
+
+} // namespace ndn
diff --git a/src/key-locator.hpp b/src/key-locator.hpp
index a86275d..2528912 100644
--- a/src/key-locator.hpp
+++ b/src/key-locator.hpp
@@ -22,9 +22,7 @@
 #ifndef NDN_KEY_LOCATOR_HPP
 #define NDN_KEY_LOCATOR_HPP
 
-#include "encoding/block.hpp"
 #include "encoding/encoding-buffer.hpp"
-
 #include "name.hpp"
 
 namespace ndn {
@@ -42,174 +40,128 @@
     }
   };
 
-  enum {
-    KeyLocator_None = 65535, // just an arbitrarily large number (used only internally)
+  enum Type {
+    /** \brief indicates KeyLocator is empty (internal use only)
+     */
+    KeyLocator_None = 65535,
+    /** \brief indicates KeyLocator contains a Name
+     */
     KeyLocator_Name = 0,
-
+    /** \brief indicates KeyLocator contains a KeyDigest
+     */
+    KeyLocator_KeyDigest = 1,
+    /** \brief indicates KeyLocator contains an unknown element
+     */
     KeyLocator_Unknown = 255
   };
 
-  KeyLocator()
-    : m_type(KeyLocator_None)
-  {
-  }
+public: // constructors
+  /** \brief construct an empty KeyLocator
+   */
+  KeyLocator();
 
-  KeyLocator(const Name& name)
-  {
-    setName(name);
-  }
-
-  /**
-   * @brief Create from wire encoding
+  /** \brief construct from wire encoding
    */
   explicit
-  KeyLocator(const Block& wire)
-  {
-    wireDecode(wire);
-  }
+  KeyLocator(const Block& wire);
 
-  ///////////////////////////////////////////////////////////////////////////////
+  /** \brief construct from Name
+   *  \note implicit conversion is permitted
+   */
+  KeyLocator(const Name& name);
 
+public: // encode and decode
+  /** \brief prepend wire encoding
+   *  \param block EncodingBuffer or Estimator
+   */
   template<bool T>
   size_t
   wireEncode(EncodingImpl<T>& block) const;
 
+  /** \return wire encoding
+   */
   const Block&
   wireEncode() const;
 
+  /** \brief decode from wire encoding
+   *  \throw Error outer TLV type is not KeyLocator
+   *  \note No error is thrown for unrecognized inner TLV, but type becomes KeyLocator_Unknown.
+   */
   void
   wireDecode(const Block& wire);
 
-  ///////////////////////////////////////////////////////////////////////////////
-
+public: // attributes
   bool
   empty() const
   {
     return m_type == KeyLocator_None;
   }
 
-  uint32_t
-  getType() const { return m_type; }
+  Type
+  getType() const
+  {
+    return m_type;
+  }
 
-  ////////////////////////////////////////////////////////
-  // Helper methods for different types of key locators
-  //
-  // For now only Name type is actually supported
+  /** \brief clear KeyLocator
+   *  \details type becomes KeyLocator_None
+   *  \return self
+   */
+  KeyLocator&
+  clear();
 
+  /** \brief get Name element
+   *  \throw Error if type is not KeyLocator_Name
+   */
   const Name&
   getName() const;
 
-  void
+  /** \brief set Name element
+   *  \details type becomes KeyLocator_Name
+   *  \return self
+   */
+  KeyLocator&
   setName(const Name& name);
 
+  /** \brief get KeyDigest element
+   *  \throw Error if type is not KeyLocator_KeyDigest
+   */
+  const Block&
+  getKeyDigest() const;
+
+  /** \brief set KeyDigest element
+   *  \details type becomes KeyLocator_KeyDigest
+   *  \throw Error if Block type is not KeyDigest
+   *  \return self
+   */
+  KeyLocator&
+  setKeyDigest(const Block& keyDigest);
+
+  /** \brief set KeyDigest value
+   *  \details type becomes KeyLocator_KeyDigest
+   *  \return self
+   */
+  KeyLocator&
+  setKeyDigest(const ConstBufferPtr& keyDigest);
+
 public: // EqualityComparable concept
   bool
   operator==(const KeyLocator& other) const;
 
   bool
-  operator!=(const KeyLocator& other) const;
+  operator!=(const KeyLocator& other) const
+  {
+    return !this->operator==(other);
+  }
 
 private:
-  uint32_t m_type;
+  Type m_type;
   Name m_name;
+  Block m_keyDigest;
 
   mutable Block m_wire;
 };
 
-template<bool T>
-inline size_t
-KeyLocator::wireEncode(EncodingImpl<T>& block) const
-{
-  // KeyLocator ::= KEY-LOCATOR-TYPE TLV-LENGTH KeyLocatorValue
-
-  // KeyLocatorValue ::= Name |
-  //                     KeyLocatorDigest |     (not supported yet)
-  //                     ...
-
-  // KeyLocatorDigest ::= KEY-LOCATOR-DIGEST-TYPE TLV-LENGTH BYTE+
-
-  size_t totalLength = 0;
-
-  switch (m_type) {
-  case KeyLocator_None:
-    break;
-  case KeyLocator_Name:
-    totalLength += m_name.wireEncode(block);
-    break;
-  default:
-    throw Error("Unsupported KeyLocator type");
-  }
-
-  totalLength += block.prependVarNumber(totalLength);
-  totalLength += block.prependVarNumber(tlv::KeyLocator);
-  return totalLength;
-}
-
-inline const Block&
-KeyLocator::wireEncode() const
-{
-  if (m_wire.hasWire())
-    return m_wire;
-
-  EncodingEstimator estimator;
-  size_t estimatedSize = wireEncode(estimator);
-
-  EncodingBuffer buffer(estimatedSize, 0);
-  wireEncode(buffer);
-
-  m_wire = buffer.block();
-  return m_wire;
-}
-
-inline void
-KeyLocator::wireDecode(const Block& value)
-{
-  if (value.type() != tlv::KeyLocator)
-    throw Error("Unexpected TLV type during KeyLocator decoding");
-
-  m_wire = value;
-  m_wire.parse();
-
-  if (!m_wire.elements().empty() && m_wire.elements_begin()->type() == tlv::Name)
-    {
-      m_type = KeyLocator_Name;
-      m_name.wireDecode(*m_wire.elements_begin());
-    }
-  else
-    {
-      m_type = KeyLocator_Unknown;
-    }
-}
-
-inline const Name&
-KeyLocator::getName() const
-{
-  if (m_type != KeyLocator_Name)
-    throw Error("Requested Name, but KeyLocator is not of the Name type");
-
-  return m_name;
-}
-
-inline void
-KeyLocator::setName(const Name& name)
-{
-  m_wire.reset();
-  m_type = KeyLocator_Name;
-  m_name = name;
-}
-
-inline bool
-KeyLocator::operator==(const KeyLocator& other) const
-{
-  return wireEncode() == other.wireEncode();
-}
-
-inline bool
-KeyLocator::operator!=(const KeyLocator& other) const
-{
-  return !this->operator==(other);
-}
-
 } // namespace ndn
 
-#endif
+#endif // NDN_KEY_LOCATOR_HPP
