build: switch to C++17

Change-Id: Ia147b22fbdee68d87f0289851683ffbbb4466caa
diff --git a/src/clients/response.cpp b/src/clients/response.cpp
index 48b8a7d..4aedf73 100644
--- a/src/clients/response.cpp
+++ b/src/clients/response.cpp
@@ -163,14 +163,14 @@
 Response&
 Response::addRr(const Block& rr)
 {
-  this->m_rrs.push_back(rr);
+  m_rrs.push_back(rr);
   return *this;
 }
 
 Response&
 Response::addRr(const std::string& rr)
 {
-  return this->addRr(makeBinaryBlock(ndns::tlv::RrData, rr.c_str(), rr.size()));
+  return addRr(makeStringBlock(ndns::tlv::RrData, rr));
 }
 
 bool
diff --git a/src/clients/response.hpp b/src/clients/response.hpp
index 4e8f335..5417c8c 100644
--- a/src/clients/response.hpp
+++ b/src/clients/response.hpp
@@ -33,8 +33,7 @@
 /**
  * @brief Default life time of resource record
  */
-const time::seconds DEFAULT_RR_FRESHNESS_PERIOD = 3600_s;
-
+inline constexpr time::seconds DEFAULT_RR_FRESHNESS_PERIOD = 3600_s;
 
 /**
  * @brief NDNS Response abstraction. Response is used on client side,
diff --git a/src/daemon/config-file.hpp b/src/daemon/config-file.hpp
index b17dfe6..29a0587 100644
--- a/src/daemon/config-file.hpp
+++ b/src/daemon/config-file.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  Regents of the University of California,
+ * Copyright (c) 2014-2022,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -107,7 +107,7 @@
   static T
   parseNumber(const ConfigSection& node, const std::string& key, const std::string& sectionName)
   {
-    static_assert(std::is_arithmetic<T>::value, "T must be an arithmetic type");
+    static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type");
 
     boost::optional<T> value = node.get_value_optional<T>();
     if (value) {
diff --git a/src/daemon/db-mgr.cpp b/src/daemon/db-mgr.cpp
index e1ab0fc..3c20f94 100644
--- a/src/daemon/db-mgr.cpp
+++ b/src/daemon/db-mgr.cpp
@@ -27,7 +27,7 @@
 
 NDNS_LOG_INIT(DbMgr);
 
-static const std::string NDNS_SCHEMA = R"SQL(
+const std::string NDNS_SCHEMA = R"SQL(
 CREATE TABLE IF NOT EXISTS zones (
   id    INTEGER NOT NULL PRIMARY KEY,
   name  BLOB NOT NULL UNIQUE,
@@ -143,20 +143,19 @@
 DbMgr::restoreName(sqlite3_stmt* stmt, int iCol)
 {
   Name name;
+  span buffer(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, iCol)),
+              sqlite3_column_bytes(stmt, iCol));
 
-  const uint8_t* buffer = static_cast<const uint8_t*>(sqlite3_column_blob(stmt, iCol));
-  size_t nBytesLeft = sqlite3_column_bytes(stmt, iCol);
-
-  while (nBytesLeft > 0) {
-    bool hasDecodingSucceeded;
+  while (!buffer.empty()) {
     name::Component component;
-    std::tie(hasDecodingSucceeded, component) = Block::fromBuffer({buffer, nBytesLeft});
-    if (!hasDecodingSucceeded) {
-      NDN_THROW(Error("Error while decoding name from the database"));
+    try {
+      component.wireDecode(Block(buffer));
+    }
+    catch (const ndn::tlv::Error&) {
+      NDN_THROW_NESTED(Error("Error while decoding name from the database"));
     }
     name.append(component);
-    buffer += component.size();
-    nBytesLeft -= component.size();
+    buffer = buffer.subspan(component.size());
   }
 
   return name;
@@ -250,8 +249,8 @@
 
   while (sqlite3_step(stmt) == SQLITE_ROW) {
     const char* key = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
-    rtn[string(key)] = Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 1)),
-                                       sqlite3_column_bytes(stmt, 1)));
+    rtn[string(key)] = Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 1)),
+                                  sqlite3_column_bytes(stmt, 1)));
   }
 
   sqlite3_finalize(stmt);
@@ -410,10 +409,10 @@
   if (sqlite3_step(stmt) == SQLITE_ROW) {
     rrset.setId(sqlite3_column_int64(stmt, 0));
     rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
-    rrset.setVersion(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
-                                     sqlite3_column_bytes(stmt, 2))));
-    rrset.setData(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
-                                  sqlite3_column_bytes(stmt, 3))));
+    rrset.setVersion(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
+                                                sqlite3_column_bytes(stmt, 2)))));
+    rrset.setData(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
+                             sqlite3_column_bytes(stmt, 3))));
   }
   else {
     rrset.setId(0);
@@ -454,10 +453,10 @@
   if (sqlite3_step(stmt) == SQLITE_ROW) {
     rrset.setId(sqlite3_column_int64(stmt, 0));
     rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
-    rrset.setVersion(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
-                                     sqlite3_column_bytes(stmt, 2))));
-    rrset.setData(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
-                                  sqlite3_column_bytes(stmt, 3))));
+    rrset.setVersion(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
+                                                sqlite3_column_bytes(stmt, 2)))));
+    rrset.setData(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
+                             sqlite3_column_bytes(stmt, 3))));
   }
   else {
     rrset.setId(0);
@@ -493,13 +492,13 @@
 
     rrset.setId(sqlite3_column_int64(stmt, 0));
     rrset.setTtl(time::seconds(sqlite3_column_int64(stmt, 1)));
-    rrset.setVersion(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
-                                     sqlite3_column_bytes(stmt, 2))));
-    rrset.setData(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
-                                  sqlite3_column_bytes(stmt, 3))));
+    rrset.setVersion(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 2)),
+                                                sqlite3_column_bytes(stmt, 2)))));
+    rrset.setData(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 3)),
+                             sqlite3_column_bytes(stmt, 3))));
     rrset.setLabel(restoreName(stmt, 4));
-    rrset.setType(Block(make_span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 5)),
-                                  sqlite3_column_bytes(stmt, 5))));
+    rrset.setType(name::Component(Block(span(static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 5)),
+                                             sqlite3_column_bytes(stmt, 5)))));
   }
   sqlite3_finalize(stmt);
 
diff --git a/src/daemon/db-mgr.hpp b/src/daemon/db-mgr.hpp
index 81ae5ad..747060f 100644
--- a/src/daemon/db-mgr.hpp
+++ b/src/daemon/db-mgr.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020, Regents of the University of California.
+ * Copyright (c) 2014-2022, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -196,8 +196,7 @@
    * @brief remove all records of a specific type in a zone
    */
   void
-  removeRrsetsOfZoneByType(Zone& zone,
-                           const name::Component& type);
+  removeRrsetsOfZoneByType(Zone& zone, const name::Component& type);
 
   /**
    * @brief replace ttl, version, and Data with new values
@@ -220,10 +219,10 @@
    * If @p name is not preserved until @p stmt is executed, @p isStatic must be
    * set to `false`.
    */
-  void
+  static void
   saveName(const Name& name, sqlite3_stmt* stmt, int iCol, bool isStatic = true);
 
-  Name
+  static Name
   restoreName(sqlite3_stmt* stmt, int iCol);
 
 private:
diff --git a/src/daemon/rrset-factory.cpp b/src/daemon/rrset-factory.cpp
index eed7ad0..41e93a1 100644
--- a/src/daemon/rrset-factory.cpp
+++ b/src/daemon/rrset-factory.cpp
@@ -98,7 +98,7 @@
 
   rrset.setVersion(name.get(-1));
 
-  return std::make_pair(rrset, name);
+  return {rrset, name};
 }
 
 bool
@@ -125,13 +125,10 @@
   if (ttl == DEFAULT_RR_TTL)
     ttl = m_zone.getTtl();
 
-  std::pair<Rrset, Name> rrsetAndName = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
-  const Name& name = rrsetAndName.second;
-  Rrset& rrset = rrsetAndName.first;
+  auto [rrset, name] = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
 
   Link link(name);
   link.setDelegationList(std::move(delegations));
-
   setContentType(link, NDNS_LINK, ttl);
   sign(link);
   rrset.setData(link.wireEncode());
@@ -152,19 +149,16 @@
   if (ttl == DEFAULT_RR_TTL)
     ttl = m_zone.getTtl();
 
-  Name name;
-  Rrset rrset;
-  std::tie(rrset, name) = generateBaseRrset(label, label::TXT_RR_TYPE, version, ttl);
+  auto [rrset, name] = generateBaseRrset(label, label::TXT_RR_TYPE, version, ttl);
 
   std::vector<Block> rrs;
   rrs.reserve(strings.size());
   for (const auto& item : strings) {
-    rrs.push_back(makeBinaryBlock(ndns::tlv::RrData, item.data(), item.size()));
+    rrs.push_back(makeStringBlock(ndns::tlv::RrData, item));
   }
 
   Data data(name);
   data.setContent(wireEncode(rrs));
-
   setContentType(data, NDNS_RESP, ttl);
   sign(data);
   rrset.setData(data.wireEncode());
@@ -185,13 +179,10 @@
   if (ttl == DEFAULT_RR_TTL)
     ttl = m_zone.getTtl();
 
-  Name name;
-  Rrset rrset;
-  std::tie(rrset, name) = generateBaseRrset(label, label::APPCERT_RR_TYPE, version, ttl);
+  auto [rrset, name] = generateBaseRrset(label, label::APPCERT_RR_TYPE, version, ttl);
 
   Data data(name);
   data.setContent(cert.wireEncode());
-
   setContentType(data, NDNS_KEY, ttl);
   sign(data);
   rrset.setData(data.wireEncode());
@@ -211,12 +202,9 @@
   if (ttl == DEFAULT_RR_TTL)
     ttl = m_zone.getTtl();
 
-  Name name;
-  Rrset rrset;
-  std::tie(rrset, name) = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
+  auto [rrset, name] = generateBaseRrset(label, label::NS_RR_TYPE, version, ttl);
 
   Data data(name);
-
   setContentType(data, NDNS_AUTH, ttl);
   sign(data);
   rrset.setData(data.wireEncode());
@@ -238,9 +226,7 @@
   if (ttl == DEFAULT_RR_TTL)
     ttl = m_zone.getTtl();
 
-  Name name;
-  Rrset rrset;
-  std::tie(rrset, name) = generateBaseRrset(label, label::DOE_RR_TYPE, version, ttl);
+  auto [rrset, name] = generateBaseRrset(label, label::DOE_RR_TYPE, version, ttl);
 
   std::vector<Block> range;
   range.push_back(lowerLabel.wireEncode());
@@ -303,12 +289,9 @@
 {
   std::vector<std::string> txts;
   wire.parse();
-
   for (const auto& e : wire.elements()) {
-    txts.push_back(std::string(reinterpret_cast<const char*>(e.value()),
-                               e.value_size()));
+    txts.emplace_back(reinterpret_cast<const char*>(e.value()), e.value_size());
   }
-
   return txts;
 }
 
diff --git a/src/mgmt/management-tool.cpp b/src/mgmt/management-tool.cpp
index 9ac88cf..33b704c 100644
--- a/src/mgmt/management-tool.cpp
+++ b/src/mgmt/management-tool.cpp
@@ -38,7 +38,6 @@
 #include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/security/transform.hpp>
 
-
 namespace ndn {
 namespace ndns {
 
@@ -48,8 +47,6 @@
 using security::transform::streamSink;
 using security::transform::bufferSource;
 using security::Certificate;
-using security::Identity;
-using security::Key;
 
 ManagementTool::ManagementTool(const std::string& dbFile, KeyChain& keyChain)
   : m_keyChain(keyChain)
@@ -112,14 +109,14 @@
   NDNS_LOG_INFO("Generated D-Key's identityName: " + dkeyIdentityName.toUri());
 
   Name dskName;
-  Key ksk;
-  Key dsk;
-  Key dkey;
+  security::Key ksk;
+  security::Key dsk;
+  security::Key dkey;
   Certificate dskCert;
   Certificate kskCert;
   Certificate dkeyCert;
-  Identity zoneIdentity = m_keyChain.createIdentity(zoneIdentityName);
-  Identity dkeyIdentity = m_keyChain.createIdentity(dkeyIdentityName);
+  auto zoneIdentity = m_keyChain.createIdentity(zoneIdentityName);
+  auto dkeyIdentity = m_keyChain.createIdentity(dkeyIdentityName);
 
   if (dkeyCertName == DEFAULT_CERT) {
     dkey = m_keyChain.createKey(dkeyIdentity);
@@ -319,7 +316,7 @@
                                  const std::string& inFile,
                                  const time::seconds& ttl,
                                  const Name& inputDskCertName,
-                                 const ndn::io::IoEncoding encoding,
+                                 ndn::io::IoEncoding encoding,
                                  bool needResign)
 {
   //check precondition
@@ -397,7 +394,7 @@
 }
 
 void
-ManagementTool::listZone(const Name& zoneName, std::ostream& os, const bool printRaw)
+ManagementTool::listZone(const Name& zoneName, std::ostream& os, bool printRaw)
 {
   Zone zone(zoneName);
   if (!m_dbMgr.find(zone)) {
@@ -440,7 +437,7 @@
                     || re.getContentType() == NDNS_KEY
                     || re.getContentType() == NDNS_AUTH ? 1 : re.getRrs().size();
 
-    const std::vector<Block>& rrs = re.getRrs();
+    const auto& rrs = re.getRrs();
 
     if (re.getContentType() != NDNS_BLOB && re.getContentType() != NDNS_KEY) {
       os << "; rrset=" << rrset.getLabel().toUri()
@@ -515,7 +512,8 @@
 }
 
 void
-ManagementTool::listAllZones(std::ostream& os) {
+ManagementTool::listAllZones(std::ostream& os)
+{
   std::vector<Zone> zones = m_dbMgr.listZones();
 
   size_t nameWidth = 0;
@@ -622,8 +620,8 @@
 bool
 ManagementTool::matchCertificate(const Name& certName, const Name& identity)
 {
-  security::Identity id = m_keyChain.getPib().getIdentity(identity);
-  for (const security::Key& key : id.getKeys()) {
+  auto id = m_keyChain.getPib().getIdentity(identity);
+  for (const auto& key : id.getKeys()) {
     try {
       key.getCertificate(certName);
       return true;
diff --git a/src/mgmt/management-tool.hpp b/src/mgmt/management-tool.hpp
index ba00458..592205c 100644
--- a/src/mgmt/management-tool.hpp
+++ b/src/mgmt/management-tool.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020, Regents of the University of California.
+ * Copyright (c) 2014-2022, Regents of the University of California.
  *
  * This file is part of NDNS (Named Data Networking Domain Name Service).
  * See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -35,14 +35,14 @@
 namespace ndn {
 namespace ndns {
 
-static const Name DEFAULT_CERT;
-static const Name ROOT_ZONE;
-static const time::seconds DEFAULT_CACHE_TTL = time::seconds(3600);
-static const time::seconds DEFAULT_CERT_TTL = time::days(365);
-static const std::vector<std::string> DEFAULT_CONTENTS;
-static const std::string DEFAULT_IO = "-";
-static const time::seconds DEFAULT_RR_TTL = time::seconds(0);
-static constexpr uint64_t VERSION_USE_UNIX_TIMESTAMP = std::numeric_limits<uint64_t>::max();
+inline const Name DEFAULT_CERT;
+inline const Name ROOT_ZONE;
+inline constexpr time::seconds DEFAULT_CACHE_TTL = time::seconds(3600);
+inline constexpr time::seconds DEFAULT_CERT_TTL = time::days(365);
+inline const std::vector<std::string> DEFAULT_CONTENTS;
+inline const std::string DEFAULT_IO = "-";
+inline constexpr time::seconds DEFAULT_RR_TTL = time::seconds(0);
+inline constexpr uint64_t VERSION_USE_UNIX_TIMESTAMP = std::numeric_limits<uint64_t>::max();
 
 /**
  * @brief provides management tools to the NDNS system, such as zone creation, zone delegation, DSK
@@ -139,7 +139,7 @@
                    const std::string& inFile = DEFAULT_IO,
                    const time::seconds& ttl = DEFAULT_RR_TTL,
                    const Name& dskCertName = DEFAULT_CERT,
-                   const ndn::io::IoEncoding encoding = ndn::io::BASE64,
+                   ndn::io::IoEncoding encoding = ndn::io::BASE64,
                    bool needResign = false);
 
   /** @brief Add rrset to the NDNS local database
@@ -211,7 +211,7 @@
    *  @throw Error if zoneName does not exist in the database
    */
   void
-  listZone(const Name& zoneName, std::ostream& os, const bool printRaw = false);
+  listZone(const Name& zoneName, std::ostream& os, bool printRaw = false);
 
   /** @brief lists all existing zones within this name server.
    *