Fix build against current ndn-cxx

Change-Id: I9f2e06204ee190d507c76aac7ead09ad8e4d5009
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index e3f3daa..cd28b94 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -27,6 +27,7 @@
 #include "detail/info-encoder.hpp"
 #include "detail/request-encoder.hpp"
 #include "detail/probe-encoder.hpp"
+
 #include <ndn-cxx/metadata-object.hpp>
 #include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/security/verification-helpers.hpp>
@@ -77,36 +78,36 @@
 
   auto prefixId = m_face.registerPrefix(
     prefix,
-    [&](const Name& name)
-    {
+    [&] (const Name& name) {
       // register INFO RDR metadata prefix
       name::Component metaDataComp(32, reinterpret_cast<const uint8_t*>("metadata"), std::strlen("metadata"));
       auto filterId = m_face.setInterestFilter(Name(name).append("INFO").append(metaDataComp),
-                                               bind(&CaModule::onCaProfileDiscovery, this, _2));
+                                               [this] (auto&&, const auto& i) { onCaProfileDiscovery(i); });
       m_interestFilterHandles.push_back(filterId);
 
       // register PROBE prefix
       filterId = m_face.setInterestFilter(Name(name).append("PROBE"),
-                                          bind(&CaModule::onProbe, this, _2));
+                                          [this] (auto&&, const auto& i) { onProbe(i); });
       m_interestFilterHandles.push_back(filterId);
 
       // register NEW prefix
       filterId = m_face.setInterestFilter(Name(name).append("NEW"),
-                                          bind(&CaModule::onNewRenewRevoke, this, _2, RequestType::NEW));
+                                          [this] (auto&&, const auto& i) { onNewRenewRevoke(i, RequestType::NEW); });
       m_interestFilterHandles.push_back(filterId);
 
       // register SELECT prefix
       filterId = m_face.setInterestFilter(Name(name).append("CHALLENGE"),
-                                          bind(&CaModule::onChallenge, this, _2));
+                                          [this] (auto&&, const auto& i) { onChallenge(i); });
       m_interestFilterHandles.push_back(filterId);
 
       // register REVOKE prefix
       filterId = m_face.setInterestFilter(Name(name).append("REVOKE"),
-                                          bind(&CaModule::onNewRenewRevoke, this, _2, RequestType::REVOKE));
+                                          [this] (auto&&, const auto& i) { onNewRenewRevoke(i, RequestType::REVOKE); });
       m_interestFilterHandles.push_back(filterId);
+
       NDN_LOG_TRACE("Prefix " << name << " got registered");
     },
-    bind(&CaModule::onRegisterFailed, this, _2));
+    [this] (auto&&, const auto& reason) { onRegisterFailed(reason); });
   m_registeredPrefixHandles.push_back(prefixId);
 }
 
diff --git a/src/challenge/challenge-possession.cpp b/src/challenge/challenge-possession.cpp
index 73a0c29..ef93d25 100644
--- a/src/challenge/challenge-possession.cpp
+++ b/src/challenge/challenge-possession.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -18,12 +18,15 @@
  */
 
 #include "challenge-possession.hpp"
-#include <ndn-cxx/security/verification-helpers.hpp>
+
 #include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/security/transform/public-key.hpp>
+#include <ndn-cxx/security/verification-helpers.hpp>
 #include <ndn-cxx/util/io.hpp>
 #include <ndn-cxx/util/random.hpp>
 
+#include <boost/property_tree/json_parser.hpp>
+
 namespace ndn {
 namespace ndncert {
 
@@ -53,9 +56,9 @@
   try {
     boost::property_tree::read_json(m_configFile, config);
   }
-  catch (const boost::property_tree::info_parser_error& error) {
-    NDN_THROW(std::runtime_error("Failed to parse configuration file " + m_configFile +
-                                             " " + error.message() + " line " + std::to_string(error.line())));
+  catch (const boost::property_tree::file_parser_error& error) {
+    NDN_THROW(std::runtime_error("Failed to parse configuration file " + m_configFile + ": " +
+                                 error.message() + " on line " + std::to_string(error.line())));
   }
 
   if (config.begin() == config.end()) {
@@ -96,7 +99,8 @@
         }
         catch (const std::exception& e) {
           NDN_LOG_ERROR("Cannot load challenge parameter: credential " << e.what());
-          return returnWithError(request, ErrorCode::INVALID_PARAMETER, "Cannot challenge credential: credential." + std::string(e.what()));
+          return returnWithError(request, ErrorCode::INVALID_PARAMETER,
+                                 "Cannot challenge credential: credential."s + e.what());
         }
       }
       else if (readString(elements[i]) == PARAMETER_KEY_PROOF) {
@@ -114,7 +118,7 @@
     if (credential.hasContent() && signatureLen == 0) {
       Name signingKeyName = credential.getSignatureInfo().getKeyLocator().getName();
       security::transform::PublicKey key;
-      const auto &pubKeyBuffer = credential.getPublicKey();
+      const auto& pubKeyBuffer = credential.getPublicKey();
       key.loadPkcs8(pubKeyBuffer.data(), pubKeyBuffer.size());
       for (auto anchor : m_trustAnchors) {
         if (anchor.getKeyName() == signingKeyName) {
@@ -123,8 +127,9 @@
           }
         }
       }
-    } else {
-        return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
+    }
+    else {
+      return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
     }
     if (!checkOK) {
       return returnWithError(request, ErrorCode::INVALID_PARAMETER, "Certificate cannot be verified");
@@ -140,11 +145,12 @@
     NDN_LOG_TRACE("Secret for request " << toHex(request.requestId.data(), request.requestId.size())
                   << " : " << toHex(secretCode.data(), 16));
     return returnWithNewChallengeStatus(request, NEED_PROOF, std::move(secretJson), m_maxAttemptTimes, m_secretLifetime);
-  } else if (request.challengeState && request.challengeState->challengeStatus == NEED_PROOF) {
+  }
+  else if (request.challengeState && request.challengeState->challengeStatus == NEED_PROOF) {
     NDN_LOG_TRACE("Challenge Interest (proof) arrives. Check the proof");
     //check the format and load credential
     if (credential.hasContent() || signatureLen == 0) {
-        return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
+      return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
     }
     credential = security::Certificate(Block(fromHex(request.challengeState->secrets.get(PARAMETER_KEY_CREDENTIAL_CERT, ""))));
     auto secretCode = *fromHex(request.challengeState->secrets.get(PARAMETER_KEY_NONCE, ""));
@@ -153,11 +159,11 @@
     security::transform::PublicKey key;
     const auto& pubKeyBuffer = credential.getPublicKey();
     key.loadPkcs8(pubKeyBuffer.data(), pubKeyBuffer.size());
-    if (security::verifySignature(secretCode.data(), secretCode.size(), signature, signatureLen, key)) {
+    if (security::verifySignature({{secretCode.data(), secretCode.size()}}, signature, signatureLen, key)) {
       return returnWithSuccess(request);
     }
     return returnWithError(request, ErrorCode::INVALID_PARAMETER,
-            "Cannot verify the proof of private key against credential.");
+                           "Cannot verify the proof of private key against credential.");
   }
   NDN_LOG_TRACE("Proof of possession: bad state");
   return returnWithError(request, ErrorCode::INVALID_PARAMETER, "Fail to recognize the request.");
@@ -171,12 +177,13 @@
   if (status == Status::BEFORE_CHALLENGE) {
     result.emplace(PARAMETER_KEY_CREDENTIAL_CERT, "Please provide the certificate issued by a trusted CA.");
     return result;
-  } else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF) {
+  }
+  else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF) {
     result.emplace(PARAMETER_KEY_PROOF, "Please sign a Data packet with request ID as the content.");
-  } else {
+  }
+  else {
     NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
   }
-
   return result;
 }
 
@@ -195,29 +202,33 @@
         request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CREDENTIAL_CERT));
         Block valueBlock(tlv::ParameterValue);
         auto& certTlvStr = std::get<1>(item);
-        valueBlock.push_back(Block((uint8_t*)certTlvStr.c_str(), certTlvStr.size()));
+        valueBlock.push_back(Block(reinterpret_cast<const uint8_t*>(certTlvStr.data()), certTlvStr.size()));
         request.push_back(valueBlock);
       }
       else {
         NDN_THROW(std::runtime_error("Wrong parameter provided."));
       }
     }
-  } else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF){
+  }
+  else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF){
     if (params.size() != 1) {
       NDN_THROW(std::runtime_error("Wrong parameter provided."));
     }
-    for (const auto &item : params) {
+    for (const auto& item : params) {
       if (std::get<0>(item) == PARAMETER_KEY_PROOF) {
         request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_PROOF));
-        auto &sigTlvStr = std::get<1>(item);
-        Block valueBlock = makeBinaryBlock(tlv::ParameterValue, (uint8_t *) sigTlvStr.c_str(),
+        auto& sigTlvStr = std::get<1>(item);
+        Block valueBlock = makeBinaryBlock(tlv::ParameterValue,
+                                           reinterpret_cast<const uint8_t*>(sigTlvStr.data()),
                                            sigTlvStr.size());
         request.push_back(valueBlock);
-      } else {
+      }
+      else {
         NDN_THROW(std::runtime_error("Wrong parameter provided."));
       }
     }
-  } else {
+  }
+  else {
     NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
   }
   request.encode();
@@ -229,20 +240,20 @@
                                        KeyChain& keyChain, const Name& issuedCertName,
                                        const std::array<uint8_t, 16>& nonce)
 {
-  auto& pib = keyChain.getPib();
-  auto id = pib.getIdentity(security::extractIdentityFromCertName(issuedCertName));
-  auto issuedCert = id.getKey(security::extractKeyNameFromCertName(issuedCertName)).getCertificate(issuedCertName);
+  auto keyName = security::extractKeyNameFromCertName(issuedCertName);
+  auto id = keyChain.getPib().getIdentity(security::extractIdentityFromCertName(issuedCertName));
+  auto issuedCert = id.getKey(keyName).getCertificate(issuedCertName);
   auto issuedCertTlv = issuedCert.wireEncode();
-  auto signatureTlv = keyChain.sign(nonce.data(), nonce.size(), security::signingByCertificate(issuedCertName));
+  auto signature = keyChain.getTpm().sign({{nonce.data(), nonce.size()}}, keyName, DigestAlgorithm::SHA256);
+
   for (auto& item : params) {
-    if (std::get<0>(item) == PARAMETER_KEY_CREDENTIAL_CERT) {
-      std::get<1>(item) = std::string((char*)issuedCertTlv.wire(), issuedCertTlv.size());
+    if (item.first == PARAMETER_KEY_CREDENTIAL_CERT) {
+      item.second = std::string(reinterpret_cast<const char*>(issuedCertTlv.wire()), issuedCertTlv.size());
     }
-    else if (std::get<0>(item) == PARAMETER_KEY_PROOF) {
-      std::get<1>(item) = std::string((char*)signatureTlv.value(), signatureTlv.value_size());
+    else if (item.first == PARAMETER_KEY_PROOF) {
+      item.second = std::string(signature->get<char>(), signature->size());
     }
   }
-  return;
 }
 
 } // namespace ndncert
diff --git a/src/detail/ca-configuration.cpp b/src/detail/ca-configuration.cpp
index 7d27bfb..813c428 100644
--- a/src/detail/ca-configuration.cpp
+++ b/src/detail/ca-configuration.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -19,8 +19,11 @@
  */
 
 #include "detail/ca-configuration.hpp"
+
 #include <ndn-cxx/util/io.hpp>
+
 #include <boost/filesystem.hpp>
+#include <boost/property_tree/json_parser.hpp>
 
 namespace ndn {
 namespace ndncert {
@@ -39,7 +42,7 @@
   if (configJson.begin() == configJson.end()) {
     NDN_THROW(std::runtime_error("No JSON configuration found in file: " + fileName));
   }
-    caProfile = CaProfile::fromJson(configJson);
+  caProfile = CaProfile::fromJson(configJson);
   if (caProfile.supportedChallenges.size() == 0) {
     NDN_THROW(std::runtime_error("At least one challenge should be specified."));
   }
diff --git a/src/detail/ca-request-state.cpp b/src/detail/ca-request-state.cpp
index 53783d4..b8a6b27 100644
--- a/src/detail/ca-request-state.cpp
+++ b/src/detail/ca-request-state.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -19,15 +19,17 @@
  */
 
 #include "detail/ca-request-state.hpp"
+
 #include <ndn-cxx/util/indented-stream.hpp>
 
+#include <boost/property_tree/json_parser.hpp>
+
 namespace ndn {
 namespace ndncert {
 
 std::string statusToString(Status status)
 {
-  switch (status)
-  {
+  switch (status) {
   case Status::BEFORE_CHALLENGE:
     return "Before challenge";
   case Status::CHALLENGE:
@@ -58,11 +60,11 @@
                                const time::system_clock::TimePoint& challengeTp,
                                size_t remainingTries, time::seconds remainingTime,
                                JsonSection&& challengeSecrets)
-    : challengeStatus(challengeStatus)
-    , timestamp(challengeTp)
-    , remainingTries(remainingTries)
-    , remainingTime(remainingTime)
-    , secrets(std::move(challengeSecrets))
+  : challengeStatus(challengeStatus)
+  , timestamp(challengeTp)
+  , remainingTries(remainingTries)
+  , remainingTime(remainingTime)
+  , secrets(std::move(challengeSecrets))
 {
 }
 
diff --git a/src/detail/ca-sqlite.cpp b/src/detail/ca-sqlite.cpp
index 1cddfed..c247501 100644
--- a/src/detail/ca-sqlite.cpp
+++ b/src/detail/ca-sqlite.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -21,10 +21,13 @@
 #include "detail/ca-sqlite.hpp"
 
 #include <sqlite3.h>
-#include <boost/filesystem.hpp>
+
 #include <ndn-cxx/security/validation-policy.hpp>
 #include <ndn-cxx/util/sqlite3-statement.hpp>
 
+#include <boost/filesystem.hpp>
+#include <boost/property_tree/json_parser.hpp>
+
 namespace ndn {
 namespace ndncert {
 namespace ca {
@@ -186,7 +189,8 @@
     statement.bind(11, request.challengeState->remainingTime.count());
   }
   if (statement.step() != SQLITE_DONE) {
-    NDN_THROW(std::runtime_error("Request " + toHex(request.requestId.data(), request.requestId.size()) + " cannot be added to database"));
+    NDN_THROW(std::runtime_error("Request " + toHex(request.requestId.data(), request.requestId.size()) +
+                                 " cannot be added to database"));
   }
 }
 
diff --git a/src/detail/ndncert-common.hpp b/src/detail/ndncert-common.hpp
index 0e1b392..01fa883 100644
--- a/src/detail/ndncert-common.hpp
+++ b/src/detail/ndncert-common.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -37,6 +37,9 @@
 
 #include <cstddef>
 #include <cstdint>
+#include <string>
+#include <tuple>
+
 #include <ndn-cxx/data.hpp>
 #include <ndn-cxx/encoding/block-helpers.hpp>
 #include <ndn-cxx/encoding/block.hpp>
@@ -48,13 +51,11 @@
 #include <ndn-cxx/security/certificate.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 #include <ndn-cxx/util/logger.hpp>
-#include <ndn-cxx/util/nonstd/optional.hpp>
-#include <tuple>
+#include <ndn-cxx/util/optional.hpp>
+
 #include <boost/algorithm/string.hpp>
 #include <boost/assert.hpp>
 #include <boost/noncopyable.hpp>
-#include <boost/property_tree/info_parser.hpp>
-#include <boost/property_tree/json_parser.hpp>
 #include <boost/property_tree/ptree.hpp>
 
 namespace ndn {
@@ -93,8 +94,7 @@
 
 } // namespace tlv
 
-using boost::noncopyable;
-typedef boost::property_tree::ptree JsonSection;
+using JsonSection = boost::property_tree::ptree;
 
 // NDNCERT error code
 enum class ErrorCode : uint64_t {
diff --git a/src/detail/profile-storage.cpp b/src/detail/profile-storage.cpp
index 7ae3c08..949309a 100644
--- a/src/detail/profile-storage.cpp
+++ b/src/detail/profile-storage.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
  *
  * This file is part of ndncert, a certificate management system based on NDN.
  *
@@ -19,7 +19,9 @@
  */
 
 #include "detail/profile-storage.hpp"
+
 #include <boost/filesystem.hpp>
+#include <boost/property_tree/json_parser.hpp>
 
 namespace ndn {
 namespace ndncert {