security: get KeyDigest from PublicKey.

Change-Id: Ibb7cf0aba262dbb80d5ea1d2da02318963c0f417
Refs: #1964
diff --git a/src/security/public-key.cpp b/src/security/public-key.cpp
index 801fe6c..07b8137 100644
--- a/src/security/public-key.cpp
+++ b/src/security/public-key.cpp
@@ -25,6 +25,7 @@
 #include "public-key.hpp"
 
 #include "../encoding/oid.hpp"
+#include "../util/crypto.hpp"
 #include "cryptopp.hpp"
 
 namespace ndn {
@@ -41,6 +42,22 @@
   decode(src);
 }
 
+const Block&
+PublicKey::computeDigest() const
+{
+  if (m_key.empty())
+    throw Error("Public key is empty");
+
+  if (m_digest.hasWire())
+    return m_digest;
+  else {
+    m_digest = Block(tlv::KeyDigest, crypto::sha256(m_key.buf(), m_key.size()));
+    m_digest.encode();
+    return m_digest;
+  }
+}
+
+
 void
 PublicKey::encode(CryptoPP::BufferedTransformation& out) const
 {
@@ -105,6 +122,8 @@
       m_type = KEY_TYPE_NULL;
       throw Error("PublicKey decoding error");
     }
+
+  m_digest.reset();
 }
 
 // Blob
diff --git a/src/security/public-key.hpp b/src/security/public-key.hpp
index 243bccc..e739717 100644
--- a/src/security/public-key.hpp
+++ b/src/security/public-key.hpp
@@ -29,6 +29,7 @@
 #include "../common.hpp"
 
 #include "../encoding/buffer.hpp"
+#include "../encoding/block.hpp"
 #include "security-common.hpp"
 
 namespace CryptoPP {
@@ -84,6 +85,12 @@
     return m_type;
   }
 
+  /**
+   * @return a KeyDigest block that matches this public key
+   */
+  const Block&
+  computeDigest() const;
+
   void
   encode(CryptoPP::BufferedTransformation& out) const;
 
@@ -105,6 +112,7 @@
 private:
   KeyType m_type;
   Buffer m_key;
+  mutable Block m_digest;
 };
 
 std::ostream&