commons clean up

Change-Id: I13ce15666974e294d2645768dd20194f0584d406
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 821372b..5481b2b 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -357,11 +357,11 @@
                                        "No parameters are found after decryption."));
     return;
   }
-  Block paramTLV = makeBinaryBlock(tlv_encrypted_payload, paramTLVPayload.data(), paramTLVPayload.size());
+  Block paramTLV = makeBinaryBlock(tlv::EncryptedPayload, paramTLVPayload.data(), paramTLVPayload.size());
   paramTLV.parse();
 
   // load the corresponding challenge module
-  std::string challengeType = readString(paramTLV.get(tlv_selected_challenge));
+  std::string challengeType = readString(paramTLV.get(tlv::SelectedChallenge));
   auto challenge = ChallengeModule::createChallengeModule(challengeType);
   if (challenge == nullptr) {
     NDN_LOG_TRACE("Unrecognized challenge type: " << challengeType);
@@ -389,7 +389,7 @@
 
       payload = CHALLENGE::encodeDataContent(requestState);
       payload.parse();
-      payload.push_back(makeNestedBlock(tlv_issued_cert_name, issuedCert.getName()));
+      payload.push_back(makeNestedBlock(tlv::IssuedCertName, issuedCert.getName()));
       payload.encode();
       NDN_LOG_TRACE("Challenge succeeded. Certificate has been issued: " << issuedCert.getName());
     }
diff --git a/src/ca-state.hpp b/src/ca-state.hpp
index fefc0ff..4c99185 100644
--- a/src/ca-state.hpp
+++ b/src/ca-state.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_CA_STATE_HPP
 #define NDNCERT_CA_STATE_HPP
 
-#include "ndncert-common.hpp"
+#include "protocol-detail/ndncert-common.hpp"
 
 namespace ndn {
 namespace ndncert {
diff --git a/src/identity-challenge/challenge-credential.cpp b/src/identity-challenge/challenge-credential.cpp
index b8e493f..3ad014a 100644
--- a/src/identity-challenge/challenge-credential.cpp
+++ b/src/identity-challenge/challenge-credential.cpp
@@ -87,7 +87,7 @@
   size_t signatureLen;
   const auto& elements = params.elements();
   for (size_t i = 0; i < elements.size(); i++) {
-    if (elements[i].type() == tlv_parameter_key) {
+    if (elements[i].type() == tlv::ParameterKey) {
       if (readString(elements[i]) == PARAMETER_KEY_CREDENTIAL_CERT) {
         try {
           credential.wireDecode(elements[i + 1].blockFromValue());
@@ -139,24 +139,24 @@
 ChallengeCredential::genChallengeRequestTLV(Status status, const std::string& challengeStatus,
                                             std::vector<std::tuple<std::string, std::string>>&& params)
 {
-  Block request = makeEmptyBlock(tlv_encrypted_payload);
+  Block request = makeEmptyBlock(tlv::EncryptedPayload);
   if (status == Status::BEFORE_CHALLENGE) {
     if (params.size() != 2) {
       NDN_THROW(std::runtime_error("Wrong parameter provided."));
     }
-    request.push_back(makeStringBlock(tlv_selected_challenge, CHALLENGE_TYPE));
+    request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
     for (const auto& item : params) {
       if (std::get<0>(item) == PARAMETER_KEY_CREDENTIAL_CERT) {
-        request.push_back(makeStringBlock(tlv_parameter_key, PARAMETER_KEY_CREDENTIAL_CERT));
-        Block valueBlock = makeEmptyBlock(tlv_parameter_value);
+        request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CREDENTIAL_CERT));
+        Block valueBlock = makeEmptyBlock(tlv::ParameterValue);
         auto& certTlvStr = std::get<1>(item);
         valueBlock.push_back(Block((uint8_t*)certTlvStr.c_str(), certTlvStr.size()));
         request.push_back(valueBlock);
       }
       else if (std::get<0>(item) == PARAMETER_KEY_PROOF_OF_PRIVATE_KEY) {
-        request.push_back(makeStringBlock(tlv_parameter_key, PARAMETER_KEY_PROOF_OF_PRIVATE_KEY));
+        request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_PROOF_OF_PRIVATE_KEY));
         auto& sigTlvStr = std::get<1>(item);
-        Block valueBlock = makeBinaryBlock(tlv_parameter_value, (uint8_t*)sigTlvStr.c_str(), sigTlvStr.size());
+        Block valueBlock = makeBinaryBlock(tlv::ParameterValue, (uint8_t*)sigTlvStr.c_str(), sigTlvStr.size());
         request.push_back(valueBlock);
       }
       else {
diff --git a/src/identity-challenge/challenge-email.cpp b/src/identity-challenge/challenge-email.cpp
index f08025b..0c65c69 100644
--- a/src/identity-challenge/challenge-email.cpp
+++ b/src/identity-challenge/challenge-email.cpp
@@ -49,7 +49,7 @@
   auto currentTime = time::system_clock::now();
   if (request.m_status == Status::BEFORE_CHALLENGE) {
     // for the first time, init the challenge
-    std::string emailAddress = readString(params.get(tlv_parameter_value));
+    std::string emailAddress = readString(params.get(tlv::ParameterValue));
     if (!isValidEmailAddress(emailAddress)) {
       return returnWithNewChallengeStatus(request, INVALID_EMAIL, JsonSection(), m_maxAttemptTimes - 1, m_secretLifetime);
     }
@@ -70,7 +70,7 @@
         request.m_challengeState->m_challengeStatus == WRONG_CODE) {
       NDN_LOG_TRACE("Challenge Interest arrives. Challenge Status: " << request.m_challengeState->m_challengeStatus);
       // the incoming interest should bring the pin code
-      std::string givenCode = readString(params.get(tlv_parameter_value));
+      std::string givenCode = readString(params.get(tlv::ParameterValue));
       auto secret = request.m_challengeState->m_secrets;
       // check if run out of time
       if (currentTime - request.m_challengeState->m_timestamp >= m_secretLifetime) {
@@ -123,22 +123,22 @@
 Block
 ChallengeEmail::genChallengeRequestTLV(Status status, const std::string& challengeStatus, std::vector<std::tuple<std::string, std::string>>&& params)
 {
-  Block request = makeEmptyBlock(tlv_encrypted_payload);
+  Block request = makeEmptyBlock(tlv::EncryptedPayload);
   if (status == Status::BEFORE_CHALLENGE) {
     if (params.size() != 1 || std::get<0>(params[0]) != PARAMETER_KEY_EMAIL) {
       NDN_THROW(std::runtime_error("Wrong parameter provided."));
     }
-    request.push_back(makeStringBlock(tlv_selected_challenge, CHALLENGE_TYPE));
-    request.push_back(makeStringBlock(tlv_parameter_key, PARAMETER_KEY_EMAIL));
-    request.push_back(makeStringBlock(tlv_parameter_value, std::get<1>(params[0])));
+    request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+    request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_EMAIL));
+    request.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(params[0])));
   }
   else if (status == Status::CHALLENGE && (challengeStatus == NEED_CODE || challengeStatus == WRONG_CODE)) {
     if (params.size() != 1 || std::get<0>(params[0]) != PARAMETER_KEY_CODE) {
       NDN_THROW(std::runtime_error("Wrong parameter provided."));
     }
-    request.push_back(makeStringBlock(tlv_selected_challenge, CHALLENGE_TYPE));
-    request.push_back(makeStringBlock(tlv_parameter_key, PARAMETER_KEY_CODE));
-    request.push_back(makeStringBlock(tlv_parameter_value, std::get<1>(params[0])));
+    request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+    request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
+    request.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(params[0])));
   }
   else {
     NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
diff --git a/src/identity-challenge/challenge-pin.cpp b/src/identity-challenge/challenge-pin.cpp
index 04bd153..fe17cd1 100644
--- a/src/identity-challenge/challenge-pin.cpp
+++ b/src/identity-challenge/challenge-pin.cpp
@@ -56,7 +56,7 @@
         request.m_challengeState->m_challengeStatus == WRONG_CODE) {
       NDN_LOG_TRACE("Challenge Interest arrives. Challenge Status: " << request.m_challengeState->m_challengeStatus);
       // the incoming interest should bring the pin code
-      std::string givenCode = readString(params.get(tlv_parameter_value));
+      std::string givenCode = readString(params.get(tlv::ParameterValue));
       auto secret = request.m_challengeState->m_secrets;
       if (currentTime - request.m_challengeState->m_timestamp >= m_secretLifetime) {
         return returnWithError(request, ErrorCode::OUT_OF_TIME, "Secret expired.");
@@ -106,17 +106,17 @@
 Block
 ChallengePin::genChallengeRequestTLV(Status status, const std::string& challengeStatus, std::vector<std::tuple<std::string, std::string>>&& params)
 {
-  Block request = makeEmptyBlock(tlv_encrypted_payload);
+  Block request = makeEmptyBlock(tlv::EncryptedPayload);
   if (status == Status::BEFORE_CHALLENGE) {
-    request.push_back(makeStringBlock(tlv_selected_challenge, CHALLENGE_TYPE));
+    request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
   }
   else if (status == Status::CHALLENGE && (challengeStatus == NEED_CODE || challengeStatus == WRONG_CODE)) {
     if (params.size() != 1 || std::get<0>(params[0]) != PARAMETER_KEY_CODE) {
       NDN_THROW(std::runtime_error("Wrong parameter provided."));
     }
-    request.push_back(makeStringBlock(tlv_selected_challenge, CHALLENGE_TYPE));
-    request.push_back(makeStringBlock(tlv_parameter_key, PARAMETER_KEY_CODE));
-    request.push_back(makeStringBlock(tlv_parameter_value, std::get<1>(params[0])));
+    request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+    request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
+    request.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(params[0])));
   }
   else {
     NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
diff --git a/src/protocol-detail/challenge.cpp b/src/protocol-detail/challenge.cpp
index 3504115..d49ca4e 100644
--- a/src/protocol-detail/challenge.cpp
+++ b/src/protocol-detail/challenge.cpp
@@ -26,14 +26,14 @@
 Block
 CHALLENGE::encodeDataContent(const CaState& request)
 {
-  Block response = makeEmptyBlock(tlv_encrypted_payload);
-  response.push_back(makeNonNegativeIntegerBlock(tlv_status, static_cast<size_t>(request.m_status)));
+  Block response = makeEmptyBlock(tlv::EncryptedPayload);
+  response.push_back(makeNonNegativeIntegerBlock(tlv::Status, static_cast<size_t>(request.m_status)));
   if (request.m_challengeState) {
-    response.push_back(makeStringBlock(tlv_challenge_status, request.m_challengeState->m_challengeStatus));
+    response.push_back(makeStringBlock(tlv::ChallengeStatus, request.m_challengeState->m_challengeStatus));
     response.push_back(
-        makeNonNegativeIntegerBlock(tlv_remaining_tries, request.m_challengeState->m_remainingTries));
+        makeNonNegativeIntegerBlock(tlv::RemainingTries, request.m_challengeState->m_remainingTries));
     response.push_back(
-        makeNonNegativeIntegerBlock(tlv_remaining_time, request.m_challengeState->m_remainingTime.count()));
+        makeNonNegativeIntegerBlock(tlv::RemainingTime, request.m_challengeState->m_remainingTime.count()));
   }
   response.encode();
   return response;
@@ -43,18 +43,18 @@
 CHALLENGE::decodeDataContent(const Block& data, RequesterState& state)
 {
   data.parse();
-  state.m_status = static_cast<Status>(readNonNegativeInteger(data.get(tlv_status)));
-  if (data.find(tlv_challenge_status) != data.elements_end()) {
-    state.m_challengeStatus = readString(data.get(tlv_challenge_status));
+  state.m_status = static_cast<Status>(readNonNegativeInteger(data.get(tlv::Status)));
+  if (data.find(tlv::ChallengeStatus) != data.elements_end()) {
+    state.m_challengeStatus = readString(data.get(tlv::ChallengeStatus));
   }
-  if (data.find(tlv_remaining_tries) != data.elements_end()) {
-    state.m_remainingTries = readNonNegativeInteger(data.get(tlv_remaining_tries));
+  if (data.find(tlv::RemainingTries) != data.elements_end()) {
+    state.m_remainingTries = readNonNegativeInteger(data.get(tlv::RemainingTries));
   }
-  if (data.find(tlv_remaining_time) != data.elements_end()) {
-    state.m_freshBefore = time::system_clock::now() + time::seconds(readNonNegativeInteger(data.get(tlv_remaining_time)));
+  if (data.find(tlv::RemainingTime) != data.elements_end()) {
+    state.m_freshBefore = time::system_clock::now() + time::seconds(readNonNegativeInteger(data.get(tlv::RemainingTime)));
   }
-  if (data.find(tlv_issued_cert_name) != data.elements_end()) {
-    Block issuedCertNameBlock = data.get(tlv_issued_cert_name);
+  if (data.find(tlv::IssuedCertName) != data.elements_end()) {
+    Block issuedCertNameBlock = data.get(tlv::IssuedCertName);
     state.m_issuedCertName = Name(issuedCertNameBlock.blockFromValue());
   }
 }
diff --git a/src/protocol-detail/crypto-helper.hpp b/src/protocol-detail/crypto-helper.hpp
index baa2e66..a590bfa 100644
--- a/src/protocol-detail/crypto-helper.hpp
+++ b/src/protocol-detail/crypto-helper.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_CRYPTO_SUPPORT_CRYPTO_HELPER_HPP
 #define NDNCERT_CRYPTO_SUPPORT_CRYPTO_HELPER_HPP
 
-#include "../ndncert-common.hpp"
+#include "ndncert-common.hpp"
 
 namespace ndn {
 namespace ndncert {
diff --git a/src/protocol-detail/enc-tlv.cpp b/src/protocol-detail/enc-tlv.cpp
index b19bfcc..8342300 100644
--- a/src/protocol-detail/enc-tlv.cpp
+++ b/src/protocol-detail/enc-tlv.cpp
@@ -42,9 +42,9 @@
   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_initialization_vector, iv.data(), iv.size()));
-  content.push_back(makeBinaryBlock(tlv_authentication_tag, tag, 16));
-  content.push_back(makeBinaryBlock(tlv_encrypted_payload, encryptedPayload, encryptedPayloadLen));
+  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;
@@ -55,12 +55,12 @@
 {
   block.parse();
   Buffer result;
-  result.resize(block.get(tlv_encrypted_payload).value_size());
-  int resultLen = aes_gcm_128_decrypt(block.get(tlv_encrypted_payload).value(),
-                                      block.get(tlv_encrypted_payload).value_size(),
-                                      associatedData, associatedDataSize, block.get(tlv_authentication_tag).value(),
-                                      key, block.get(tlv_initialization_vector).value(), result.data());
-  if (resultLen == -1 || resultLen != (int)block.get(tlv_encrypted_payload).value_size()) {
+  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;
diff --git a/src/protocol-detail/enc-tlv.hpp b/src/protocol-detail/enc-tlv.hpp
index 9e207c0..1c55119 100644
--- a/src/protocol-detail/enc-tlv.hpp
+++ b/src/protocol-detail/enc-tlv.hpp
@@ -21,20 +21,20 @@
 #ifndef NDNCERT_CRYPTO_SUPPORT_ENC_TLV_HPP
 #define NDNCERT_CRYPTO_SUPPORT_ENC_TLV_HPP
 
-#include "../ndncert-common.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 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
+ * @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,
diff --git a/src/protocol-detail/error.cpp b/src/protocol-detail/error.cpp
index 79dc535..266e4e6 100644
--- a/src/protocol-detail/error.cpp
+++ b/src/protocol-detail/error.cpp
@@ -27,8 +27,8 @@
 ErrorTLV::encodeDataContent(ErrorCode errorCode, const std::string& description)
 {
   Block response = makeEmptyBlock(tlv::Content);
-  response.push_back(makeNonNegativeIntegerBlock(tlv_error_code, static_cast<size_t>(errorCode)));
-  response.push_back(makeStringBlock(tlv_error_info, description));
+  response.push_back(makeNonNegativeIntegerBlock(tlv::ErrorCode, static_cast<size_t>(errorCode)));
+  response.push_back(makeStringBlock(tlv::ErrorInfo, description));
   response.encode();
   return response;
 }
@@ -37,11 +37,11 @@
 ErrorTLV::decodefromDataContent(const Block& block)
 {
   block.parse();
-  if (block.find(tlv_error_code) == block.elements_end()) {
+  if (block.find(tlv::ErrorCode) == block.elements_end()) {
     return std::make_tuple(ErrorCode::NO_ERROR, "");
   }
-  ErrorCode error = static_cast<ErrorCode>(readNonNegativeInteger(block.get(tlv_error_code)));
-  return std::make_tuple(error, readString(block.get(tlv_error_info)));
+  ErrorCode error = static_cast<ErrorCode>(readNonNegativeInteger(block.get(tlv::ErrorCode)));
+  return std::make_tuple(error, readString(block.get(tlv::ErrorInfo)));
 }
 
 } // namespace ndncert
diff --git a/src/protocol-detail/info.cpp b/src/protocol-detail/info.cpp
index 08a6997..beef51d 100644
--- a/src/protocol-detail/info.cpp
+++ b/src/protocol-detail/info.cpp
@@ -27,7 +27,7 @@
 INFO::encodeDataContent(const CaProfile& caConfig, const security::Certificate& certificate)
 {
   auto content = makeEmptyBlock(tlv::Content);
-  content.push_back(makeNestedBlock(tlv_ca_prefix, caConfig.m_caPrefix));
+  content.push_back(makeNestedBlock(tlv::CaPrefix, caConfig.m_caPrefix));
   std::string caInfo = "";
   if (caConfig.m_caInfo == "") {
     caInfo = "Issued by " + certificate.getSignatureInfo().getKeyLocator().getName().toUri();
@@ -35,12 +35,12 @@
   else {
     caInfo = caConfig.m_caInfo;
   }
-  content.push_back(makeStringBlock(tlv_ca_info, caInfo));
+  content.push_back(makeStringBlock(tlv::CaInfo, caInfo));
   for (const auto& key : caConfig.m_probeParameterKeys) {
-    content.push_back(makeStringBlock(tlv_parameter_key, key));
+    content.push_back(makeStringBlock(tlv::ParameterKey, key));
   }
-  content.push_back(makeNonNegativeIntegerBlock(tlv_max_validity_period, caConfig.m_maxValidityPeriod.count()));
-  content.push_back(makeNestedBlock(tlv_ca_certificate, certificate));
+  content.push_back(makeNonNegativeIntegerBlock(tlv::MaxValidityPeriod, caConfig.m_maxValidityPeriod.count()));
+  content.push_back(makeNestedBlock(tlv::CaCertificate, certificate));
   content.encode();
   return content;
 }
@@ -52,20 +52,20 @@
   block.parse();
   for (auto const& item : block.elements()) {
     switch (item.type()) {
-    case tlv_ca_prefix:
+    case tlv::CaPrefix:
       item.parse();
       result.m_caPrefix.wireDecode(item.get(tlv::Name));
       break;
-    case tlv_ca_info:
+    case tlv::CaInfo:
       result.m_caInfo = readString(item);
       break;
-    case tlv_parameter_key:
+    case tlv::ParameterKey:
       result.m_probeParameterKeys.push_back(readString(item));
       break;
-    case tlv_max_validity_period:
+    case tlv::MaxValidityPeriod:
       result.m_maxValidityPeriod = time::seconds(readNonNegativeInteger(item));
       break;
-    case tlv_ca_certificate:
+    case tlv::CaCertificate:
       item.parse();
       result.m_cert = std::make_shared<security::Certificate>(item.get(tlv::Data));
       break;
diff --git a/src/ndncert-common.cpp b/src/protocol-detail/ndncert-common.cpp
similarity index 84%
rename from src/ndncert-common.cpp
rename to src/protocol-detail/ndncert-common.cpp
index 5f3adbe..1915082 100644
--- a/src/ndncert-common.cpp
+++ b/src/protocol-detail/ndncert-common.cpp
@@ -23,7 +23,7 @@
 namespace ndn {
 namespace ndncert {
 
-std::map<ErrorCode, std::string> errorCodeText = {
+const std::map<ErrorCode, std::string> errorCodeText = {
   {ErrorCode::NO_ERROR,             "NO_ERROR"},
   {ErrorCode::BAD_INTEREST_FORMAT,  "BAD_INTEREST_FORMAT"},
   {ErrorCode::BAD_PARAMETER_FORMAT, "BAD_PARAMETER_FORMAT"},
@@ -36,6 +36,13 @@
   {ErrorCode::NO_AVAILABLE_NAMES,   "NO_AVAILABLE_NAMES"}
 };
 
+const std::map<RequestType, std::string> requestTypeText = {
+  {RequestType::NEW, "New"},
+  {RequestType::RENEW, "Renew"},
+  {RequestType::REVOKE, "Revoke"},
+  {RequestType::NOTINITIALIZED, "Not Initialized"},
+};
+
 std::string errorCodeToString(ErrorCode code)
 {
   return errorCodeText.at(code);
@@ -43,19 +50,7 @@
 
 std::string requestTypeToString(RequestType type)
 {
-  switch (type)
-  {
-  case RequestType::NEW:
-    return "New";
-  case RequestType::RENEW:
-    return "Renew";
-  case RequestType::REVOKE:
-    return "Revoke";
-  case RequestType::NOTINITIALIZED:
-    return "Not initalized";
-  default:
-    return "Unrecognized type";
-  }
+  return requestTypeText.at(type);
 }
 
 } // namespace ndncert
diff --git a/src/ndncert-common.hpp b/src/protocol-detail/ndncert-common.hpp
similarity index 79%
rename from src/ndncert-common.hpp
rename to src/protocol-detail/ndncert-common.hpp
index cb8cd5b..cf19bb9 100644
--- a/src/ndncert-common.hpp
+++ b/src/protocol-detail/ndncert-common.hpp
@@ -58,40 +58,41 @@
 #include <boost/property_tree/ptree.hpp>
 
 namespace ndn {
+namespace tlv {
+  enum : uint32_t {
+    CaPrefix = 129,
+    CaInfo = 131,
+    ParameterKey = 133,
+    ParameterValue = 135,
+    CaCertificate = 137,
+    MaxValidityPeriod = 139,
+    ProbeResponse = 141,
+    MaxSuffixLength = 143,
+    EcdhPub = 145,
+    CertRequest = 147,
+    Salt = 149,
+    RequestId = 151,
+    Challenge = 153,
+    Status = 155,
+    InitializationVector = 157,
+    EncryptedPayload = 159,
+    SelectedChallenge = 161,
+    ChallengeStatus = 163,
+    RemainingTries = 165,
+    RemainingTime = 167,
+    IssuedCertName = 169,
+    ErrorCode = 171,
+    ErrorInfo = 173,
+    AuthenticationTag = 175,
+    CertToRevoke = 177,
+    ProbeRedirect = 179
+ };
+} // namespace tlv
 namespace ndncert {
 
 using boost::noncopyable;
 typedef boost::property_tree::ptree JsonSection;
 
-enum : uint32_t {
-  tlv_ca_prefix = 129,
-  tlv_ca_info = 131,
-  tlv_parameter_key = 133,
-  tlv_parameter_value = 135,
-  tlv_ca_certificate = 137,
-  tlv_max_validity_period = 139,
-  tlv_probe_response = 141,
-  tlv_max_suffix_length = 143,
-  tlv_ecdh_pub = 145,
-  tlv_cert_request = 147,
-  tlv_salt = 149,
-  tlv_request_id = 151,
-  tlv_challenge = 153,
-  tlv_status = 155,
-  tlv_initialization_vector = 157,
-  tlv_encrypted_payload = 159,
-  tlv_selected_challenge = 161,
-  tlv_challenge_status = 163,
-  tlv_remaining_tries = 165,
-  tlv_remaining_time = 167,
-  tlv_issued_cert_name = 169,
-  tlv_error_code = 171,
-  tlv_error_info = 173,
-  tlv_authentication_tag = 175,
-  tlv_cert_to_revoke = 177,
-  tlv_probe_redirect = 179
-};
-
 // NDNCERT error code
 enum class ErrorCode : uint16_t {
   NO_ERROR = 0,
diff --git a/src/protocol-detail/new-renew-revoke.cpp b/src/protocol-detail/new-renew-revoke.cpp
index 75ffab7..8c2921e 100644
--- a/src/protocol-detail/new-renew-revoke.cpp
+++ b/src/protocol-detail/new-renew-revoke.cpp
@@ -19,7 +19,7 @@
  */
 
 #include "new-renew-revoke.hpp"
-#include "../ndncert-common.hpp"
+#include "ndncert-common.hpp"
 #include <ndn-cxx/security/transform/base64-encode.hpp>
 #include <ndn-cxx/security/transform/buffer-source.hpp>
 #include <ndn-cxx/security/transform/stream-sink.hpp>
@@ -45,11 +45,11 @@
     return request;
   }
 
-  request.push_back(makeStringBlock(tlv_ecdh_pub, ecdhPub));
+  request.push_back(makeStringBlock(tlv::EcdhPub, ecdhPub));
   if (requestType == RequestType::NEW || requestType == RequestType::RENEW) {
-    request.push_back(makeNestedBlock(tlv_cert_request, certRequest));
+    request.push_back(makeNestedBlock(tlv::CertRequest, certRequest));
   } else if (requestType == RequestType::REVOKE) {
-    request.push_back(makeNestedBlock(tlv_cert_to_revoke, certRequest));
+    request.push_back(makeNestedBlock(tlv::CertToRevoke, certRequest));
   }
   request.encode();
   return request;
@@ -60,13 +60,13 @@
                                               shared_ptr<security::Certificate>& clientCert) {
   payload.parse();
 
-  ecdhPub = readString(payload.get(tlv_ecdh_pub));
+  ecdhPub = readString(payload.get(tlv::EcdhPub));
   Block requestPayload;
   if (requestType == RequestType::NEW) {
-    requestPayload = payload.get(tlv_cert_request);
+    requestPayload = payload.get(tlv::CertRequest);
   }
   else if (requestType == RequestType::REVOKE) {
-    requestPayload = payload.get(tlv_cert_to_revoke);
+    requestPayload = payload.get(tlv::CertToRevoke);
   }
   requestPayload.parse();
 
@@ -80,12 +80,12 @@
                                     const std::list<std::string>& challenges)
 {
   Block response = makeEmptyBlock(tlv::Content);
-  response.push_back(makeStringBlock(tlv_ecdh_pub, ecdhKey));
-  response.push_back(makeStringBlock(tlv_salt, salt));
-  response.push_back(makeStringBlock(tlv_request_id, request.m_requestId));
-  response.push_back(makeNonNegativeIntegerBlock(tlv_status, static_cast<size_t>(request.m_status)));
+  response.push_back(makeStringBlock(tlv::EcdhPub, ecdhKey));
+  response.push_back(makeStringBlock(tlv::Salt, salt));
+  response.push_back(makeStringBlock(tlv::RequestId, request.m_requestId));
+  response.push_back(makeNonNegativeIntegerBlock(tlv::Status, static_cast<size_t>(request.m_status)));
   for (const auto& entry: challenges) {
-    response.push_back(makeStringBlock(tlv_challenge, entry));
+    response.push_back(makeStringBlock(tlv::Challenge, entry));
   }
   response.encode();
   return response;
@@ -95,14 +95,14 @@
 NEW_RENEW_REVOKE::decodeDataContent(const Block& content)
 {
   content.parse();
-  const auto& ecdhKey = readString(content.get(tlv_ecdh_pub));
-  const auto& salt = readString(content.get(tlv_salt));
+  const auto& ecdhKey = readString(content.get(tlv::EcdhPub));
+  const auto& salt = readString(content.get(tlv::Salt));
   uint64_t saltInt = std::stoull(salt);
-  const auto& requestStatus = static_cast<Status>(readNonNegativeInteger(content.get(tlv_status)));
-  const auto& requestId = readString(content.get(tlv_request_id));
+  const auto& requestStatus = static_cast<Status>(readNonNegativeInteger(content.get(tlv::Status)));
+  const auto& requestId = readString(content.get(tlv::RequestId));
   std::list<std::string> challenges;
   for (auto const& element : content.elements()) {
-    if (element.type() == tlv_challenge) {
+    if (element.type() == tlv::Challenge) {
       challenges.push_back(readString(element));
     }
   }
diff --git a/src/protocol-detail/probe.cpp b/src/protocol-detail/probe.cpp
index 04b4bc9..3426145 100644
--- a/src/protocol-detail/probe.cpp
+++ b/src/protocol-detail/probe.cpp
@@ -28,8 +28,8 @@
 {
   auto content = makeEmptyBlock(tlv::ApplicationParameters);
   for (size_t i = 0; i < parameters.size(); ++i) {
-    content.push_back(makeStringBlock(tlv_parameter_key, std::get<0>(parameters[i])));
-    content.push_back(makeStringBlock(tlv_parameter_value, std::get<1>(parameters[i])));
+    content.push_back(makeStringBlock(tlv::ParameterKey, std::get<0>(parameters[i])));
+    content.push_back(makeStringBlock(tlv::ParameterValue, std::get<1>(parameters[i])));
   }
   content.encode();
   return content;
@@ -41,7 +41,7 @@
   std::vector<std::tuple<std::string, std::string>> result;
   block.parse();
   for (size_t i = 0; i < block.elements().size() - 1; ++i) {
-    if (block.elements().at(i).type() == tlv_parameter_key && block.elements().at(i + 1).type() == tlv_parameter_value) {
+    if (block.elements().at(i).type() == tlv::ParameterKey && block.elements().at(i + 1).type() == tlv::ParameterValue) {
       result.push_back(std::make_tuple(readString(block.elements().at(i)), readString(block.elements().at(i + 1))));
     }
   }
@@ -54,16 +54,16 @@
 {
   Block content = makeEmptyBlock(tlv::Content);
   for (const auto& name : identifiers) {
-    Block item(tlv_probe_response);
+    Block item(tlv::ProbeResponse);
     item.push_back(name.wireEncode());
     if (maxSuffixLength) {
-      item.push_back(makeNonNegativeIntegerBlock(tlv_max_suffix_length, *maxSuffixLength));
+      item.push_back(makeNonNegativeIntegerBlock(tlv::MaxSuffixLength, *maxSuffixLength));
     }
     content.push_back(item);
   }
   if (redirectionItems) {
     for (const auto& item : *redirectionItems) {
-      content.push_back(makeNestedBlock(tlv_probe_redirect, item->getFullName()));
+      content.push_back(makeNestedBlock(tlv::ProbeRedirect, item->getFullName()));
     }
   }
   content.encode();
@@ -77,7 +77,7 @@
 {
   block.parse();
   for (const auto& item : block.elements()) {
-    if (item.type() == tlv_probe_response) {
+    if (item.type() == tlv::ProbeResponse) {
       item.parse();
       Name elementName;
       int maxSuffixLength = 0;
@@ -87,7 +87,7 @@
                   NDN_THROW(std::runtime_error("Invalid probe format"));
               }
               elementName.wireDecode(subBlock);
-          } else if (subBlock.type() == tlv_max_suffix_length) {
+          } else if (subBlock.type() == tlv::MaxSuffixLength) {
               maxSuffixLength = readNonNegativeInteger(subBlock);
           }
       }
@@ -96,7 +96,7 @@
       }
       availableNames.emplace_back(elementName, maxSuffixLength);
     }
-    if (item.type() == tlv_probe_redirect) {
+    if (item.type() == tlv::ProbeRedirect) {
       availableRedirection.emplace_back(Name(item.blockFromValue()));
     }
   }
diff --git a/src/requester-state.hpp b/src/requester-state.hpp
index f027863..f77b591 100644
--- a/src/requester-state.hpp
+++ b/src/requester-state.hpp
@@ -21,7 +21,7 @@
 #ifndef NDNCERT_REQUESTER_STATE_HPP
 #define NDNCERT_REQUESTER_STATE_HPP
 
-#include "ndncert-common.hpp"
+#include "protocol-detail/ndncert-common.hpp"
 #include "protocol-detail/crypto-helper.hpp"
 #include "configuration.hpp"
 
diff --git a/src/requester.cpp b/src/requester.cpp
index 358126e..1f67f97 100644
--- a/src/requester.cpp
+++ b/src/requester.cpp
@@ -259,7 +259,7 @@
   }
   processIfError(reply);
   auto result = decodeBlockWithAesGcm128(reply.getContent(), state.m_aesKey, (const uint8_t*)"test", strlen("test"));
-  Block contentTLV = makeBinaryBlock(tlv_encrypted_payload, result.data(), result.size());
+  Block contentTLV = makeBinaryBlock(tlv::EncryptedPayload, result.data(), result.size());
   CHALLENGE::decodeDataContent(contentTLV, state);
 }