fix verify signature bug;
add log info when content cannot be verified in fetcher

Change-Id: I7742f46848a3e108e8f57b2e8c39d044e6eb4997
diff --git a/ccnx/ccnx-wrapper.cpp b/ccnx/ccnx-wrapper.cpp
index af64b87..c498515 100644
--- a/ccnx/ccnx-wrapper.cpp
+++ b/ccnx/ccnx-wrapper.cpp
@@ -669,7 +669,7 @@
 bool
 CcnxWrapper::verifyPco(PcoPtr &pco)
 {
-  bool verified = ccn_verify_content(m_handle, pco->msg(), (ccn_parsed_ContentObject *)pco->pco());
+  bool verified = (ccn_verify_content(m_handle, pco->msg(), (ccn_parsed_ContentObject *)pco->pco()) == 0);
   pco->setVerified(verified);
   return verified;
 }
diff --git a/src/fetcher.cc b/src/fetcher.cc
index 8f78323..d59f457 100644
--- a/src/fetcher.cc
+++ b/src/fetcher.cc
@@ -133,10 +133,18 @@
   if (m_forwardingHint == Name ())
   {
     // check whether data is verified in this case; if verified invoke callback
-    if (!m_segmentCallback.empty () && data->verified())
+    if (data->verified())
+    {
+      if (!m_segmentCallback.empty ())
       {
         m_segmentCallback (m_deviceName, m_name, seqno, data);
       }
+    }
+    else
+    {
+      _LOG_ERROR("Can not verify signature content. Name = " << data->name());
+      // probably needs to do more in the future
+    }
     // we don't have to tell FetchManager about this
   }
   else
@@ -146,10 +154,18 @@
         PcoPtr pco = make_shared<ParsedContentObject> (*data->contentPtr ());
 
         // we need to verify this pco and apply callback only when verified
-        if (!m_segmentCallback.empty () && m_ccnx->verifyPco(pco))
-          {
-            m_segmentCallback (m_deviceName, m_name, seqno, pco);
-          }
+        if (m_ccnx->verifyPco(pco))
+        {
+          if (!m_segmentCallback.empty ())
+            {
+              m_segmentCallback (m_deviceName, m_name, seqno, pco);
+            }
+        }
+        else
+        {
+          _LOG_ERROR("Can not verify signature content. Name = " << pco->name());
+          // probably needs to do more in the future
+        }
       }
       catch (MisformedContentObjectException &e)
         {
diff --git a/test/test-ccnx-wrapper.cc b/test/test-ccnx-wrapper.cc
index def7876..06535fc 100644
--- a/test/test-ccnx-wrapper.cc
+++ b/test/test-ccnx-wrapper.cc
@@ -62,6 +62,15 @@
   BOOST_CHECK_EQUAL(name, msg);
 }
 
+void encapCallback(const Name &name, Ccnx::PcoPtr pco)
+{
+  cout << " in encap data callback" << endl;
+  PcoPtr npco = make_shared<ParsedContentObject> (*(pco->contentPtr()));
+  g_dataCallback_counter ++;
+  BOOST_CHECK(npco);
+  BOOST_CHECK(c1->verifyPco(npco));
+}
+
 void
 timeout(const Name &name, const Closure &closure, Selectors selectors)
 {
@@ -192,6 +201,14 @@
   c2->publishUnsignedData(Name(n1), (const unsigned char *)n1.c_str(), n1.size(), 1);
   usleep(1000);
   BOOST_CHECK_EQUAL(g_dataCallback_counter, 1);
+
+  string n2 = "/xxxxxx/signed/01";
+  Bytes content = c1->createContentObject(Name(n1), (const unsigned char *)n2.c_str(), n2.size(), 1);
+  c1->publishUnsignedData(Name(n2), head(content), content.size(), 1);
+  Closure encapClosure(bind(encapCallback, _1, _2), bind(timeout, _1, _2, _3));
+  c2->sendInterest(Name(n2), encapClosure);
+  usleep(2000);
+  BOOST_CHECK_EQUAL(g_dataCallback_counter, 2);
   teardown();
 }
 
@@ -223,4 +240,5 @@
     teardown();
  }
 
+
 BOOST_AUTO_TEST_SUITE_END()