build: switch to C++17

Change-Id: I119767c48c085c62556347ba6c11a85e30c32ced
diff --git a/src/access-manager.cpp b/src/access-manager.cpp
index 3602c98..0093d57 100644
--- a/src/access-manager.cpp
+++ b/src/access-manager.cpp
@@ -23,10 +23,9 @@
 #include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/util/logger.hpp>
 
-NDN_LOG_INIT(nac.AccessManager);
+namespace ndn::nac {
 
-namespace ndn {
-namespace nac {
+NDN_LOG_INIT(nac.AccessManager);
 
 AccessManager::AccessManager(const Identity& identity, const Name& dataset,
                              KeyChain& keyChain, Face& face)
@@ -123,5 +122,4 @@
   m_ims.erase(Name(m_nacKey.getName()).append(KDK).append(ENCRYPTED_BY).append(identity));
 }
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
diff --git a/src/access-manager.hpp b/src/access-manager.hpp
index 22dc2cc..5bfb0b1 100644
--- a/src/access-manager.hpp
+++ b/src/access-manager.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2021, Regents of the University of California
+ * Copyright (c) 2014-2022, Regents of the University of California
  *
  * NAC library is free software: you can redistribute it and/or modify it under the
  * terms of the GNU Lesser General Public License as published by the Free Software
@@ -24,8 +24,7 @@
 
 #include <ndn-cxx/face.hpp>
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 /**
  * @brief Access Manager
@@ -131,7 +130,6 @@
   ScopedRegisteredPrefixHandle m_kdkReg;
 };
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
 
 #endif // NDN_NAC_ACCESS_MANAGER_HPP
diff --git a/src/common.cpp b/src/common.cpp
index da4c5fd..45488b1 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018, Regents of the University of California
+/*
+ * Copyright (c) 2014-2022, Regents of the University of California
  *
  * NAC library is free software: you can redistribute it and/or modify it under the
  * terms of the GNU Lesser General Public License as published by the Free Software
@@ -19,8 +19,7 @@
 
 #include "common.hpp"
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 Name
 convertKekNameToKdkPrefix(const Name& kekName, const ErrorCallback& onFailure)
@@ -47,10 +46,9 @@
   }
 
   auto kekName = ckDataName.getSubName(ckName.size() + 1);
-  return std::make_tuple(convertKekNameToKdkPrefix(kekName, onFailure),
-                         kekName.getPrefix(-2),
-                         kekName.getPrefix(-2).append("KEY").append(kekName.get(-1)));
+  return {convertKekNameToKdkPrefix(kekName, onFailure),
+          kekName.getPrefix(-2),
+          kekName.getPrefix(-2).append("KEY").append(kekName.get(-1))};
 }
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
diff --git a/src/common.hpp b/src/common.hpp
index 1f95504..5aebdeb 100644
--- a/src/common.hpp
+++ b/src/common.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
  *
  * NAC library is free software: you can redistribute it and/or modify it under the
  * terms of the GNU Lesser General Public License as published by the Free Software
@@ -63,8 +63,7 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/noncopyable.hpp>
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 using security::Certificate;
 using security::DataValidationFailureCallback;
@@ -151,7 +150,6 @@
 std::tuple<Name, Name, Name>
 extractKdkInfoFromCkName(const Name& ckDataName, const Name& ckName, const ErrorCallback& onFailure);
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
 
 #endif // NDN_NAC_COMMON_HPP
diff --git a/src/decryptor.cpp b/src/decryptor.cpp
index 74290c8..0becbe2 100644
--- a/src/decryptor.cpp
+++ b/src/decryptor.cpp
@@ -25,8 +25,7 @@
 #include <ndn-cxx/util/exception.hpp>
 #include <ndn-cxx/util/logger.hpp>
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 NDN_LOG_INIT(nac.Decryptor);
 
@@ -72,9 +71,7 @@
                      "Missing required InitialVector in the supplied EncryptedContent block");
   }
 
-  ContentKeys::iterator ck;
-  bool isNew = false;
-  std::tie(ck, isNew) = m_cks.emplace(ec.getKeyLocator(), ContentKey{});
+  auto [ck, isNew] = m_cks.emplace(ec.getKeyLocator(), ContentKey{});
 
   if (ck->second.isRetrieved) {
     doDecrypt(ec, ck->second.bits, onSuccess, onFailure);
@@ -101,17 +98,15 @@
   //   from the encrypted data          unknown (name in retrieved CK is used to determine KDK)
 
   const Name& ckName = ck->first;
-
   NDN_LOG_DEBUG("Fetching CK " << ckName);
 
   ck->second.pendingInterest = m_face.expressInterest(Interest(ckName)
                                                        .setMustBeFresh(false) // ?
                                                        .setCanBePrefix(true),
     [=] (const Interest& ckInterest, const Data& ckData) {
-      ck->second.pendingInterest = nullopt;
+      ck->second.pendingInterest = std::nullopt;
       // TODO: verify that the key is legit
-      Name kdkPrefix, kdkIdentity, kdkKeyName;
-      std::tie(kdkPrefix, kdkIdentity, kdkKeyName) =
+      auto [kdkPrefix, kdkIdentity, kdkKeyName] =
         extractKdkInfoFromCkName(ckData.getName(), ckInterest.getName(), onFailure);
       if (kdkPrefix.empty()) {
         return; // error has been already reported
@@ -131,13 +126,13 @@
       fetchKdk(ck, kdkPrefix, ckData, onFailure, N_RETRIES);
     },
     [=] (const Interest& i, const lp::Nack& nack) {
-      ck->second.pendingInterest = nullopt;
+      ck->second.pendingInterest = std::nullopt;
       onFailure(ErrorCode::CkRetrievalFailure,
                 "Retrieval of CK [" + i.getName().toUri() + "] failed. "
                 "Got NACK (" + boost::lexical_cast<std::string>(nack.getReason()) + ")");
     },
     [=] (const Interest& i) {
-      ck->second.pendingInterest = nullopt;
+      ck->second.pendingInterest = std::nullopt;
       if (nTriesLeft > 1) {
         fetchCk(ck, onFailure, nTriesLeft - 1);
       }
@@ -167,7 +162,7 @@
 
   ck->second.pendingInterest = m_face.expressInterest(Interest(kdkName).setMustBeFresh(true),
     [=] (const Interest&, const Data& kdkData) {
-      ck->second.pendingInterest = nullopt;
+      ck->second.pendingInterest = std::nullopt;
       // TODO: verify that the key is legit
 
       bool isOk = decryptAndImportKdk(kdkData, onFailure);
@@ -178,13 +173,13 @@
                                          onFailure);
     },
     [=] (const Interest& i, const lp::Nack& nack) {
-      ck->second.pendingInterest = nullopt;
+      ck->second.pendingInterest = std::nullopt;
       onFailure(ErrorCode::KdkRetrievalFailure,
                 "Retrieval of KDK [" + i.getName().toUri() + "] failed. "
                 "Got NACK (" + boost::lexical_cast<std::string>(nack.getReason()) + ")");
     },
     [=] (const Interest& i) {
-      ck->second.pendingInterest = nullopt;
+      ck->second.pendingInterest = std::nullopt;
       if (nTriesLeft > 1) {
         fetchKdk(ck, kdkPrefix, ckData, onFailure, nTriesLeft - 1);
       }
@@ -264,5 +259,4 @@
   onSuccess(os.buf());
 }
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
diff --git a/src/decryptor.hpp b/src/decryptor.hpp
index edc6f2d..a8ea7c3 100644
--- a/src/decryptor.hpp
+++ b/src/decryptor.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2019, Regents of the University of California
+ * Copyright (c) 2014-2022, Regents of the University of California
  *
  * NAC library is free software: you can redistribute it and/or modify it under the
  * terms of the GNU Lesser General Public License as published by the Free Software
@@ -25,8 +25,7 @@
 
 #include <ndn-cxx/face.hpp>
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 /**
  * @brief NAC Decryptor
@@ -44,7 +43,7 @@
   {
     bool isRetrieved = false;
     Buffer bits;
-    optional<PendingInterestHandle> pendingInterest;
+    std::optional<PendingInterestHandle> pendingInterest;
 
     struct PendingDecrypt
     {
@@ -111,7 +110,6 @@
   ContentKeys m_cks;
 };
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
 
 #endif // NDN_NAC_DECRYPTOR_HPP
diff --git a/src/encrypted-content.cpp b/src/encrypted-content.cpp
index beaeda5..2bd8b27 100644
--- a/src/encrypted-content.cpp
+++ b/src/encrypted-content.cpp
@@ -23,12 +23,11 @@
 #include <ndn-cxx/util/concepts.hpp>
 #include <ndn-cxx/util/exception.hpp>
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 BOOST_CONCEPT_ASSERT((WireEncodable<EncryptedContent>));
 BOOST_CONCEPT_ASSERT((WireDecodable<EncryptedContent>));
-static_assert(std::is_base_of<ndn::tlv::Error, EncryptedContent::Error>::value,
+static_assert(std::is_base_of_v<ndn::tlv::Error, EncryptedContent::Error>,
               "EncryptedContent::Error must inherit from tlv::Error");
 
 EncryptedContent::EncryptedContent(const Block& block)
@@ -183,19 +182,14 @@
   if (!wire.hasWire()) {
     NDN_THROW(Error("The supplied block does not contain wire format"));
   }
+  if (wire.type() != tlv::EncryptedContent) {
+    NDN_THROW(Error("EncryptedContent", wire.type()));
+  }
 
-  m_payload.reset();
-  m_iv.reset();
-  m_payloadKey.reset();
-
+  *this = {};
   m_wire = wire;
   m_wire.parse();
 
-  if (m_wire.type() != tlv::EncryptedContent) {
-    NDN_THROW(Error("Unexpected TLV type (expecting EncryptedContent, got " +
-                    ndn::to_string(m_wire.type()) + ")"));
-  }
-
   auto block = m_wire.find(tlv::EncryptedPayload);
   if (block != m_wire.elements_end()) {
     m_payload = *block;
@@ -220,5 +214,4 @@
   }
 }
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
diff --git a/src/encrypted-content.hpp b/src/encrypted-content.hpp
index 5ba0ab1..03b85d5 100644
--- a/src/encrypted-content.hpp
+++ b/src/encrypted-content.hpp
@@ -24,23 +24,22 @@
 
 #include <ndn-cxx/encoding/tlv.hpp>
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 /**
  * @brief Encrypted content
  *
- * <code>
- *     EncryptedContent ::= ENCRYPTED-CONTENT-TYPE TLV-LENGTH
- *                            InitializationVector
- *                            EncryptedPayload
- *                            EncryptedPayloadKey
- *                            Name
+ * @verbatim
+ * EncryptedContent ::= ENCRYPTED-CONTENT-TYPE TLV-LENGTH
+ *                        InitializationVector
+ *                        EncryptedPayload
+ *                        EncryptedPayloadKey
+ *                        Name
  *
- *     InitializationVector ::= INITIALIZATION-VECTOR-TYPE TLV-LENGTH(=N) BYTE{N}
- *     EncryptedPayload ::= ENCRYPTED-PAYLOAD-TYPE TLV-LENGTH(=N) BYTE{N}
- *     EncryptedPayloadKey ::= ENCRYPTED-PAYLOAD-KEY-TYPE TLV-LENGTH(=N) BYTE{N}
- * </code>
+ * InitializationVector ::= INITIALIZATION-VECTOR-TYPE TLV-LENGTH(=N) BYTE{N}
+ * EncryptedPayload ::= ENCRYPTED-PAYLOAD-TYPE TLV-LENGTH(=N) BYTE{N}
+ * EncryptedPayloadKey ::= ENCRYPTED-PAYLOAD-KEY-TYPE TLV-LENGTH(=N) BYTE{N}
+ * @endverbatim
  */
 class EncryptedContent
 {
@@ -149,7 +148,6 @@
   mutable Block m_wire;
 };
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
 
 #endif // NDN_NAC_ENCRYPTED_CONTENT_HPP
diff --git a/src/encryptor.cpp b/src/encryptor.cpp
index b35a744..04febf0 100644
--- a/src/encryptor.cpp
+++ b/src/encryptor.cpp
@@ -24,8 +24,7 @@
 #include <ndn-cxx/security/transform/stream-sink.hpp>
 #include <ndn-cxx/util/logger.hpp>
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 NDN_LOG_INIT(nac.Encryptor);
 
@@ -207,5 +206,4 @@
   }
 }
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
diff --git a/src/encryptor.hpp b/src/encryptor.hpp
index 1b177eb..d0d1415 100644
--- a/src/encryptor.hpp
+++ b/src/encryptor.hpp
@@ -23,13 +23,12 @@
 #include "common.hpp"
 #include "encrypted-content.hpp"
 
-namespace ndn {
-namespace nac {
+namespace ndn::nac {
 
 /**
  * @brief NAC Encryptor
  *
- * Encryptor encrypts the requested content and returns ``EncryptedContent`` element.
+ * Encryptor encrypts the requested content and returns an EncryptedContent element.
  */
 class Encryptor
 {
@@ -135,7 +134,7 @@
   SigningInfo m_ckDataSigningInfo;
 
   bool m_isKekRetrievalInProgress;
-  optional<Data> m_kek;
+  std::optional<Data> m_kek;
   ErrorCallback m_onFailure;
 
   InMemoryStoragePersistent m_ims; // for encrypted CKs
@@ -147,7 +146,6 @@
   Scheduler m_scheduler;
 };
 
-} // namespace nac
-} // namespace ndn
+} // namespace ndn::nac
 
 #endif // NDN_NAC_ENCRYPTOR_HPP
diff --git a/src/version.hpp.in b/src/version.hpp.in
index 2f002c9..2cebe55 100644
--- a/src/version.hpp.in
+++ b/src/version.hpp.in
@@ -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
  *
  * NAC library is free software: you can redistribute it and/or modify it under the
  * terms of the GNU Lesser General Public License as published by the Free Software
@@ -20,49 +20,49 @@
 #ifndef NDN_NAC_VERSION_HPP
 #define NDN_NAC_VERSION_HPP
 
-namespace ndn {
-namespace nac {
+// ndn-nac version follows Semantic Versioning 2.0.0
+// https://semver.org/spec/v2.0.0.html
 
-/** ndn-nac version follows Semantic Versioning 2.0.0 specification
- *  http://semver.org/
- */
-
-/** \brief ndn-nac version represented as an integer
+/**
+ * \brief ndn-nac version represented as an integer.
  *
- *  MAJOR*1000000 + MINOR*1000 + PATCH
+ * Equivalent to: #NDN_NAC_VERSION_MAJOR*1000000 + #NDN_NAC_VERSION_MINOR*1000 + #NDN_NAC_VERSION_PATCH
  */
 #define NDN_NAC_VERSION @VERSION@
 
-/** \brief ndn-nac version represented as a string
+/// The major version of ndn-nac
+#define NDN_NAC_VERSION_MAJOR @VERSION_MAJOR@
+/// The minor version of ndn-nac
+#define NDN_NAC_VERSION_MINOR @VERSION_MINOR@
+/// The patch version of ndn-nac
+#define NDN_NAC_VERSION_PATCH @VERSION_PATCH@
+
+/**
+ * \brief ndn-nac version represented as a string.
  *
- *  MAJOR.MINOR.PATCH
+ * Format:
+ * @code
+ * MAJOR.MINOR.PATCH
+ * @endcode
  */
 #define NDN_NAC_VERSION_STRING "@VERSION_STRING@"
 
-/** \brief ndn-nac version string, including git commit information, if ndn-nac is build from
- *         specific git commit
+/**
+ * \brief ndn-nac version string, including git commit information if ndn-nac is built from a
+ *        specific git commit.
  *
- * NDN_NAC_VERSION_BUILD_STRING is obtained using the following command (`ndn-nac-` prefix is
- * afterwards removed):
+ * #NDN_NAC_VERSION_BUILD_STRING is obtained using the following command (`ndn-nac-` prefix is
+ * afterwards removed): ``git describe --match 'ndn-nac-*'``
  *
- *    `git describe --match 'ndn-nac-*'`
+ * When ndn-nac is not built from git, #NDN_NAC_VERSION_BUILD_STRING equals #NDN_NAC_VERSION_STRING.
  *
- * When ndn-nac is built not from git, NDN_NAC_VERSION_BUILD_STRING equals NDN_NAC_VERSION_STRING
- *
+ * Format:
+ * @code
  * MAJOR.MINOR.PATCH(-release-candidate-tag)(-(number-of-commits-since-tag)-COMMIT-HASH)
+ * @endcode
  *
- * Example, 0.1.0-rc1-1-g5c86570
+ * Example: 0.1.0-rc1-1-g5c86570
  */
 #define NDN_NAC_VERSION_BUILD_STRING "@VERSION_BUILD@"
 
-/// MAJOR version
-#define NDN_NAC_VERSION_MAJOR @VERSION_MAJOR@
-/// MINOR version
-#define NDN_NAC_VERSION_MINOR @VERSION_MINOR@
-/// PATCH version
-#define NDN_NAC_VERSION_PATCH @VERSION_PATCH@
-
-} // namespace nac
-} // namespace ndn
-
 #endif // NDN_NAC_VERSION_HPP