Finalize switch to v2 security

Change-Id: I1da06c817a7b3455fda1033ee530cde3221f02b7
Refs: #4091
diff --git a/src/common.hpp b/src/common.hpp
index efeabe6..ecd0719 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -26,8 +26,9 @@
 #include <ndn-cxx/data.hpp>
 #include <ndn-cxx/selectors.hpp>
 #include <ndn-cxx/key-locator.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
-#include <ndn-cxx/security/validator.hpp>
+#include <ndn-cxx/security/v2/key-chain.hpp>
+#include <ndn-cxx/security/v2/validator.hpp>
+#include <ndn-cxx/security/validator-config.hpp>
 #include <ndn-cxx/util/time.hpp>
 #include <ndn-cxx/util/scheduler.hpp>
 
@@ -57,9 +58,11 @@
 using ndn::Exclude;
 using ndn::Data;
 using ndn::KeyLocator;
-using ndn::KeyChain;
 using ndn::Scheduler;
-using ndn::Validator;
+using ndn::security::v2::KeyChain;
+using ndn::security::v2::Validator;
+using ndn::security::v2::ValidationError;
+using ndn::security::ValidatorConfig;
 
 using std::shared_ptr;
 using std::make_shared;
diff --git a/src/handles/delete-handle.cpp b/src/handles/delete-handle.cpp
index d062399..5c06015 100644
--- a/src/handles/delete-handle.cpp
+++ b/src/handles/delete-handle.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -33,48 +33,47 @@
 DeleteHandle::onInterest(const Name& prefix, const Interest& interest)
 {
   m_validator.validate(interest, bind(&DeleteHandle::onValidated, this, _1, prefix),
-                       bind(&DeleteHandle::onValidationFailed, this, _1, _2));
+                                 bind(&DeleteHandle::onValidationFailed, this, _1, _2));
 }
 
 void
-DeleteHandle::onValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+DeleteHandle::onValidated(const Interest& interest, const Name& prefix)
 {
   RepoCommandParameter parameter;
 
   try {
-    extractParameter(*interest, prefix, parameter);
+    extractParameter(interest, prefix, parameter);
   }
   catch (RepoCommandParameter::Error) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
 
   if (parameter.hasSelectors()) {
 
     if (parameter.hasStartBlockId() || parameter.hasEndBlockId()) {
-      negativeReply(*interest, 402);
+      negativeReply(interest, 402);
       return;
     }
 
     //choose data with selector and delete it
-    processSelectorDeleteCommand(*interest, parameter);
+    processSelectorDeleteCommand(interest, parameter);
     return;
   }
 
   if (!parameter.hasStartBlockId() && !parameter.hasEndBlockId()) {
-    processSingleDeleteCommand(*interest, parameter);
+    processSingleDeleteCommand(interest, parameter);
     return;
   }
 
-  processSegmentDeleteCommand(*interest, parameter);
+  processSegmentDeleteCommand(interest, parameter);
 }
 
 void
-DeleteHandle::onValidationFailed(const shared_ptr<const Interest>& interest,
-                                 const std::string& reason)
+DeleteHandle::onValidationFailed(const Interest& interest, const ValidationError& error)
 {
-  std::cerr << reason << std::endl;
-  negativeReply(*interest, 401);
+  std::cerr << error << std::endl;
+  negativeReply(interest, 401);
 }
 //listen change the setinterestfilter
 void
diff --git a/src/handles/delete-handle.hpp b/src/handles/delete-handle.hpp
index 265d5ef..17cb48a 100644
--- a/src/handles/delete-handle.hpp
+++ b/src/handles/delete-handle.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -50,10 +50,10 @@
   onInterest(const Name& prefix, const Interest& interest);
 
   void
-  onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+  onValidated(const Interest& interest, const Name& prefix);
 
   void
-  onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
+  onValidationFailed(const Interest& interest, const ValidationError& error);
 
   /**
    * @todo delete check has not been realized due to the while loop of segmented data deletion.
diff --git a/src/handles/watch-handle.cpp b/src/handles/watch-handle.cpp
index 91eaac4..bee036f 100644
--- a/src/handles/watch-handle.cpp
+++ b/src/handles/watch-handle.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -53,18 +53,18 @@
 }
 
 void
-WatchHandle::onValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WatchHandle::onValidated(const Interest& interest, const Name& prefix)
 {
   RepoCommandParameter parameter;
   try {
-    extractParameter(*interest, prefix, parameter);
+    extractParameter(interest, prefix, parameter);
   }
   catch (RepoCommandParameter::Error) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
 
-  processWatchCommand(*interest, parameter);
+  processWatchCommand(interest, parameter);
 }
 
 void WatchHandle::watchStop(const Name& name)
@@ -79,11 +79,10 @@
 }
 
 void
-WatchHandle::onValidationFailed(const shared_ptr<const Interest>& interest,
-                                const std::string& reason)
+WatchHandle::onValidationFailed(const Interest& interest, const ValidationError& error)
 {
-  std::cerr << reason << std::endl;
-  negativeReply(*interest, 401);
+  std::cerr << error << std::endl;
+  negativeReply(interest, 401);
 }
 
 void
@@ -95,13 +94,12 @@
 }
 
 void
-WatchHandle::onDataValidated(const Interest& interest, const shared_ptr<const Data>& data,
-                             const Name& name)
+WatchHandle::onDataValidated(const Interest& interest, const Data& data, const Name& name)
 {
   if (!m_processes[name].second) {
     return;
   }
-  if (getStorageHandle().insertData(*data)) {
+  if (getStorageHandle().insertData(data)) {
     m_size++;
     if (!onRunning(name))
       return;
@@ -113,7 +111,7 @@
 
     // update selectors
     // if data name is equal to interest name, use MinSuffixComponents selecor to exclude this data
-    if (data->getName().size() == interest.getName().size()) {
+    if (data.getName().size() == interest.getName().size()) {
       fetchInterest.setMinSuffixComponents(2);
     }
     else {
@@ -122,7 +120,7 @@
         exclude = interest.getExclude();
       }
 
-      exclude.excludeBefore(data->getName()[interest.getName().size()]);
+      exclude.excludeBefore(data.getName()[interest.getName().size()]);
       fetchInterest.setExclude(exclude);
     }
 
@@ -139,10 +137,10 @@
 }
 
 void
-WatchHandle::onDataValidationFailed(const Interest& interest, const shared_ptr<const Data>& data,
-                                    const std::string& reason, const Name& name)
+WatchHandle::onDataValidationFailed(const Interest& interest, const Data& data,
+                                    const ValidationError& error, const Name& name)
 {
-  std::cerr << reason << std::endl;
+  std::cerr << error << std::endl;
   if (!m_processes[name].second) {
     return;
   }
@@ -156,7 +154,7 @@
 
   // update selectors
   // if data name is equal to interest name, use MinSuffixComponents selecor to exclude this data
-  if (data->getName().size() == interest.getName().size()) {
+  if (data.getName().size() == interest.getName().size()) {
     fetchInterest.setMinSuffixComponents(2);
   }
   else {
@@ -165,7 +163,7 @@
       exclude = interest.getExclude();
     }
     // Only exclude this data since other data whose names are smaller may be validated and satisfied
-    exclude.excludeBefore(data->getName()[interest.getName().size()]);
+    exclude.excludeBefore(data.getName()[interest.getName().size()]);
     fetchInterest.setExclude(exclude);
   }
 
@@ -219,27 +217,26 @@
 }
 
 void
-WatchHandle::onStopValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WatchHandle::onStopValidated(const Interest& interest, const Name& prefix)
 {
   RepoCommandParameter parameter;
   try {
-    extractParameter(*interest, prefix, parameter);
+    extractParameter(interest, prefix, parameter);
   }
   catch (RepoCommandParameter::Error) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
 
   watchStop(parameter.getName());
-  negativeReply(*interest, 101);
+  negativeReply(interest, 101);
 }
 
 void
-WatchHandle::onStopValidationFailed(const shared_ptr<const Interest>& interest,
-                                    const std::string& reason)
+WatchHandle::onStopValidationFailed(const Interest& interest, const ValidationError& error)
 {
-  std::cerr << reason << std::endl;
-  negativeReply(*interest, 401);
+  std::cerr << error << std::endl;
+  negativeReply(interest, 401);
 }
 
 void
@@ -251,26 +248,26 @@
 }
 
 void
-WatchHandle::onCheckValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WatchHandle::onCheckValidated(const Interest& interest, const Name& prefix)
 {
   RepoCommandParameter parameter;
   try {
-    extractParameter(*interest, prefix, parameter);
+    extractParameter(interest, prefix, parameter);
   }
   catch (RepoCommandParameter::Error) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
 
   if (!parameter.hasName()) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
   //check whether this process exists
   Name name = parameter.getName();
   if (m_processes.count(name) == 0) {
     std::cerr << "no such process name: " << name << std::endl;
-    negativeReply(*interest, 404);
+    negativeReply(interest, 404);
     return;
   }
 
@@ -279,16 +276,15 @@
     response.setStatusCode(101);
   }
 
-  reply(*interest, response);
+  reply(interest, response);
 
 }
 
 void
-WatchHandle::onCheckValidationFailed(const shared_ptr<const Interest>& interest,
-                                     const std::string& reason)
+WatchHandle::onCheckValidationFailed(const Interest& interest, const ValidationError& error)
 {
-  std::cerr << reason << std::endl;
-  negativeReply(*interest, 401);
+  std::cerr << error << std::endl;
+  negativeReply(interest, 401);
 }
 
 void
diff --git a/src/handles/watch-handle.hpp b/src/handles/watch-handle.hpp
index 5768e06..c7071df 100644
--- a/src/handles/watch-handle.hpp
+++ b/src/handles/watch-handle.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -68,10 +68,10 @@
   onInterest(const Name& prefix, const Interest& interest);
 
   void
-  onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+  onValidated(const Interest& interest, const Name& prefix);
 
   void
-  onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
+  onValidationFailed(const Interest& interest, const ValidationError& error);
 
 private: // data fetching
   /**
@@ -87,15 +87,14 @@
   onTimeout(const Interest& interest, const Name& name);
 
   void
-  onDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
-                  const Name& name);
+  onDataValidated(const Interest& interest, const Data& data, const Name& name);
 
   /**
    * @brief failure of validation
    */
   void
-  onDataValidationFailed(const Interest& interest, const std::shared_ptr<const Data>& data,
-                         const std::string& reason, const Name& name);
+  onDataValidationFailed(const Interest& interest, const Data& data,
+                         const ValidationError& error, const Name& name);
 
 
   void
@@ -112,11 +111,10 @@
   onCheckInterest(const Name& prefix, const Interest& interest);
 
   void
-  onCheckValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+  onCheckValidated(const Interest& interest, const Name& prefix);
 
   void
-  onCheckValidationFailed(const std::shared_ptr<const Interest>& interest,
-                          const std::string& reason);
+  onCheckValidationFailed(const Interest& interest, const ValidationError& error);
 
 private: // watch stop command
   /**
@@ -126,11 +124,10 @@
   onStopInterest(const Name& prefix, const Interest& interest);
 
   void
-  onStopValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+  onStopValidated(const Interest& interest, const Name& prefix);
 
   void
-  onStopValidationFailed(const std::shared_ptr<const Interest>& interest,
-                         const std::string& reason);
+  onStopValidationFailed(const Interest& interest, const ValidationError& error);
 
 private:
   void
diff --git a/src/handles/write-handle.cpp b/src/handles/write-handle.cpp
index a398f0b..4586bad 100644
--- a/src/handles/write-handle.cpp
+++ b/src/handles/write-handle.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -55,38 +55,37 @@
 }
 
 void
-WriteHandle::onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix)
+WriteHandle::onValidated(const Interest& interest, const Name& prefix)
 {
   //m_validResult = 1;
   RepoCommandParameter parameter;
   try {
-    extractParameter(*interest, prefix, parameter);
+    extractParameter(interest, prefix, parameter);
   }
   catch (RepoCommandParameter::Error) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
 
   if (parameter.hasStartBlockId() || parameter.hasEndBlockId()) {
     if (parameter.hasSelectors()) {
-      negativeReply(*interest, 402);
+      negativeReply(interest, 402);
       return;
     }
-    processSegmentedInsertCommand(*interest, parameter);
+    processSegmentedInsertCommand(interest, parameter);
   }
   else {
-    processSingleInsertCommand(*interest, parameter);
+    processSingleInsertCommand(interest, parameter);
   }
   if (parameter.hasInterestLifetime())
     m_interestLifetime = parameter.getInterestLifetime();
 }
 
 void
-WriteHandle::onValidationFailed(const std::shared_ptr<const Interest>& interest,
-                                const std::string& reason)
+WriteHandle::onValidationFailed(const Interest& interest, const ValidationError& error)
 {
-  std::cerr << reason << std::endl;
-  negativeReply(*interest, 401);
+  std::cerr << error << std::endl;
+  negativeReply(interest, 401);
 }
 
 void
@@ -98,9 +97,7 @@
 }
 
 void
-WriteHandle::onDataValidated(const Interest& interest,
-                             const std::shared_ptr<const Data>& data,
-                             ProcessId processId)
+WriteHandle::onDataValidated(const Interest& interest, const Data& data, ProcessId processId)
 {
   if (m_processes.count(processId) == 0) {
     return;
@@ -110,9 +107,9 @@
   RepoCommandResponse& response = process.response;
 
   if (response.getInsertNum() == 0) {
-    getStorageHandle().insertData(*data);
-   // getStorageHandle().insertEntry(*data);
-   // getStoreIndex().insert(*data);
+    getStorageHandle().insertData(data);
+   // getStorageHandle().insertEntry(data);
+   // getStoreIndex().insert(data);
     response.setInsertNum(1);
   }
 
@@ -120,10 +117,9 @@
 }
 
 void
-WriteHandle::onDataValidationFailed(const std::shared_ptr<const Data>& data,
-                                    const std::string& reason)
+WriteHandle::onDataValidationFailed(const Data& data, const ValidationError& error)
 {
-  std::cerr << reason << std::endl;
+  std::cerr << error << std::endl;
 }
 
 void
@@ -135,9 +131,7 @@
 }
 
 void
-WriteHandle::onSegmentDataValidated(const Interest& interest,
-                                    const std::shared_ptr<const Data>& data,
-                                    ProcessId processId)
+WriteHandle::onSegmentDataValidated(const Interest& interest, const Data& data, ProcessId processId)
 {
   if (m_processes.count(processId) == 0) {
     return;
@@ -145,7 +139,7 @@
   RepoCommandResponse& response = m_processes[processId].response;
 
   //refresh endBlockId
-  Name::Component finalBlockId = data->getFinalBlockId();
+  Name::Component finalBlockId = data.getFinalBlockId();
 
   if (!finalBlockId.empty()) {
     SegmentNo final = finalBlockId.toSegment();
@@ -160,7 +154,7 @@
   }
 
   //insert data
-  if (getStorageHandle().insertData(*data)) {
+  if (getStorageHandle().insertData(data)) {
     response.setInsertNum(response.getInsertNum() + 1);
   }
 
@@ -386,26 +380,26 @@
 }
 
 void
-WriteHandle::onCheckValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WriteHandle::onCheckValidated(const Interest& interest, const Name& prefix)
 {
   RepoCommandParameter parameter;
   try {
-    extractParameter(*interest, prefix, parameter);
+    extractParameter(interest, prefix, parameter);
   }
   catch (RepoCommandParameter::Error) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
 
   if (!parameter.hasProcessId()) {
-    negativeReply(*interest, 403);
+    negativeReply(interest, 403);
     return;
   }
   //check whether this process exists
   ProcessId processId = parameter.getProcessId();
   if (m_processes.count(processId) == 0) {
     std::cerr << "no such processId: " << processId << std::endl;
-    negativeReply(*interest, 404);
+    negativeReply(interest, 404);
     return;
   }
 
@@ -416,27 +410,26 @@
   //Check whether it is single data fetching
   if (!response.hasStartBlockId() &&
       !response.hasEndBlockId()) {
-    reply(*interest, response);
+    reply(interest, response);
     return;
   }
 
   //read if noEndtimeout
   if (!response.hasEndBlockId()) {
     extendNoEndTime(process);
-    reply(*interest, response);
+    reply(interest, response);
     return;
   }
   else {
-    reply(*interest, response);
+    reply(interest, response);
   }
 }
 
 void
-WriteHandle::onCheckValidationFailed(const shared_ptr<const Interest>& interest,
-                                     const std::string& reason)
+WriteHandle::onCheckValidationFailed(const Interest& interest, const ValidationError& error)
 {
-  std::cerr << reason << std::endl;
-  negativeReply(*interest, 401);
+  std::cerr << error << std::endl;
+  negativeReply(interest, 401);
 }
 
 void
diff --git a/src/handles/write-handle.hpp b/src/handles/write-handle.hpp
index 1e7a007..c6622d9 100644
--- a/src/handles/write-handle.hpp
+++ b/src/handles/write-handle.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -107,10 +107,10 @@
   onInterest(const Name& prefix, const Interest& interest);
 
   void
-  onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+  onValidated(const Interest& interest, const Name& prefix);
 
   void
-  onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
+  onValidationFailed(const Interest& interest, const ValidationError& error);
 
 private: // single data fetching
   /**
@@ -120,8 +120,7 @@
   onData(const Interest& interest, const Data& data, ProcessId processId);
 
   void
-  onDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
-                  ProcessId processId);
+  onDataValidated(const Interest& interest, const Data& data, ProcessId processId);
 
   /**
    * @brief handle when fetching one data timeout
@@ -140,8 +139,7 @@
   onSegmentData(const Interest& interest, const Data& data, ProcessId processId);
 
   void
-  onSegmentDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
-                         ProcessId processId);
+  onSegmentDataValidated(const Interest& interest, const Data& data, ProcessId processId);
 
   /**
    * @brief Timeout when fetching segmented data. Data can be fetched RETRY_TIMEOUT times.
@@ -175,7 +173,7 @@
    * @brief failure of validation for both one or segmented data
    */
   void
-  onDataValidationFailed(const std::shared_ptr<const Data>& data, const std::string& reason);
+  onDataValidationFailed(const Data& data, const ValidationError& error);
 
   /**
    * @brief extends noEndTime of process if not noEndTimeout, set StatusCode 405
@@ -194,11 +192,10 @@
   onCheckInterest(const Name& prefix, const Interest& interest);
 
   void
-  onCheckValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+  onCheckValidated(const Interest& interest, const Name& prefix);
 
   void
-  onCheckValidationFailed(const std::shared_ptr<const Interest>& interest,
-                          const std::string& reason);
+  onCheckValidationFailed(const Interest& interest, const ValidationError& error);
 
 private:
   void
diff --git a/src/repo-command-parameter.hpp b/src/repo-command-parameter.hpp
index 3648679..97208b6 100644
--- a/src/repo-command-parameter.hpp
+++ b/src/repo-command-parameter.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -20,11 +20,12 @@
 #ifndef REPO_REPO_COMMAND_PARAMETER_HPP
 #define REPO_REPO_COMMAND_PARAMETER_HPP
 
+#include "repo-tlv.hpp"
+
 #include <ndn-cxx/encoding/encoding-buffer.hpp>
 #include <ndn-cxx/encoding/block-helpers.hpp>
 #include <ndn-cxx/name.hpp>
 #include <ndn-cxx/selectors.hpp>
-#include "repo-tlv.hpp"
 
 namespace repo {
 
@@ -244,7 +245,7 @@
     return m_hasInterestLifetime;
   }
 
-  template<bool T>
+  template<ndn::encoding::Tag T>
   size_t
   wireEncode(EncodingImpl<T>& block) const;
 
@@ -276,7 +277,7 @@
   mutable Block m_wire;
 };
 
-template<bool T>
+template<ndn::encoding::Tag T>
 inline size_t
 RepoCommandParameter::wireEncode(EncodingImpl<T>& encoder) const
 {
diff --git a/src/repo-command-response.hpp b/src/repo-command-response.hpp
index d8f1fe8..b07d894 100644
--- a/src/repo-command-response.hpp
+++ b/src/repo-command-response.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -20,11 +20,12 @@
 #ifndef REPO_REPO_COMMAND_RESPONSE_HPP
 #define REPO_REPO_COMMAND_RESPONSE_HPP
 
+#include "repo-tlv.hpp"
+
 #include <ndn-cxx/encoding/block.hpp>
 #include <ndn-cxx/encoding/block-helpers.hpp>
 #include <ndn-cxx/encoding/encoding-buffer.hpp>
 #include <ndn-cxx/encoding/tlv-nfd.hpp>
-#include "repo-tlv.hpp"
 
 namespace repo {
 
@@ -194,7 +195,7 @@
     return m_hasDeleteNum;
   }
 
-  template<bool T>
+  template<ndn::encoding::Tag T>
   size_t
   wireEncode(EncodingImpl<T>& block) const;
 
@@ -222,7 +223,7 @@
   mutable Block m_wire;
 };
 
-template<bool T>
+template<ndn::encoding::Tag T>
 inline size_t
 RepoCommandResponse::wireEncode(EncodingImpl<T>& encoder) const
 {
diff --git a/src/repo.cpp b/src/repo.cpp
index e12698f..28a43a0 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -118,6 +118,7 @@
   , m_face(ioService)
   , m_store(std::make_shared<SqliteStorage>(config.dbPath))
   , m_storageHandle(config.nMaxPackets, *m_store)
+  , m_validator(m_face)
   , m_readHandle(m_face, m_storageHandle, m_keyChain, m_scheduler)
   , m_writeHandle(m_face, m_storageHandle, m_keyChain, m_scheduler, m_validator)
   , m_watchHandle(m_face, m_storageHandle, m_keyChain, m_scheduler, m_validator)
@@ -167,9 +168,7 @@
 void
 Repo::enableValidation()
 {
-  std::cerr << "Validation is temporarily disabled. All commands will be authorized.\n";
-  /// \todo #4091 restore with ValidatorPolicyConf
-  // m_validator.load(m_config.validatorNode, m_config.repoConfigPath);
+  m_validator.load(m_config.validatorNode, m_config.repoConfigPath);
 }
 
 } // namespace repo
diff --git a/src/repo.hpp b/src/repo.hpp
index ef506a7..382a21e 100644
--- a/src/repo.hpp
+++ b/src/repo.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -32,7 +32,7 @@
 
 #include "common.hpp"
 
-#include <ndn-cxx/security/validator-null.hpp>
+#include <ndn-cxx/security/validator-config.hpp>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/info_parser.hpp>
 
@@ -86,7 +86,7 @@
   std::shared_ptr<Storage> m_store;
   RepoStorage m_storageHandle;
   KeyChain m_keyChain;
-  ndn::ValidatorNull m_validator;
+  ValidatorConfig m_validator;
   ReadHandle m_readHandle;
   WriteHandle m_writeHandle;
   WatchHandle m_watchHandle;
diff --git a/src/storage/index.cpp b/src/storage/index.cpp
index 3197a70..3eb2cce 100644
--- a/src/storage/index.cpp
+++ b/src/storage/index.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -19,8 +19,8 @@
 
 #include "index.hpp"
 
-#include <ndn-cxx/util/crypto.hpp>
-#include "ndn-cxx/security/signature-sha256-with-rsa.hpp"
+#include <ndn-cxx/util/sha256.hpp>
+#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
 
 namespace repo {
 
@@ -160,7 +160,7 @@
 Index::computeKeyLocatorHash(const KeyLocator& keyLocator)
 {
   const Block& block = keyLocator.wireEncode();
-  ndn::ConstBufferPtr keyLocatorHash = ndn::crypto::computeSha256Digest(block.wire(), block.size());
+  ndn::ConstBufferPtr keyLocatorHash = ndn::util::Sha256::computeDigest(block.wire(), block.size());
   return keyLocatorHash;
 }
 
@@ -175,7 +175,7 @@
     {
       KeyLocator keyLocator = interest.getPublisherPublicKeyLocator();
       const Block& block = keyLocator.wireEncode();
-      hash = ndn::crypto::computeSha256Digest(block.wire(), block.size());
+      hash = ndn::util::Sha256::computeDigest(block.wire(), block.size());
     }
 
   if (isLeftmost)
diff --git a/src/storage/sqlite-storage.cpp b/src/storage/sqlite-storage.cpp
index 034ae66..3411dfb 100644
--- a/src/storage/sqlite-storage.cpp
+++ b/src/storage/sqlite-storage.cpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2017, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -17,10 +17,11 @@
  * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "../../build/src/config.hpp"
 #include "sqlite-storage.hpp"
+#include "../../build/src/config.hpp"
 #include "index.hpp"
-#include <ndn-cxx/util/crypto.hpp>
+
+#include <ndn-cxx/util/sha256.hpp>
 #include <boost/filesystem.hpp>
 #include <istream>
 
@@ -163,7 +164,7 @@
                         data.wireEncode().size(),0 ) == SQLITE_OK &&
       sqlite3_bind_blob(insertStmt, 4,
                         (const void*)&(*entry.getKeyLocatorHash()),
-                        ndn::crypto::SHA256_DIGEST_SIZE,0) == SQLITE_OK) {
+                        ndn::util::Sha256::DIGEST_SIZE, 0) == SQLITE_OK) {
     rc = sqlite3_step(insertStmt);
     if (rc == SQLITE_CONSTRAINT) {
       std::cerr << "Insert  failed" << std::endl;