further update and rename files

Change-Id: Ie664c5b9e5a764b8706d21cc85b9cec8755dc380
diff --git a/src/ca-state.cpp b/src/ca-detail/ca-state.cpp
similarity index 100%
rename from src/ca-state.cpp
rename to src/ca-detail/ca-state.cpp
diff --git a/src/ca-state.hpp b/src/ca-detail/ca-state.hpp
similarity index 98%
rename from src/ca-state.hpp
rename to src/ca-detail/ca-state.hpp
index 2204f1c..4c99185 100644
--- a/src/ca-state.hpp
+++ b/src/ca-detail/ca-state.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_CA_STATE_HPP
 #define NDNCERT_CA_STATE_HPP
 
-#include "detail/ndncert-common.hpp"
+#include "protocol-detail/ndncert-common.hpp"
 
 namespace ndn {
 namespace ndncert {
diff --git a/src/ca-detail/ca-storage.hpp b/src/ca-detail/ca-storage.hpp
index e18a5bc..e35af1a 100644
--- a/src/ca-detail/ca-storage.hpp
+++ b/src/ca-detail/ca-storage.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_CA_STORAGE_HPP
 #define NDNCERT_CA_STORAGE_HPP
 
-#include "ca-state.hpp"
+#include "ca-detail/ca-state.hpp"
 
 namespace ndn {
 namespace ndncert {
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index a6b0f7d..f2e825a 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -19,14 +19,14 @@
  */
 
 #include "ca-module.hpp"
-#include "detail/enc-tlv.hpp"
+#include "protocol-detail/crypto-helper.hpp"
 #include "identity-challenge/challenge-module.hpp"
 #include "name-assignments/assignment-funcs.hpp"
-#include "detail/challenge-encoder.hpp"
-#include "detail/error-encoder.hpp"
-#include "detail/info-encoder.hpp"
-#include "detail/new-renew-revoke-encoder.hpp"
-#include "detail/probe-encoder.hpp"
+#include "protocol-detail/challenge-encoder.hpp"
+#include "protocol-detail/error-encoder.hpp"
+#include "protocol-detail/info-encoder.hpp"
+#include "protocol-detail/new-renew-revoke-encoder.hpp"
+#include "protocol-detail/probe-encoder.hpp"
 #include <ndn-cxx/metadata-object.hpp>
 #include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/security/verification-helpers.hpp>
diff --git a/src/ca-module.hpp b/src/ca-module.hpp
index 118a85e..3fb79cb 100644
--- a/src/ca-module.hpp
+++ b/src/ca-module.hpp
@@ -22,7 +22,7 @@
 #define NDNCERT_CA_MODULE_HPP
 
 #include "configuration.hpp"
-#include "detail/crypto-helper.hpp"
+#include "protocol-detail/crypto-helper.hpp"
 #include "ca-detail/ca-storage.hpp"
 
 namespace ndn {
diff --git a/src/configuration.hpp b/src/configuration.hpp
index eee8d35..87b115a 100644
--- a/src/configuration.hpp
+++ b/src/configuration.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_CONFIGURATION_HPP
 #define NDNCERT_CONFIGURATION_HPP
 
-#include "ca-state.hpp"
+#include "ca-detail/ca-state.hpp"
 #include "name-assignments/assignment-funcs.hpp"
 
 namespace ndn {
diff --git a/src/detail/enc-tlv.cpp b/src/detail/enc-tlv.cpp
deleted file mode 100644
index 8342300..0000000
--- a/src/detail/enc-tlv.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
- *
- * This file is part of ndncert, a certificate management system based on NDN.
- *
- * ndncert is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received copies of the GNU General Public License along with
- * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndncert authors and contributors.
- */
-
-#include "enc-tlv.hpp"
-#include "crypto-helper.hpp"
-#include <ndn-cxx/encoding/buffer-stream.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/random.hpp>
-
-namespace ndn {
-namespace ndncert {
-
-Block
-encodeBlockWithAesGcm128(uint32_t tlv_type, const uint8_t* key, const uint8_t* payload, size_t payloadSize,
-                         const uint8_t* associatedData, size_t associatedDataSize)
-{
-  Buffer iv;
-  iv.resize(12);
-  random::generateSecureBytes(iv.data(), iv.size());
-
-  uint8_t* encryptedPayload = new uint8_t[payloadSize];
-  uint8_t tag[16];
-  size_t encryptedPayloadLen = aes_gcm_128_encrypt(payload, payloadSize, associatedData, associatedDataSize,
-                                                   key, iv.data(), encryptedPayload, tag);
-  auto content = makeEmptyBlock(tlv_type);
-  content.push_back(makeBinaryBlock(tlv::InitializationVector, iv.data(), iv.size()));
-  content.push_back(makeBinaryBlock(tlv::AuthenticationTag, tag, 16));
-  content.push_back(makeBinaryBlock(tlv::EncryptedPayload, encryptedPayload, encryptedPayloadLen));
-  content.encode();
-  delete[] encryptedPayload;
-  return content;
-}
-
-Buffer
-decodeBlockWithAesGcm128(const Block& block, const uint8_t* key, const uint8_t* associatedData, size_t associatedDataSize)
-{
-  block.parse();
-  Buffer result;
-  result.resize(block.get(tlv::EncryptedPayload).value_size());
-  int resultLen = aes_gcm_128_decrypt(block.get(tlv::EncryptedPayload).value(),
-                                      block.get(tlv::EncryptedPayload).value_size(),
-                                      associatedData, associatedDataSize, block.get(tlv::AuthenticationTag).value(),
-                                      key, block.get(tlv::InitializationVector).value(), result.data());
-  if (resultLen == -1 || resultLen != (int)block.get(tlv::EncryptedPayload).value_size()) {
-    return Buffer();
-  }
-  return result;
-}
-
-} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/enc-tlv.hpp b/src/detail/enc-tlv.hpp
deleted file mode 100644
index 1c55119..0000000
--- a/src/detail/enc-tlv.hpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
- *
- * This file is part of ndncert, a certificate management system based on NDN.
- *
- * ndncert is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received copies of the GNU General Public License along with
- * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndncert authors and contributors.
- */
-
-#ifndef NDNCERT_CRYPTO_SUPPORT_ENC_TLV_HPP
-#define NDNCERT_CRYPTO_SUPPORT_ENC_TLV_HPP
-
-#include "ndncert-common.hpp"
-
-namespace ndn {
-namespace ndncert {
-
-/**
- * Encode the payload into TLV block with Authenticated GCM 128 Encryption
- * @p tlv::type, intput, the TLV TYPE of the encoded block, either ApplicationParameters or Content
- * @p key, intput, 16 Bytes, the AES key used for encryption
- * @p payload, input, the plaintext payload
- * @p payloadSize, input, the size of the plaintext payload
- * @p associatedData, input, associated data used for authentication
- * @p associatedDataSize, input, the size of associated data
- * @return the TLV block with @p tlv::type TLV TYPE
- */
-Block
-encodeBlockWithAesGcm128(uint32_t tlv_type, const uint8_t* key, const uint8_t* payload, size_t payloadSize,
-                         const uint8_t* associatedData, size_t associatedDataSize);
-
-/**
- * Decode the payload from TLV block with Authenticated GCM 128 Encryption
- * @p block, intput, the TLV block in the format of NDNCERT protocol
- * @p key, intput, 16 Bytes, the AES key used for encryption
- * @p associatedData, input, associated data used for authentication
- * @p associatedDataSize, input, the size of associated data
- * @return the plaintext buffer
- */
-Buffer
-decodeBlockWithAesGcm128(const Block& block, const uint8_t* key,
-                         const uint8_t* associatedData, size_t associatedDataSize);
-
-} // namespace ndncert
-} // namespace ndn
-
-#endif // NDNCERT_CRYPTO_SUPPORT_ENC_TLV_HPP
diff --git a/src/identity-challenge/challenge-module.hpp b/src/identity-challenge/challenge-module.hpp
index 66f705e..eabb19d 100644
--- a/src/identity-challenge/challenge-module.hpp
+++ b/src/identity-challenge/challenge-module.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_CHALLENGE_MODULE_HPP
 #define NDNCERT_CHALLENGE_MODULE_HPP
 
-#include "ca-state.hpp"
+#include "ca-detail/ca-state.hpp"
 
 namespace ndn {
 namespace ndncert {
diff --git a/src/name-assignments/assignment-funcs.hpp b/src/name-assignments/assignment-funcs.hpp
index 42a34ed..a39bb82 100644
--- a/src/name-assignments/assignment-funcs.hpp
+++ b/src/name-assignments/assignment-funcs.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_ASSIGNMENT_FUNCS_HPP
 #define NDNCERT_ASSIGNMENT_FUNCS_HPP
 
-#include "../ca-state.hpp"
+#include "../ca-detail/ca-state.hpp"
 
 namespace ndn {
 namespace ndncert {
diff --git a/src/detail/challenge-encoder.cpp b/src/protocol-detail/challenge-encoder.cpp
similarity index 100%
rename from src/detail/challenge-encoder.cpp
rename to src/protocol-detail/challenge-encoder.cpp
diff --git a/src/detail/challenge-encoder.hpp b/src/protocol-detail/challenge-encoder.hpp
similarity index 86%
rename from src/detail/challenge-encoder.hpp
rename to src/protocol-detail/challenge-encoder.hpp
index f66d9cb..60372f9 100644
--- a/src/detail/challenge-encoder.hpp
+++ b/src/protocol-detail/challenge-encoder.hpp
@@ -18,10 +18,10 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#ifndef NDNCERT_DETAIL_CHALLENGE_STEP_HPP
-#define NDNCERT_DETAIL_CHALLENGE_STEP_HPP
+#ifndef NDNCERT_PROTOCOL_DETAIL_CHALLENGE_STEP_HPP
+#define NDNCERT_PROTOCOL_DETAIL_CHALLENGE_STEP_HPP
 
-#include "../ca-state.hpp"
+#include "../ca-detail/ca-state.hpp"
 #include "../requester-state.hpp"
 
 namespace ndn {
@@ -40,4 +40,4 @@
 } // namespace ndncert
 } // namespace ndn
 
-#endif // NDNCERT_DETAIL_CHALLENGE_STEP_HPP
\ No newline at end of file
+#endif // NDNCERT_PROTOCOL_DETAIL_CHALLENGE_STEP_HPP
\ No newline at end of file
diff --git a/src/detail/crypto-helper.cpp b/src/protocol-detail/crypto-helper.cpp
similarity index 87%
rename from src/detail/crypto-helper.cpp
rename to src/protocol-detail/crypto-helper.cpp
index 5a56ab1..a7f561d 100644
--- a/src/detail/crypto-helper.cpp
+++ b/src/protocol-detail/crypto-helper.cpp
@@ -32,6 +32,7 @@
 #include <ndn-cxx/security/transform/signer-filter.hpp>
 #include <ndn-cxx/security/transform/step-source.hpp>
 #include <ndn-cxx/security/transform/stream-sink.hpp>
+#include <ndn-cxx/util/random.hpp>
 
 namespace ndn {
 namespace ndncert {
@@ -40,6 +41,13 @@
 
 NDN_LOG_INIT(ndncert.cryptosupport);
 
+void
+handleErrors(const std::string& errorInfo)
+{
+  NDN_LOG_DEBUG("Error in CRYPTO SUPPORT " << errorInfo);
+  NDN_THROW(std::runtime_error("Error in CRYPTO SUPPORT: " + errorInfo));
+}
+
 struct ECDHState::ECDH_CTX
 {
   int EC_NID;
@@ -387,11 +395,41 @@
   }
 }
 
-void
-handleErrors(const std::string& errorInfo)
+Block
+encodeBlockWithAesGcm128(uint32_t tlv_type, const uint8_t* key, const uint8_t* payload, size_t payloadSize,
+                         const uint8_t* associatedData, size_t associatedDataSize)
 {
-  NDN_LOG_DEBUG("Error in CRYPTO SUPPORT " << errorInfo);
-  NDN_THROW(std::runtime_error("Error in CRYPTO SUPPORT: " + errorInfo));
+  Buffer iv;
+  iv.resize(12);
+  random::generateSecureBytes(iv.data(), iv.size());
+
+  uint8_t* encryptedPayload = new uint8_t[payloadSize];
+  uint8_t tag[16];
+  size_t encryptedPayloadLen = aes_gcm_128_encrypt(payload, payloadSize, associatedData, associatedDataSize,
+                                                   key, iv.data(), encryptedPayload, tag);
+  auto content = makeEmptyBlock(tlv_type);
+  content.push_back(makeBinaryBlock(tlv::InitializationVector, iv.data(), iv.size()));
+  content.push_back(makeBinaryBlock(tlv::AuthenticationTag, tag, 16));
+  content.push_back(makeBinaryBlock(tlv::EncryptedPayload, encryptedPayload, encryptedPayloadLen));
+  content.encode();
+  delete[] encryptedPayload;
+  return content;
+}
+
+Buffer
+decodeBlockWithAesGcm128(const Block& block, const uint8_t* key, const uint8_t* associatedData, size_t associatedDataSize)
+{
+  block.parse();
+  Buffer result;
+  result.resize(block.get(tlv::EncryptedPayload).value_size());
+  int resultLen = aes_gcm_128_decrypt(block.get(tlv::EncryptedPayload).value(),
+                                      block.get(tlv::EncryptedPayload).value_size(),
+                                      associatedData, associatedDataSize, block.get(tlv::AuthenticationTag).value(),
+                                      key, block.get(tlv::InitializationVector).value(), result.data());
+  if (resultLen == -1 || resultLen != (int)block.get(tlv::EncryptedPayload).value_size()) {
+    return Buffer();
+  }
+  return result;
 }
 
 } // namespace ndncert
diff --git a/src/detail/crypto-helper.hpp b/src/protocol-detail/crypto-helper.hpp
similarity index 75%
rename from src/detail/crypto-helper.hpp
rename to src/protocol-detail/crypto-helper.hpp
index a590bfa..50aa7bb 100644
--- a/src/detail/crypto-helper.hpp
+++ b/src/protocol-detail/crypto-helper.hpp
@@ -18,8 +18,8 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#ifndef NDNCERT_CRYPTO_SUPPORT_CRYPTO_HELPER_HPP
-#define NDNCERT_CRYPTO_SUPPORT_CRYPTO_HELPER_HPP
+#ifndef NDNCERT_PROTOCOL_DETAIL_CRYPTO_HELPER_HPP
+#define NDNCERT_PROTOCOL_DETAIL_CRYPTO_HELPER_HPP
 
 #include "ndncert-common.hpp"
 
@@ -125,10 +125,33 @@
 aes_gcm_128_decrypt(const uint8_t* ciphertext, size_t ciphertext_len, const uint8_t* associated, size_t associated_len,
                     const uint8_t* tag, const uint8_t* key, const uint8_t* iv, uint8_t* plaintext);
 
-void
-handleErrors(const std::string& errorInfo);
+/**
+ * Encode the payload into TLV block with Authenticated GCM 128 Encryption
+ * @p tlv::type, intput, the TLV TYPE of the encoded block, either ApplicationParameters or Content
+ * @p key, intput, 16 Bytes, the AES key used for encryption
+ * @p payload, input, the plaintext payload
+ * @p payloadSize, input, the size of the plaintext payload
+ * @p associatedData, input, associated data used for authentication
+ * @p associatedDataSize, input, the size of associated data
+ * @return the TLV block with @p tlv::type TLV TYPE
+ */
+Block
+encodeBlockWithAesGcm128(uint32_t tlv_type, const uint8_t* key, const uint8_t* payload, size_t payloadSize,
+                         const uint8_t* associatedData, size_t associatedDataSize);
+
+/**
+ * Decode the payload from TLV block with Authenticated GCM 128 Encryption
+ * @p block, intput, the TLV block in the format of NDNCERT protocol
+ * @p key, intput, 16 Bytes, the AES key used for encryption
+ * @p associatedData, input, associated data used for authentication
+ * @p associatedDataSize, input, the size of associated data
+ * @return the plaintext buffer
+ */
+Buffer
+decodeBlockWithAesGcm128(const Block& block, const uint8_t* key,
+                         const uint8_t* associatedData, size_t associatedDataSize);
 
 } // namespace ndncert
 } // namespace ndn
 
-#endif // NDNCERT_CRYPTO_SUPPORT_CRYPTO_HELPER_HPP
+#endif // NDNCERT_PROTOCOL_DETAIL_CRYPTO_HELPER_HPP
diff --git a/src/detail/error-encoder.cpp b/src/protocol-detail/error-encoder.cpp
similarity index 100%
rename from src/detail/error-encoder.cpp
rename to src/protocol-detail/error-encoder.cpp
diff --git a/src/detail/error-encoder.hpp b/src/protocol-detail/error-encoder.hpp
similarity index 90%
rename from src/detail/error-encoder.hpp
rename to src/protocol-detail/error-encoder.hpp
index ade9fb3..76ecb36 100644
--- a/src/detail/error-encoder.hpp
+++ b/src/protocol-detail/error-encoder.hpp
@@ -18,8 +18,8 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#ifndef NDNCERT_DETAIL_ERROR_ENCODER_HPP
-#define NDNCERT_DETAIL_ERROR_ENCODER_HPP
+#ifndef NDNCERT_PROTOCOL_DETAIL_ERROR_ENCODER_HPP
+#define NDNCERT_PROTOCOL_DETAIL_ERROR_ENCODER_HPP
 
 #include "../configuration.hpp"
 
@@ -45,4 +45,4 @@
 } // namespace ndncert
 } // namespace ndn
 
-#endif // NDNCERT_DETAIL_ERROR_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_PROTOCOL_DETAIL_ERROR_ENCODER_HPP
\ No newline at end of file
diff --git a/src/detail/info-encoder.cpp b/src/protocol-detail/info-encoder.cpp
similarity index 100%
rename from src/detail/info-encoder.cpp
rename to src/protocol-detail/info-encoder.cpp
diff --git a/src/detail/info-encoder.hpp b/src/protocol-detail/info-encoder.hpp
similarity index 90%
rename from src/detail/info-encoder.hpp
rename to src/protocol-detail/info-encoder.hpp
index 8c3ed09..e317d5a 100644
--- a/src/detail/info-encoder.hpp
+++ b/src/protocol-detail/info-encoder.hpp
@@ -18,8 +18,8 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#ifndef NDNCERT_DETAIL_INFO_ENCODER_HPP
-#define NDNCERT_DETAIL_INFO_ENCODER_HPP
+#ifndef NDNCERT_PROTOCOL_DETAIL_INFO_ENCODER_HPP
+#define NDNCERT_PROTOCOL_DETAIL_INFO_ENCODER_HPP
 
 #include "../configuration.hpp"
 
@@ -45,4 +45,4 @@
 } // namespace ndncert
 } // namespace ndn
 
-#endif // NDNCERT_DETAIL_INFO_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_PROTOCOL_DETAIL_INFO_ENCODER_HPP
\ No newline at end of file
diff --git a/src/detail/ndncert-common.cpp b/src/protocol-detail/ndncert-common.cpp
similarity index 100%
rename from src/detail/ndncert-common.cpp
rename to src/protocol-detail/ndncert-common.cpp
diff --git a/src/detail/ndncert-common.hpp b/src/protocol-detail/ndncert-common.hpp
similarity index 100%
rename from src/detail/ndncert-common.hpp
rename to src/protocol-detail/ndncert-common.hpp
diff --git a/src/detail/new-renew-revoke-encoder.cpp b/src/protocol-detail/new-renew-revoke-encoder.cpp
similarity index 100%
rename from src/detail/new-renew-revoke-encoder.cpp
rename to src/protocol-detail/new-renew-revoke-encoder.cpp
diff --git a/src/detail/new-renew-revoke-encoder.hpp b/src/protocol-detail/new-renew-revoke-encoder.hpp
similarity index 89%
rename from src/detail/new-renew-revoke-encoder.hpp
rename to src/protocol-detail/new-renew-revoke-encoder.hpp
index 075114f..98e29c4 100644
--- a/src/detail/new-renew-revoke-encoder.hpp
+++ b/src/protocol-detail/new-renew-revoke-encoder.hpp
@@ -18,10 +18,10 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#ifndef NDNCERT_DETAIL_NEW_RENEW_REVOKE_ENCODER_HPP
-#define NDNCERT_DETAIL_NEW_RENEW_REVOKE_ENCODER_HPP
+#ifndef NDNCERT_PROTOCOL_DETAIL_NEW_RENEW_REVOKE_ENCODER_HPP
+#define NDNCERT_PROTOCOL_DETAIL_NEW_RENEW_REVOKE_ENCODER_HPP
 
-#include "../ca-state.hpp"
+#include "../ca-detail/ca-state.hpp"
 
 namespace ndn {
 namespace ndncert {
@@ -53,4 +53,4 @@
 } // namespace ndncert
 } // namespace ndn
 
-#endif // NDNCERT_DETAIL_NEW_RENEW_REVOKE_HPP
\ No newline at end of file
+#endif // NDNCERT_PROTOCOL_DETAIL_NEW_RENEW_REVOKE_HPP
\ No newline at end of file
diff --git a/src/detail/probe-encoder.cpp b/src/protocol-detail/probe-encoder.cpp
similarity index 100%
rename from src/detail/probe-encoder.cpp
rename to src/protocol-detail/probe-encoder.cpp
diff --git a/src/detail/probe-encoder.hpp b/src/protocol-detail/probe-encoder.hpp
similarity index 91%
rename from src/detail/probe-encoder.hpp
rename to src/protocol-detail/probe-encoder.hpp
index b56e458..c0e038e 100644
--- a/src/detail/probe-encoder.hpp
+++ b/src/protocol-detail/probe-encoder.hpp
@@ -18,8 +18,8 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#ifndef NDNCERT_DETAIL_PROBE_ENCODER_HPP
-#define NDNCERT_DETAIL_PROBE_ENCODER_HPP
+#ifndef NDNCERT_PROTOCOL_DETAIL_PROBE_ENCODER_HPP
+#define NDNCERT_PROTOCOL_DETAIL_PROBE_ENCODER_HPP
 
 #include "../configuration.hpp"
 
@@ -50,4 +50,4 @@
 } // namespace ndncert
 } // namespace ndn
 
-#endif // NDNCERT_DETAIL_PROBE_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_PROTOCOL_DETAIL_PROBE_ENCODER_HPP
\ No newline at end of file
diff --git a/src/requester-state.hpp b/src/requester-state.hpp
index 6e8be3d..8a254c6 100644
--- a/src/requester-state.hpp
+++ b/src/requester-state.hpp
@@ -21,8 +21,8 @@
 #ifndef NDNCERT_REQUESTER_STATE_HPP
 #define NDNCERT_REQUESTER_STATE_HPP
 
-#include "detail/ndncert-common.hpp"
-#include "detail/crypto-helper.hpp"
+#include "protocol-detail/ndncert-common.hpp"
+#include "protocol-detail/crypto-helper.hpp"
 #include "configuration.hpp"
 
 namespace ndn {
@@ -44,7 +44,6 @@
    * The type of request. Either NEW, RENEW, or REVOKE.
    */
   RequestType m_type;
-
   /**
    * The identity name for the requesting certificate.
    */
@@ -61,7 +60,6 @@
    * The current status of the request.
    */
   Status m_status = Status::NOT_STARTED;
-
   /**
    * The type of challenge chosen.
    */
diff --git a/src/requester.cpp b/src/requester.cpp
index 632c53d..64ce59c 100644
--- a/src/requester.cpp
+++ b/src/requester.cpp
@@ -20,12 +20,12 @@
 
 #include "requester.hpp"
 #include "identity-challenge/challenge-module.hpp"
-#include "detail/enc-tlv.hpp"
-#include "detail/challenge-encoder.hpp"
-#include "detail/error-encoder.hpp"
-#include "detail/info-encoder.hpp"
-#include "detail/new-renew-revoke-encoder.hpp"
-#include "detail/probe-encoder.hpp"
+#include "protocol-detail/crypto-helper.hpp"
+#include "protocol-detail/challenge-encoder.hpp"
+#include "protocol-detail/error-encoder.hpp"
+#include "protocol-detail/info-encoder.hpp"
+#include "protocol-detail/new-renew-revoke-encoder.hpp"
+#include "protocol-detail/probe-encoder.hpp"
 #include <ndn-cxx/security/signing-helpers.hpp>
 #include <ndn-cxx/security/transform/base64-encode.hpp>
 #include <ndn-cxx/security/transform/buffer-source.hpp>
diff --git a/src/requester.hpp b/src/requester.hpp
index 4f1bb80..0267803 100644
--- a/src/requester.hpp
+++ b/src/requester.hpp
@@ -106,8 +106,8 @@
    */
   static shared_ptr<Interest>
   genNewInterest(RequesterState& state, const Name& identityName,
-                      const time::system_clock::TimePoint& notBefore,
-                      const time::system_clock::TimePoint& notAfter);
+                 const time::system_clock::TimePoint& notBefore,
+                 const time::system_clock::TimePoint& notAfter);
 
   /**
    * Generates a REVOKE interest to the CA.
@@ -135,6 +135,7 @@
    * @p challengeSelected, The selected challenge for the request.
    *            Can use state.m_challengeType to continue.
    * @return The requirement list for the current stage of the challenge, in name, prompt mapping.
+   * @throw std::runtime_error if the challenge is not supported.
    */
   static std::vector<std::tuple<std::string, std::string>>
   selectOrContinueChallenge(RequesterState& state, const std::string& challengeSelected);
@@ -144,6 +145,7 @@
    * @p state, The requester state of the request.
    * @p parameters, The requirement list, in name, value mapping.
    * @return The shared pointer to the encoded interest
+   * @throw std::runtime_error if the challenge is not selected or is not supported.
    */
   static shared_ptr<Interest>
   genChallengeInterest(const RequesterState& state,
diff --git a/tests/unit-tests/bench.t.cpp b/tests/unit-tests/bench.t.cpp
index 1fe853b..dd23d49 100644
--- a/tests/unit-tests/bench.t.cpp
+++ b/tests/unit-tests/bench.t.cpp
@@ -20,7 +20,7 @@
 
 #include "ca-module.hpp"
 #include "identity-challenge/challenge-pin.hpp"
-#include "detail/info-encoder.hpp"
+#include "protocol-detail/info-encoder.hpp"
 #include "requester.hpp"
 #include "test-common.hpp"
 
diff --git a/tests/unit-tests/ca-module.t.cpp b/tests/unit-tests/ca-module.t.cpp
index 1dd39f4..27d417f 100644
--- a/tests/unit-tests/ca-module.t.cpp
+++ b/tests/unit-tests/ca-module.t.cpp
@@ -22,7 +22,7 @@
 #include "identity-challenge/challenge-module.hpp"
 #include "identity-challenge/challenge-email.hpp"
 #include "identity-challenge/challenge-pin.hpp"
-#include "detail/info-encoder.hpp"
+#include "protocol-detail/info-encoder.hpp"
 #include "requester.hpp"
 #include "test-common.hpp"
 
diff --git a/tests/unit-tests/configuration.t.cpp b/tests/unit-tests/configuration.t.cpp
index 7d5c901..eb9619b 100644
--- a/tests/unit-tests/configuration.t.cpp
+++ b/tests/unit-tests/configuration.t.cpp
@@ -19,7 +19,7 @@
  */
 
 #include "configuration.hpp"
-#include "detail/info-encoder.hpp"
+#include "protocol-detail/info-encoder.hpp"
 #include "test-common.hpp"
 
 namespace ndn {
diff --git a/tests/unit-tests/crypto-helper.t.cpp b/tests/unit-tests/crypto-helper.t.cpp
index 313969e..fe614cf 100644
--- a/tests/unit-tests/crypto-helper.t.cpp
+++ b/tests/unit-tests/crypto-helper.t.cpp
@@ -18,7 +18,7 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#include "detail/crypto-helper.hpp"
+#include "protocol-detail/crypto-helper.hpp"
 #include "test-common.hpp"
 
 namespace ndn {
@@ -294,6 +294,19 @@
   BOOST_CHECK(memcmp(decrypted, plaintext, sizeof(plaintext)) == 0);
 }
 
+
+BOOST_AUTO_TEST_CASE(BlockEncodingDecoding)
+{
+  const uint8_t key[] = {0xbc, 0x22, 0xf3, 0xf0, 0x5c, 0xc4, 0x0d, 0xb9,
+                         0x31, 0x1e, 0x41, 0x92, 0x96, 0x6f, 0xee, 0x92};
+  const std::string plaintext = "alongstringalongstringalongstringalongstringalongstringalongstringalongstringalongstring";
+  const std::string associatedData = "test";
+  auto block = encodeBlockWithAesGcm128(ndn::tlv::Content, key, (uint8_t*)plaintext.c_str(), plaintext.size(),
+                                        (uint8_t*)associatedData.c_str(), associatedData.size());
+  auto decoded = decodeBlockWithAesGcm128(block, key, (uint8_t*)associatedData.c_str(), associatedData.size());
+  BOOST_CHECK_EQUAL(plaintext, std::string((char*)decoded.get<uint8_t>(), decoded.size()));
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace tests
diff --git a/tests/unit-tests/enc-tlv.t.cpp b/tests/unit-tests/enc-tlv.t.cpp
deleted file mode 100644
index 314bf2b..0000000
--- a/tests/unit-tests/enc-tlv.t.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
- *
- * This file is part of ndncert, a certificate management system based on NDN.
- *
- * ndncert is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received copies of the GNU General Public License along with
- * ndncert, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndncert authors and contributors.
- */
-
-#include "detail/enc-tlv.hpp"
-#include "detail/crypto-helper.hpp"
-#include "test-common.hpp"
-
-namespace ndn {
-namespace ndncert {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(TestEncTlv)
-
-BOOST_AUTO_TEST_CASE(EncodingDecoding)
-{
-  const uint8_t key[] = {0xbc, 0x22, 0xf3, 0xf0, 0x5c, 0xc4, 0x0d, 0xb9,
-                         0x31, 0x1e, 0x41, 0x92, 0x96, 0x6f, 0xee, 0x92};
-  const std::string plaintext = "alongstringalongstringalongstringalongstringalongstringalongstringalongstringalongstring";
-  const std::string associatedData = "test";
-  auto block = encodeBlockWithAesGcm128(ndn::tlv::Content, key, (uint8_t*)plaintext.c_str(), plaintext.size(),
-                                        (uint8_t*)associatedData.c_str(), associatedData.size());
-  auto decoded = decodeBlockWithAesGcm128(block, key, (uint8_t*)associatedData.c_str(), associatedData.size());
-  BOOST_CHECK_EQUAL(plaintext, std::string((char*)decoded.get<uint8_t>(), decoded.size()));
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/protocol-detail.t.cpp b/tests/unit-tests/protocol-detail.t.cpp
index 6157d61..d022d19 100644
--- a/tests/unit-tests/protocol-detail.t.cpp
+++ b/tests/unit-tests/protocol-detail.t.cpp
@@ -18,10 +18,10 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#include "detail/info-encoder.hpp"
-#include "detail/probe-encoder.hpp"
-#include "detail/new-renew-revoke-encoder.hpp"
-#include "detail/challenge-encoder.hpp"
+#include "protocol-detail/info-encoder.hpp"
+#include "protocol-detail/probe-encoder.hpp"
+#include "protocol-detail/new-renew-revoke-encoder.hpp"
+#include "protocol-detail/challenge-encoder.hpp"
 #include "test-common.hpp"
 
 namespace ndn {
diff --git a/tests/unit-tests/requester.t.cpp b/tests/unit-tests/requester.t.cpp
index 0ab1d67..5ea7a03 100644
--- a/tests/unit-tests/requester.t.cpp
+++ b/tests/unit-tests/requester.t.cpp
@@ -19,8 +19,8 @@
  */
 
 #include "requester.hpp"
-#include "detail/error-encoder.hpp"
-#include "detail/probe-encoder.hpp"
+#include "protocol-detail/error-encoder.hpp"
+#include "protocol-detail/probe-encoder.hpp"
 #include "identity-challenge/challenge-module.hpp"
 #include "ca-module.hpp"
 #include "test-common.hpp"
diff --git a/tools/ndncert-client.cpp b/tools/ndncert-client.cpp
index 46bf35e..5c712a6 100644
--- a/tools/ndncert-client.cpp
+++ b/tools/ndncert-client.cpp
@@ -18,8 +18,6 @@
  * See AUTHORS.md for complete list of ndncert authors and contributors.
  */
 
-#include "identity-challenge/challenge-module.hpp"
-#include "detail/info-encoder.hpp"
 #include "requester.hpp"
 #include <ndn-cxx/security/verification-helpers.hpp>
 #include <boost/asio.hpp>
@@ -136,7 +134,6 @@
                          bind(&onNackCb), bind(&timeoutCb));
     return;
   }
-
   runChallenge(requesterState->m_challengeType);
 }
 
@@ -186,15 +183,8 @@
   }
   auto it = challengeList.begin();
   std::advance(it, challengeIndex);
-  unique_ptr<ChallengeModule> challenge = ChallengeModule::createChallengeModule(*it);
-  if (challenge != nullptr) {
-    std::cerr << "The challenge has been selected: " << *it << std::endl;
-    runChallenge(*it);
-  }
-  else {
-    std::cerr << "Error. Cannot load selected Challenge Module. Exit." << std::endl;
-    exit(1);
-  }
+  std::cerr << "The challenge has been selected: " << *it << std::endl;
+  runChallenge(*it);
 }
 
 static void
@@ -416,7 +406,15 @@
 static void
 runChallenge(const std::string& challengeType)
 {
-  auto requirement = Requester::selectOrContinueChallenge(*requesterState, challengeType);
+  std::vector<std::tuple<std::string, std::string>> requirement;
+  try {
+    requirement = Requester::selectOrContinueChallenge(*requesterState, challengeType);
+  }
+  catch (const std::exception& e) {
+    std::cerr << "Error. Cannot successfully load the Challenge Module with error: " << std::string(e.what())
+              << "Exit." << std::endl;
+    exit(1);
+  }
   if (requirement.size() > 0) {
     std::cerr << "\n***************************************\n"
               << "Step " << nStep