interest: Interest::matchesData function

refs #1157

Change-Id: I5b74367cb1afed75728e2d5092ced5d269332f9d
diff --git a/src/interest.cpp b/src/interest.cpp
index a49ee1f..8734274 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -9,6 +9,7 @@
 
 #include "interest.hpp"
 #include "util/random.hpp"
+#include "data.hpp"
 
 using namespace std;
 
@@ -51,6 +52,29 @@
   return true;
 }
 
+bool
+Interest::matchesData(const Data& data) const
+{
+  if (!this->matchesName(data.getName())) {
+    return false;
+  }
+
+  const KeyLocator& publisherPublicKeyLocator = this->getPublisherPublicKeyLocator();
+  if (!publisherPublicKeyLocator.empty()) {
+    const Signature& signature = data.getSignature();
+    const Block& signatureInfo = signature.getInfo();
+    Block::element_const_iterator it = signatureInfo.find(Tlv::KeyLocator);
+    if (it == signatureInfo.elements_end()) {
+      return false;
+    }
+    if (publisherPublicKeyLocator.wireEncode() != *it) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
 std::ostream &
 operator << (std::ostream &os, const Interest &interest)
 {