security: minor cleanup

Change-Id: Ibedce96a5f1fecc61149f354384194fae4fa39cb
Refs: #4542
diff --git a/src/security/v2/validation-policy-command-interest.cpp b/src/security/v2/validation-policy-command-interest.cpp
index d765e44..7e04bad 100644
--- a/src/security/v2/validation-policy-command-interest.cpp
+++ b/src/security/v2/validation-policy-command-interest.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -20,7 +20,6 @@
  */
 
 #include "validation-policy-command-interest.hpp"
-#include "../pib/key.hpp"
 
 namespace ndn {
 namespace security {
@@ -37,7 +36,7 @@
   }
   setInnerPolicy(std::move(inner));
 
-  m_options.gracePeriod = std::max(m_options.gracePeriod, time::nanoseconds::zero());
+  m_options.gracePeriod = std::max(m_options.gracePeriod, 0_ns);
 }
 
 void
@@ -68,7 +67,7 @@
 void
 ValidationPolicyCommandInterest::cleanup()
 {
-  time::steady_clock::TimePoint expiring = time::steady_clock::now() - m_options.recordLifetime;
+  auto expiring = time::steady_clock::now() - m_options.recordLifetime;
 
   while ((!m_queue.empty() && m_queue.front().lastRefreshed <= expiring) ||
          (m_options.maxRecords >= 0 &&
@@ -109,33 +108,35 @@
 {
   this->cleanup();
 
-  time::system_clock::TimePoint now = time::system_clock::now();
-  time::system_clock::TimePoint timestampPoint = time::fromUnixTimestamp(time::milliseconds(timestamp));
+  auto now = time::system_clock::now();
+  auto timestampPoint = time::fromUnixTimestamp(time::milliseconds(timestamp));
   if (timestampPoint < now - m_options.gracePeriod || timestampPoint > now + m_options.gracePeriod) {
-    state->fail({ValidationError::POLICY_ERROR, "Timestamp is outside the grace period for key " + keyName.toUri()});
+    state->fail({ValidationError::POLICY_ERROR,
+                 "Timestamp is outside the grace period for key " + keyName.toUri()});
     return false;
   }
+
   auto it = m_index.find(keyName);
   if (it != m_index.end()) {
     if (timestamp <= it->timestamp) {
-      state->fail({ValidationError::POLICY_ERROR, "Timestamp is reordered for key " + keyName.toUri()});
+      state->fail({ValidationError::POLICY_ERROR,
+                   "Timestamp is reordered for key " + keyName.toUri()});
       return false;
     }
   }
 
-  shared_ptr<InterestValidationState> interestState = std::dynamic_pointer_cast<InterestValidationState>(state);
-  interestState->afterSuccess.connect(bind(&ValidationPolicyCommandInterest::insertNewRecord,
-                                           this, _1, keyName, timestamp));
+  auto interestState = dynamic_pointer_cast<InterestValidationState>(state);
+  BOOST_ASSERT(interestState != nullptr);
+  interestState->afterSuccess.connect([=] (const Interest&) { insertNewRecord(keyName, timestamp); });
   return true;
 }
 
 void
-ValidationPolicyCommandInterest::insertNewRecord(const Interest& interest, const Name& keyName,
-                                                 uint64_t timestamp)
+ValidationPolicyCommandInterest::insertNewRecord(const Name& keyName, uint64_t timestamp)
 {
   // try to insert new record
-  time::steady_clock::TimePoint now = time::steady_clock::now();
-  Queue::iterator i = m_queue.end();
+  auto now = time::steady_clock::now();
+  auto i = m_queue.end();
   bool isNew = false;
   LastTimestampRecord newRecord{keyName, timestamp, now};
   std::tie(i, isNew) = m_queue.push_back(newRecord);
diff --git a/src/security/v2/validation-policy-command-interest.hpp b/src/security/v2/validation-policy-command-interest.hpp
index 84a7be8..0630fa4 100644
--- a/src/security/v2/validation-policy-command-interest.hpp
+++ b/src/security/v2/validation-policy-command-interest.hpp
@@ -23,6 +23,7 @@
 #define NDN_SECURITY_V2_VALIDATION_POLICY_COMMAND_INTEREST_HPP
 
 #include "validation-policy.hpp"
+
 #include <boost/multi_index_container.hpp>
 #include <boost/multi_index/ordered_index.hpp>
 #include <boost/multi_index/sequenced_index.hpp>
@@ -122,11 +123,9 @@
                  const Name& keyName, uint64_t timestamp);
 
   void
-  insertNewRecord(const Interest& interest, const Name& keyName,
-                  uint64_t timestamp);
+  insertNewRecord(const Name& keyName, uint64_t timestamp);
 
 private:
-  unique_ptr<ValidationPolicy> m_innerPolicy;
   Options m_options;
 
   struct LastTimestampRecord
@@ -136,7 +135,7 @@
     time::steady_clock::TimePoint lastRefreshed;
   };
 
-  typedef boost::multi_index_container<
+  using Container = boost::multi_index_container<
     LastTimestampRecord,
     boost::multi_index::indexed_by<
       boost::multi_index::ordered_unique<
@@ -144,9 +143,9 @@
       >,
       boost::multi_index::sequenced<>
     >
-  > Container;
-  typedef Container::nth_index<0>::type Index;
-  typedef Container::nth_index<1>::type Queue;
+  >;
+  using Index = Container::nth_index<0>::type;
+  using Queue = Container::nth_index<1>::type;
 
   Container m_container;
   Index& m_index;
diff --git a/src/security/v2/validation-policy-config.cpp b/src/security/v2/validation-policy-config.cpp
index 0f0bb84..f6f6ed6 100644
--- a/src/security/v2/validation-policy-config.cpp
+++ b/src/security/v2/validation-policy-config.cpp
@@ -23,11 +23,13 @@
 #include "validator.hpp"
 #include "../../util/io.hpp"
 
-#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/property_tree/info_parser.hpp>
 
+#include <fstream>
+
 namespace ndn {
 namespace security {
 namespace v2 {
@@ -42,15 +44,11 @@
 void
 ValidationPolicyConfig::load(const std::string& filename)
 {
-  std::ifstream inputFile;
-  inputFile.open(filename.c_str());
-  if (!inputFile.good() || !inputFile.is_open()) {
-    std::string msg = "Failed to read configuration file: ";
-    msg += filename;
-    BOOST_THROW_EXCEPTION(Error(msg));
+  std::ifstream inputFile(filename);
+  if (!inputFile) {
+    BOOST_THROW_EXCEPTION(Error("Failed to read configuration file: " + filename));
   }
   load(inputFile, filename);
-  inputFile.close();
 }
 
 void
@@ -67,26 +65,20 @@
   try {
     boost::property_tree::read_info(input, tree);
   }
-  catch (const boost::property_tree::info_parser_error& error) {
-    std::stringstream msg;
-    msg << "Failed to parse configuration file";
-    msg << " " << filename;
-    msg << " " << error.message() << " line " << error.line();
-    BOOST_THROW_EXCEPTION(Error(msg.str()));
+  catch (const boost::property_tree::info_parser_error& e) {
+    BOOST_THROW_EXCEPTION(Error("Failed to parse configuration file " + filename +
+                                " line " + to_string(e.line()) + ": " + e.message()));
   }
-
   load(tree, filename);
 }
 
 void
-ValidationPolicyConfig::load(const ConfigSection& configSection,
-                             const std::string& filename)
+ValidationPolicyConfig::load(const ConfigSection& configSection, const std::string& filename)
 {
   if (m_isConfigured) {
     m_shouldBypass = false;
     m_dataRules.clear();
     m_interestRules.clear();
-
     m_validator->resetAnchors();
     m_validator->resetVerifiedCertificates();
   }
@@ -95,11 +87,7 @@
   BOOST_ASSERT(!filename.empty());
 
   if (configSection.begin() == configSection.end()) {
-    std::string msg = "Error processing configuration file";
-    msg += ": ";
-    msg += filename;
-    msg += " no data";
-    BOOST_THROW_EXCEPTION(Error(msg));
+    BOOST_THROW_EXCEPTION(Error("Error processing configuration file " + filename + ": no data"));
   }
 
   for (const auto& subSection : configSection) {
@@ -119,21 +107,19 @@
       processConfigTrustAnchor(section, filename);
     }
     else {
-      std::string msg = "Error processing configuration file";
-      msg += " ";
-      msg += filename;
-      msg += " unrecognized section: " + sectionName;
-      BOOST_THROW_EXCEPTION(Error(msg));
+      BOOST_THROW_EXCEPTION(Error("Error processing configuration file " + filename +
+                                  ": unrecognized section " + sectionName));
     }
   }
 }
 
 void
-ValidationPolicyConfig::processConfigTrustAnchor(const ConfigSection& configSection, const std::string& filename)
+ValidationPolicyConfig::processConfigTrustAnchor(const ConfigSection& configSection,
+                                                 const std::string& filename)
 {
   using namespace boost::filesystem;
 
-  ConfigSection::const_iterator propertyIt = configSection.begin();
+  auto propertyIt = configSection.begin();
 
   // Get trust-anchor.type
   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type")) {
@@ -153,13 +139,11 @@
     propertyIt++;
 
     time::nanoseconds refresh = getRefreshPeriod(propertyIt, configSection.end());
-    if (propertyIt != configSection.end()) {
-      BOOST_THROW_EXCEPTION(Error("Expect the end of trust-anchor!"));
-    }
+    if (propertyIt != configSection.end())
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <trust-anchor>"));
 
     m_validator->loadAnchor(filename, absolute(file, path(filename).parent_path()).string(),
                             refresh, false);
-    return;
   }
   else if (boost::iequals(type, "base64")) {
     // Get trust-anchor.base64-string
@@ -169,9 +153,8 @@
     std::stringstream ss(propertyIt->second.data());
     propertyIt++;
 
-    // Check other stuff
     if (propertyIt != configSection.end())
-      BOOST_THROW_EXCEPTION(Error("Expecting the end of trust-anchor"));
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <trust-anchor>"));
 
     auto idCert = io::load<Certificate>(ss);
     if (idCert != nullptr) {
@@ -180,30 +163,26 @@
     else {
       BOOST_THROW_EXCEPTION(Error("Cannot decode certificate from base64-string"));
     }
-
-    return;
   }
   else if (boost::iequals(type, "dir")) {
     if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "dir"))
-      BOOST_THROW_EXCEPTION(Error("Expect <trust-anchor.dir>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <trust-anchor.dir>"));
 
     std::string dirString(propertyIt->second.data());
     propertyIt++;
 
     time::nanoseconds refresh = getRefreshPeriod(propertyIt, configSection.end());
-    if (propertyIt != configSection.end()) {
-      BOOST_THROW_EXCEPTION(Error("Expecting the end of trust-anchor"));
-    }
+    if (propertyIt != configSection.end())
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <trust-anchor>"));
 
     path dirPath = absolute(dirString, path(filename).parent_path());
     m_validator->loadAnchor(dirString, dirPath.string(), refresh, true);
-    return;
   }
   else if (boost::iequals(type, "any")) {
     m_shouldBypass = true;
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("Unsupported trust-anchor.type: " + type));
+    BOOST_THROW_EXCEPTION(Error("Unrecognized <trust-anchor.type>: " + type));
   }
 }
 
@@ -211,7 +190,7 @@
 ValidationPolicyConfig::getRefreshPeriod(ConfigSection::const_iterator& it,
                                          const ConfigSection::const_iterator& end)
 {
-  time::nanoseconds refresh = time::nanoseconds::max();
+  auto refresh = time::nanoseconds::max();
   if (it == end) {
     return refresh;
   }
@@ -222,17 +201,18 @@
 
   std::string inputString = it->second.data();
   ++it;
-
   char unit = inputString[inputString.size() - 1];
   std::string refreshString = inputString.substr(0, inputString.size() - 1);
 
-  uint32_t refreshPeriod = 0;
-
+  int32_t refreshPeriod = -1;
   try {
-    refreshPeriod = boost::lexical_cast<uint32_t>(refreshString);
+    refreshPeriod = boost::lexical_cast<int32_t>(refreshString);
   }
   catch (const boost::bad_lexical_cast&) {
-    BOOST_THROW_EXCEPTION(Error("Bad number: " + refreshString));
+    // pass
+  }
+  if (refreshPeriod < 0) {
+    BOOST_THROW_EXCEPTION(Error("Bad refresh value: " + refreshString));
   }
 
   if (refreshPeriod == 0) {
@@ -247,7 +227,7 @@
     case 's':
       return time::seconds(refreshPeriod);
     default:
-      BOOST_THROW_EXCEPTION(Error(std::string("Wrong time unit: ") + unit));
+      BOOST_THROW_EXCEPTION(Error(std::string("Bad refresh time unit: ") + unit));
   }
 }
 
@@ -282,7 +262,8 @@
     }
   }
 
-  return state->fail({ValidationError::POLICY_ERROR, "No rule matched for data `" + data.getName().toUri() + "`"});
+  return state->fail({ValidationError::POLICY_ERROR,
+                      "No rule matched for data `" + data.getName().toUri() + "`"});
 }
 
 void
@@ -310,7 +291,8 @@
     }
   }
 
-  return state->fail({ValidationError::POLICY_ERROR, "No rule matched for interest `" + interest.getName().toUri() + "`"});
+  return state->fail({ValidationError::POLICY_ERROR,
+                      "No rule matched for interest `" + interest.getName().toUri() + "`"});
 }
 
 } // namespace validator_config
diff --git a/src/security/v2/validator-config/checker.cpp b/src/security/v2/validator-config/checker.cpp
index dc4d49a..908e126 100644
--- a/src/security/v2/validator-config/checker.cpp
+++ b/src/security/v2/validator-config/checker.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -23,11 +23,8 @@
 #include "security/v2/validation-state.hpp"
 #include "security/verification-helpers.hpp"
 #include "security/pib/key.hpp"
-#include "util/logger.hpp"
 
-#include <boost/algorithm/string.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string/predicate.hpp>
 
 namespace ndn {
 namespace security {
@@ -35,7 +32,8 @@
 namespace validator_config {
 
 bool
-Checker::check(uint32_t pktType, const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state)
+Checker::check(uint32_t pktType, const Name& pktName, const Name& klName,
+               const shared_ptr<ValidationState>& state)
 {
   BOOST_ASSERT(pktType == tlv::Interest || pktType == tlv::Data);
 
@@ -57,7 +55,8 @@
 }
 
 bool
-NameRelationChecker::checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state)
+NameRelationChecker::checkNames(const Name& pktName, const Name& klName,
+                                const shared_ptr<ValidationState>& state)
 {
   // pktName not used in this check
   Name identity = extractIdentityFromKeyName(klName);
@@ -87,7 +86,6 @@
        << " (KeyLocator=" << klName << ")";
     state->fail({ValidationError::POLICY_ERROR, os.str()});
   }
-
   return result;
 }
 
@@ -101,7 +99,8 @@
 }
 
 bool
-HyperRelationChecker::checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state)
+HyperRelationChecker::checkNames(const Name& pktName, const Name& klName,
+                                 const shared_ptr<ValidationState>& state)
 {
   if (!m_hyperPRegex.match(pktName) || !m_hyperKRegex.match(klName)) {
     std::ostringstream os;
@@ -129,11 +128,10 @@
 
   // Get checker.type
   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type")) {
-    BOOST_THROW_EXCEPTION(Error("Expect <checker.type>"));
+    BOOST_THROW_EXCEPTION(Error("Expecting <checker.type>"));
   }
 
   std::string type = propertyIt->second.data();
-
   if (boost::iequals(type, "customized")) {
     return createCustomizedChecker(configSection, configFilename);
   }
@@ -141,13 +139,13 @@
     return createHierarchicalChecker(configSection, configFilename);
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("Unsupported checker type: " + type));
+    BOOST_THROW_EXCEPTION(Error("Unrecognized <checker.type>: " + type));
   }
 }
 
 unique_ptr<Checker>
 Checker::createCustomizedChecker(const ConfigSection& configSection,
-                                        const std::string& configFilename)
+                                 const std::string& configFilename)
 {
   auto propertyIt = configSection.begin();
   propertyIt++;
@@ -161,22 +159,21 @@
 
   // Get checker.key-locator
   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "key-locator")) {
-    BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator>"));
+    BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator>"));
   }
 
   auto checker = createKeyLocatorChecker(propertyIt->second, configFilename);
   propertyIt++;
 
   if (propertyIt != configSection.end()) {
-    BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
+    BOOST_THROW_EXCEPTION(Error("Expecting end of <checker>"));
   }
-
   return checker;
 }
 
 unique_ptr<Checker>
 Checker::createHierarchicalChecker(const ConfigSection& configSection,
-                                          const std::string& configFilename)
+                                   const std::string& configFilename)
 {
   auto propertyIt = configSection.begin();
   propertyIt++;
@@ -189,54 +186,52 @@
   }
 
   if (propertyIt != configSection.end()) {
-    BOOST_THROW_EXCEPTION(Error("Expect the end of checker"));
+    BOOST_THROW_EXCEPTION(Error("Expecting end of <checker>"));
   }
-
   return make_unique<HyperRelationChecker>("^(<>*)$",        "\\1",
                                            "^(<>*)<KEY><>$", "\\1",
                                            NameRelation::IS_PREFIX_OF);
 }
 
-///
-
 unique_ptr<Checker>
-Checker::createKeyLocatorChecker(const ConfigSection& configSection, const std::string& configFilename)
+Checker::createKeyLocatorChecker(const ConfigSection& configSection,
+                                 const std::string& configFilename)
 {
   auto propertyIt = configSection.begin();
 
   // Get checker.key-locator.type
   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type"))
-    BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.type>"));
+    BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator.type>"));
 
   std::string type = propertyIt->second.data();
-
   if (boost::iequals(type, "name"))
     return createKeyLocatorNameChecker(configSection, configFilename);
   else
-    BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator.type: " + type));
+    BOOST_THROW_EXCEPTION(Error("Unrecognized <checker.key-locator.type>: " + type));
 }
 
 unique_ptr<Checker>
-Checker::createKeyLocatorNameChecker(const ConfigSection& configSection, const std::string& configFilename)
+Checker::createKeyLocatorNameChecker(const ConfigSection& configSection,
+                                     const std::string& configFilename)
 {
   auto propertyIt = configSection.begin();
   propertyIt++;
 
   if (propertyIt == configSection.end())
-    BOOST_THROW_EXCEPTION(Error("Expect more checker.key-locator properties"));
+    BOOST_THROW_EXCEPTION(Error("Unexpected end of <checker.key-locator>"));
 
   if (boost::iequals(propertyIt->first, "name")) {
     Name name;
     try {
       name = Name(propertyIt->second.data());
     }
-    catch (const Name::Error& e) {
-      BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.name: " + propertyIt->second.data()));
+    catch (const Name::Error&) {
+      BOOST_THROW_EXCEPTION(Error("Invalid <checker.key-locator.name>: " + propertyIt->second.data()));
     }
     propertyIt++;
 
     if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "relation")) {
-      BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.relation>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator.relation>"));
     }
 
     std::string relationString = propertyIt->second.data();
@@ -245,7 +240,7 @@
     NameRelation relation = getNameRelationFromString(relationString);
 
     if (propertyIt != configSection.end()) {
-      BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator"));
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <checker.key-locator>"));
     }
     return make_unique<NameRelationChecker>(name, relation);
   }
@@ -254,24 +249,23 @@
     propertyIt++;
 
     if (propertyIt != configSection.end()) {
-      BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator"));
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <checker.key-locator>"));
     }
 
     try {
       return make_unique<RegexChecker>(Regex(regexString));
     }
-    catch (const Regex::Error& e) {
-      BOOST_THROW_EXCEPTION(Error("Invalid checker.key-locator.regex: " + regexString));
+    catch (const Regex::Error&) {
+      BOOST_THROW_EXCEPTION(Error("Invalid <checker.key-locator.regex>: " + regexString));
     }
   }
   else if (boost::iequals(propertyIt->first, "hyper-relation")) {
     const ConfigSection& hSection = propertyIt->second;
-
     ConfigSection::const_iterator hPropertyIt = hSection.begin();
 
     // Get k-regex
     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-regex")) {
-      BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-regex>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator.hyper-relation.k-regex>"));
     }
 
     std::string kRegex = hPropertyIt->second.data();
@@ -279,7 +273,7 @@
 
     // Get k-expand
     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "k-expand")) {
-      BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.k-expand>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator.hyper-relation.k-expand>"));
     }
 
     std::string kExpand = hPropertyIt->second.data();
@@ -287,7 +281,7 @@
 
     // Get h-relation
     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "h-relation")) {
-      BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.h-relation>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator.hyper-relation.h-relation>"));
     }
 
     std::string hRelation = hPropertyIt->second.data();
@@ -295,7 +289,7 @@
 
     // Get p-regex
     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-regex")) {
-      BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.p-regex>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator.hyper-relation.p-regex>"));
     }
 
     std::string pRegex = hPropertyIt->second.data();
@@ -303,26 +297,26 @@
 
     // Get p-expand
     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, "p-expand")) {
-      BOOST_THROW_EXCEPTION(Error("Expect <checker.key-locator.hyper-relation.p-expand>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <checker.key-locator.hyper-relation.p-expand>"));
     }
 
     std::string pExpand = hPropertyIt->second.data();
     hPropertyIt++;
 
     if (hPropertyIt != hSection.end()) {
-      BOOST_THROW_EXCEPTION(Error("Expect the end of checker.key-locator.hyper-relation"));
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <checker.key-locator.hyper-relation>"));
     }
 
     NameRelation relation = getNameRelationFromString(hRelation);
     try {
       return make_unique<HyperRelationChecker>(pRegex, pExpand, kRegex, kExpand, relation);
     }
-    catch (const Regex::Error& e) {
-      BOOST_THROW_EXCEPTION(Error("Invalid regex for key-locator.hyper-relation"));
+    catch (const Regex::Error&) {
+      BOOST_THROW_EXCEPTION(Error("Invalid regex for <key-locator.hyper-relation>"));
     }
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("Unsupported checker.key-locator"));
+    BOOST_THROW_EXCEPTION(Error("Unrecognized <checker.key-locator>: " + propertyIt->first));
   }
 }
 
diff --git a/src/security/v2/validator-config/filter.cpp b/src/security/v2/validator-config/filter.cpp
index 1379c98..d9032c8 100644
--- a/src/security/v2/validator-config/filter.cpp
+++ b/src/security/v2/validator-config/filter.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -23,10 +23,10 @@
 
 #include "data.hpp"
 #include "interest.hpp"
-#include "util/regex.hpp"
 #include "security/security-common.hpp"
+#include "util/regex.hpp"
 
-#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
 
 namespace ndn {
 namespace security {
@@ -78,15 +78,14 @@
   auto propertyIt = configSection.begin();
 
   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "type")) {
-    BOOST_THROW_EXCEPTION(Error("Expect <filter.type>"));
+    BOOST_THROW_EXCEPTION(Error("Expecting <filter.type>"));
   }
 
   std::string type = propertyIt->second.data();
-
   if (boost::iequals(type, "name"))
     return createNameFilter(configSection, configFilename);
   else
-    BOOST_THROW_EXCEPTION(Error("Unsupported filter.type: " + type));
+    BOOST_THROW_EXCEPTION(Error("Unrecognized <filter.type>: " + type));
 }
 
 unique_ptr<Filter>
@@ -95,9 +94,8 @@
   auto propertyIt = configSection.begin();
   propertyIt++;
 
-  if (propertyIt == configSection.end()) {
-    BOOST_THROW_EXCEPTION(Error("Expect more properties for filter(name)"));
-  }
+  if (propertyIt == configSection.end())
+    BOOST_THROW_EXCEPTION(Error("Unexpected end of <filter>"));
 
   if (boost::iequals(propertyIt->first, "name")) {
     // Get filter.name
@@ -105,22 +103,22 @@
     try {
       name = Name(propertyIt->second.data());
     }
-    catch (const Name::Error& e) {
-      BOOST_THROW_EXCEPTION(Error("Wrong filter.name: " + propertyIt->second.data()));
+    catch (const Name::Error&) {
+      BOOST_THROW_EXCEPTION(Error("Invalid <filter.name>: " + propertyIt->second.data()));
     }
 
     propertyIt++;
 
     // Get filter.relation
     if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, "relation")) {
-      BOOST_THROW_EXCEPTION(Error("Expect <filter.relation>"));
+      BOOST_THROW_EXCEPTION(Error("Expecting <filter.relation>"));
     }
 
     NameRelation relation = getNameRelationFromString(propertyIt->second.data());
     propertyIt++;
 
     if (propertyIt != configSection.end())
-      BOOST_THROW_EXCEPTION(Error("Expect the end of filter"));
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <filter>"));
 
     return make_unique<RelationNameFilter>(name, relation);
   }
@@ -129,17 +127,17 @@
     propertyIt++;
 
     if (propertyIt != configSection.end())
-      BOOST_THROW_EXCEPTION(Error("Expect the end of filter"));
+      BOOST_THROW_EXCEPTION(Error("Expecting end of <filter>"));
 
     try {
       return make_unique<RegexNameFilter>(Regex(regexString));
     }
-    catch (const Regex::Error& e) {
-      BOOST_THROW_EXCEPTION(Error("Wrong filter.regex: " + regexString));
+    catch (const Regex::Error&) {
+      BOOST_THROW_EXCEPTION(Error("Invalid <filter.regex>: " + regexString));
     }
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("Wrong filter(name) properties"));
+    BOOST_THROW_EXCEPTION(Error("Unrecognized <filter> property: " + propertyIt->first));
   }
 }
 
diff --git a/src/security/v2/validator-config/rule.cpp b/src/security/v2/validator-config/rule.cpp
index 93b8df4..2cc3124 100644
--- a/src/security/v2/validator-config/rule.cpp
+++ b/src/security/v2/validator-config/rule.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -73,7 +73,8 @@
 }
 
 bool
-Rule::check(uint32_t pktType, const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) const
+Rule::check(uint32_t pktType, const Name& pktName, const Name& klName,
+            const shared_ptr<ValidationState>& state) const
 {
   NDN_LOG_TRACE("Trying to check " << pktName << " with keyLocator " << klName);
 
@@ -151,9 +152,8 @@
     hasCheckers = true;
   }
 
-  // Check other stuff
   if (propertyIt != configSection.end()) {
-    BOOST_THROW_EXCEPTION(Error("Expecting the end of rule: " + ruleId));
+    BOOST_THROW_EXCEPTION(Error("Expecting end of <rule>: " + ruleId));
   }
 
   if (!hasCheckers) {