mgmt: Switch nfd::Controller to use v2::Validator interface

The conversion also includes relevant changes in SegmentFetcher and
tests.

Change-Id: Ie2f55bac650e3689f4971ab814a8bd51068a2a40
Refs: #3920
diff --git a/src/mgmt/nfd/controller.cpp b/src/mgmt/nfd/controller.cpp
index bfb0843..945c16d 100644
--- a/src/mgmt/nfd/controller.cpp
+++ b/src/mgmt/nfd/controller.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -20,9 +20,12 @@
  */
 
 #include "controller.hpp"
-#include "../../face.hpp"
-#include "../../security/key-chain.hpp"
-#include "../../util/segment-fetcher.hpp"
+#include "face.hpp"
+#include "security/v2/key-chain.hpp"
+#include "security/validator-null.hpp"
+#include "util/segment-fetcher.hpp"
+
+#include <boost/lexical_cast.hpp>
 
 namespace ndn {
 namespace nfd {
@@ -34,13 +37,12 @@
 const uint32_t Controller::ERROR_VALIDATION = 10021; // 10000 + TLS1_ALERT_DECRYPTION_FAILED
 const uint32_t Controller::ERROR_SERVER = 500;
 const uint32_t Controller::ERROR_LBOUND = 400;
-ValidatorNull Controller::s_validatorNull;
 
-Controller::Controller(Face& face, KeyChain& keyChain, Validator& validator)
+Controller::Controller(Face& face, KeyChain& keyChain, security::v2::Validator& validator)
   : m_face(face)
   , m_keyChain(keyChain)
-  , m_signer(keyChain)
   , m_validator(validator)
+  , m_signer(keyChain)
 {
 }
 
@@ -79,11 +81,11 @@
                                    const CommandFailCallback& onFailure)
 {
   m_validator.validate(data,
-    [=] (const shared_ptr<const Data>& data) {
-      this->processValidatedCommandResponse(*data, command, onSuccess, onFailure);
+    [=] (const Data& data) {
+      this->processValidatedCommandResponse(data, command, onSuccess, onFailure);
     },
-    [=] (const shared_ptr<const Data>&, const std::string& msg) {
-      onFailure(ControlResponse(ERROR_VALIDATION, msg));
+    [=] (const Data& data, const security::v2::ValidationError& error) {
+      onFailure(ControlResponse(ERROR_VALIDATION, boost::lexical_cast<std::string>(error)));
     }
   );
 }
diff --git a/src/mgmt/nfd/controller.hpp b/src/mgmt/nfd/controller.hpp
index d9bfa1f..6582a66 100644
--- a/src/mgmt/nfd/controller.hpp
+++ b/src/mgmt/nfd/controller.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -26,15 +26,13 @@
 #include "control-response.hpp"
 #include "status-dataset.hpp"
 #include "command-options.hpp"
-#include "../../security/validator-null.hpp"
-#include "../../security/key-chain.hpp"
 #include "../../security/command-interest-signer.hpp"
+#include "../../security/validator-null.hpp"
+#include "../../security/v2/key-chain.hpp"
+#include "../../security/v2/validator.hpp"
 
 namespace ndn {
 
-namespace security {
-class Validator;
-} // namespace security
 class Face;
 
 namespace nfd {
@@ -67,7 +65,7 @@
   /** \brief construct a Controller that uses face for transport,
    *         and uses the passed KeyChain to sign commands
    */
-  Controller(Face& face, KeyChain& keyChain, security::Validator& validator = s_validatorNull);
+  Controller(Face& face, KeyChain& keyChain, security::v2::Validator& validator = security::getAcceptAllValidator());
 
   /** \brief start command execution
    */
@@ -172,11 +170,8 @@
 protected:
   Face& m_face;
   KeyChain& m_keyChain;
+  security::v2::Validator& m_validator;
   security::CommandInterestSigner m_signer;
-  security::Validator& m_validator;
-
-private:
-  static ValidatorNull s_validatorNull;
 };
 
 template<typename Dataset>