Replace all uses of BOOST_THROW_EXCEPTION with NDN_THROW

Refs: #4834
Change-Id: Ic63e276b7174f3af12af67daa9cad4586b43b9e6
diff --git a/examples/producer.cpp b/examples/producer.cpp
index ac3165e..a1f3422 100644
--- a/examples/producer.cpp
+++ b/examples/producer.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-2020, 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,6 +19,7 @@
 
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/security/validator-config.hpp>
 
 #include "encryptor.hpp"
diff --git a/src/access-manager.cpp b/src/access-manager.cpp
index 368c44a..a759f2d 100644
--- a/src/access-manager.cpp
+++ b/src/access-manager.cpp
@@ -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-2020, 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,6 +20,7 @@
 #include "access-manager.hpp"
 #include "encrypted-content.hpp"
 
+#include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/util/logger.hpp>
 
 NDN_LOG_INIT(nac.AccessManager);
diff --git a/src/common.hpp b/src/common.hpp
index 0c762ce..1f95504 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-2020, Regents of the University of California
  *
  * NAC library is free software: you can redistribute it and/or modify it under the
@@ -48,13 +48,9 @@
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/ims/in-memory-storage-persistent.hpp>
 #include <ndn-cxx/interest.hpp>
-#include <ndn-cxx/link.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
-#include <ndn-cxx/security/signing-helpers.hpp>
-#include <ndn-cxx/security/transform/block-cipher.hpp>
-#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/signing-info.hpp>
 #include <ndn-cxx/security/transform/public-key.hpp>
-#include <ndn-cxx/security/transform/stream-sink.hpp>
 #include <ndn-cxx/security/validation-callback.hpp>
 #include <ndn-cxx/security/validation-error.hpp>
 #include <ndn-cxx/security/validator-null.hpp>
@@ -63,7 +59,6 @@
 #include <ndn-cxx/util/signal.hpp>
 
 #include <boost/algorithm/string.hpp>
-#include <boost/asio.hpp>
 #include <boost/assert.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/noncopyable.hpp>
@@ -131,8 +126,7 @@
   EncryptionFailure = 103
 };
 
-using ErrorCallback = std::function<void (const ErrorCode&, const std::string&)>;
-
+using ErrorCallback = std::function<void(const ErrorCode&, const std::string&)>;
 
 class Error : public std::runtime_error
 {
diff --git a/src/decryptor.cpp b/src/decryptor.cpp
index 80ccb93..1630080 100644
--- a/src/decryptor.cpp
+++ b/src/decryptor.cpp
@@ -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-2020, 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,6 +19,10 @@
 
 #include "decryptor.hpp"
 
+#include <ndn-cxx/security/transform/block-cipher.hpp>
+#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/transform/stream-sink.hpp>
+#include <ndn-cxx/util/exception.hpp>
 #include <ndn-cxx/util/logger.hpp>
 
 namespace ndn {
@@ -251,7 +255,7 @@
                      const ErrorCallback& onFailure)
 {
   if (!content.hasIv()) {
-    BOOST_THROW_EXCEPTION(Error("Expecting Initial Vector in the encrypted content, but it is not present"));
+    NDN_THROW(Error("Expecting Initialization Vector in the encrypted content, but it is not present"));
   }
 
   OBufferStream os;
diff --git a/src/encrypted-content.cpp b/src/encrypted-content.cpp
index 20c9886..4bc3d44 100644
--- a/src/encrypted-content.cpp
+++ b/src/encrypted-content.cpp
@@ -21,6 +21,7 @@
 
 #include <ndn-cxx/encoding/block-helpers.hpp>
 #include <ndn-cxx/util/concepts.hpp>
+#include <ndn-cxx/util/exception.hpp>
 
 namespace ndn {
 namespace nac {
@@ -153,7 +154,7 @@
     totalLength += block.prependBlock(m_payload);
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("Required EncryptedPayload is not set on EncryptedContent"));
+    NDN_THROW(Error("Required EncryptedPayload is not set on EncryptedContent"));
   }
 
   totalLength += block.prependVarNumber(totalLength);
@@ -181,7 +182,7 @@
 EncryptedContent::wireDecode(const Block& wire)
 {
   if (!wire.hasWire()) {
-    BOOST_THROW_EXCEPTION(Error("The supplied block does not contain wire format"));
+    NDN_THROW(Error("The supplied block does not contain wire format"));
   }
 
   m_payload.reset();
@@ -192,8 +193,8 @@
   m_wire.parse();
 
   if (m_wire.type() != tlv::EncryptedContent) {
-    BOOST_THROW_EXCEPTION(Error("Unexpected TLV type (expecting EncryptedContent, got" +
-                                ndn::to_string(m_wire.type()) + ")"));
+    NDN_THROW(Error("Unexpected TLV type (expecting EncryptedContent, got " +
+                    ndn::to_string(m_wire.type()) + ")"));
   }
 
   auto block = m_wire.find(tlv::EncryptedPayload);
@@ -201,7 +202,7 @@
     m_payload = *block;
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("Required EncryptedPayload not found in EncryptedContent"));
+    NDN_THROW(Error("Required EncryptedPayload not found in EncryptedContent"));
   }
 
   block = m_wire.find(tlv::InitializationVector);
diff --git a/src/encryptor.cpp b/src/encryptor.cpp
index efee391..5059eba 100644
--- a/src/encryptor.cpp
+++ b/src/encryptor.cpp
@@ -19,8 +19,10 @@
 
 #include "encryptor.hpp"
 
+#include <ndn-cxx/security/transform/block-cipher.hpp>
+#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/transform/stream-sink.hpp>
 #include <ndn-cxx/util/logger.hpp>
-#include <boost/lexical_cast.hpp>
 
 namespace ndn {
 namespace nac {
@@ -112,7 +114,7 @@
 EncryptedContent
 Encryptor::encrypt(const uint8_t* data, size_t size)
 {
-  // Generate initial vector
+  // Generate IV
   auto iv = make_shared<Buffer>(AES_IV_SIZE);
   random::generateSecureBytes(iv->data(), iv->size());
 
diff --git a/tools/ndn-nac/main.cpp b/tools/ndn-nac/main.cpp
index 0ebe9ed..6858532 100644
--- a/tools/ndn-nac/main.cpp
+++ b/tools/ndn-nac/main.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-2020, 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,12 +20,13 @@
 #include "ndn-nac.hpp"
 #include "version.hpp"
 
-#include <boost/exception/get_error_info.hpp>
+#include <boost/exception/diagnostic_information.hpp>
+
 #include <ndn-cxx/util/logger.hpp>
 
 NDN_LOG_INIT(nac.Cmd);
 
-std::string nac_helper = R"STR(
+const char NAC_HELP_TEXT[] = R"STR(
   help         Show all commands
   version      Show version and exit
   dump-kek     Dump KEK
@@ -36,39 +37,28 @@
 main(int argc, char** argv)
 {
   if (argc < 2) {
-    std::cerr << nac_helper << std::endl;
-    return 1;
+    std::cerr << NAC_HELP_TEXT << std::endl;
+    return 2;
   }
 
   using namespace ndn::nac;
 
   std::string command(argv[1]);
   try {
-    if (command == "help")              { std::cout << nac_helper << std::endl; }
+    if (command == "help")              { std::cout << NAC_HELP_TEXT << std::endl; }
     else if (command == "version")      { std::cout << NDN_NAC_VERSION_BUILD_STRING << std::endl; }
     else if (command == "dump-kek")     { return nac_dump_kek(argc - 1, argv + 1); }
     else if (command == "add-member")   { return nac_add_member(argc - 1, argv + 1); }
     else {
-      std::cerr << nac_helper << std::endl;
-      return 1;
+      std::cerr << "ERROR: Unknown command '" << command << "'\n"
+                << "\n"
+                << NAC_HELP_TEXT << std::endl;
+      return 2;
     }
   }
   catch (const std::exception& e) {
-
-    std::cerr << "ERROR: " << e.what();
-
-    std::ostringstream extendedError;
-    const char* const* file = boost::get_error_info<boost::throw_file>(e);
-    const int* line = boost::get_error_info<boost::throw_line>(e);
-    const char* const* func = boost::get_error_info<boost::throw_function>(e);
-    if (file && line) {
-      extendedError << " [from " << *file << ":" << *line;
-      if (func) {
-        extendedError << " in " << *func;
-      }
-      extendedError << "]";
-    }
-    NDN_LOG_ERROR(e.what() << extendedError.str());
+    std::cerr << "ERROR: " << e.what() << std::endl;
+    NDN_LOG_ERROR(boost::diagnostic_information(e));
     return 1;
   }
 
diff --git a/tools/ndn-nac/ndn-nac.hpp b/tools/ndn-nac/ndn-nac.hpp
index 5c8fd85..44b264e 100644
--- a/tools/ndn-nac/ndn-nac.hpp
+++ b/tools/ndn-nac/ndn-nac.hpp
@@ -1,5 +1,5 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
  * Copyright (c) 2014-2020, Regents of the University of California
  *
  * NAC library is free software: you can redistribute it and/or modify it under the
@@ -22,17 +22,14 @@
 
 #include "common.hpp"
 
-#include <fstream>
 #include <iostream>
-#include <string>
 
-#include <boost/asio.hpp>
-#include <boost/exception/all.hpp>
 #include <boost/program_options/options_description.hpp>
 #include <boost/program_options/parsers.hpp>
 #include <boost/program_options/variables_map.hpp>
 
 #include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/util/exception.hpp>
 #include <ndn-cxx/util/io.hpp>
 
 namespace ndn {
@@ -54,7 +51,7 @@
     cert = io::load<Certificate>(fileName);
 
   if (cert == nullptr) {
-    BOOST_THROW_EXCEPTION(std::runtime_error("Cannot load certificate from " + fileName));
+    NDN_THROW(std::runtime_error("Cannot load certificate from " + fileName));
   }
   return *cert;
 }