security: Fix bug of checking signed interest in ValidatorConfig

If signatureInfo or signatureValue is malformed, decoding process will throw
an excetpion. This commit enables ValidatorConfig to catch the exception and
invoke onValidationFailed.

Refs: #1493

Change-Id: Ic0f960bece458a7c993f380586fc4aed10640732
diff --git a/src/security/conf/checker.hpp b/src/security/conf/checker.hpp
index 3fa8d94..b1aaf7b 100644
--- a/src/security/conf/checker.hpp
+++ b/src/security/conf/checker.hpp
@@ -94,10 +94,23 @@
         const OnInterestChecked& onValidated,
         const OnInterestCheckFailed& onValidationFailed)
   {
-    const Name& interestName = interest.getName();
-    Signature signature(interestName[INTEREST_SIG_INFO].blockFromValue(),
-                        interestName[INTEREST_SIG_VALUE].blockFromValue());
-    return check(interest, signature, onValidated, onValidationFailed);
+    try
+      {
+        const Name& interestName = interest.getName();
+        Signature signature(interestName[INTEREST_SIG_INFO].blockFromValue(),
+                            interestName[INTEREST_SIG_VALUE].blockFromValue());
+        return check(interest, signature, onValidated, onValidationFailed);
+      }
+    catch (const Tlv::Error& e)
+      {
+        onValidationFailed(interest.shared_from_this(), "Cannot decode signature related TLVs");
+        return -1;
+      }
+    catch (const Signature::Error& e)
+      {
+        onValidationFailed(interest.shared_from_this(), "No valid signature");
+        return -1;
+      }
   }
 
 private:
@@ -201,10 +214,23 @@
         const OnInterestChecked& onValidated,
         const OnInterestCheckFailed& onValidationFailed)
   {
-    const Name& interestName = interest.getName();
-    Signature signature(interestName[INTEREST_SIG_INFO].blockFromValue(),
-                        interestName[INTEREST_SIG_VALUE].blockFromValue());
-    return check(interest, signature, onValidated, onValidationFailed);
+    try
+      {
+        const Name& interestName = interest.getName();
+        Signature signature(interestName[INTEREST_SIG_INFO].blockFromValue(),
+                            interestName[INTEREST_SIG_VALUE].blockFromValue());
+        return check(interest, signature, onValidated, onValidationFailed);
+      }
+    catch (const Tlv::Error& e)
+      {
+        onValidationFailed(interest.shared_from_this(), "Cannot decode signature related TLVs");
+        return -1;
+      }
+    catch (const Signature::Error& e)
+      {
+        onValidationFailed(interest.shared_from_this(), "No valid signature");
+        return -1;
+      }
   }
 
 private: