address comments

Change-Id: Id12b605453752cf947c81b6cdda582d93a4d2bcf
diff --git a/src/detail/ca-request-state.cpp b/src/detail/ca-request-state.cpp
index 55b5cf9..739d717 100644
--- a/src/detail/ca-request-state.cpp
+++ b/src/detail/ca-request-state.cpp
@@ -66,35 +66,6 @@
 {
 }
 
-RequestState::RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status,
-                           const security::Certificate& cert, std::array<uint8_t, 16>&& encryptionKey, uint32_t aesBlockCounter)
-    : caPrefix(caName)
-    , requestId(requestId)
-    , requestType(requestType)
-    , status(status)
-    , cert(cert)
-    , encryptionKey(std::move(encryptionKey))
-    , aesBlockCounter(aesBlockCounter)
-{
-}
-
-RequestState::RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status,
-                           const security::Certificate& cert, const std::string& challengeType,
-                           const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
-                           size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
-                           std::array<uint8_t, 16>&& encryptionKey, uint32_t aesBlockCounter)
-    : caPrefix(caName)
-    , requestId(requestId)
-    , requestType(requestType)
-    , status(status)
-    , cert(cert)
-    , encryptionKey(std::move(encryptionKey))
-    , aesBlockCounter(aesBlockCounter)
-    , challengeType(challengeType)
-    , challengeState(ChallengeState(challengeStatus, challengeTp, remainingTries, remainingTime, std::move(challengeSecrets)))
-{
-}
-
 std::ostream&
 operator<<(std::ostream& os, const RequestState& request)
 {
diff --git a/src/detail/ca-request-state.hpp b/src/detail/ca-request-state.hpp
index 1857509..120a283 100644
--- a/src/detail/ca-request-state.hpp
+++ b/src/detail/ca-request-state.hpp
@@ -86,24 +86,8 @@
  *
  * ChallengeModule should take use of RequestState.ChallengeState to keep the challenge state.
  */
-class RequestState
+struct RequestState
 {
-public:
-  /**
-   * @brief Used to instantiate a RequestState when challenge is not started.
-   */
-  RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status,
-               const security::Certificate& cert, std::array<uint8_t, 16>&& m_encryptionKey, uint32_t aesBlockCounter = 0);
-  /**
-   * @brief Used to instantiate a RequestState after challenge is started.
-   */
-  RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status,
-               const security::Certificate& cert, const std::string& challengeType,
-               const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
-               size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
-               std::array<uint8_t, 16>&& m_encryptionKey, uint32_t aesBlockCounter);
-
-public:
   /**
    * @brief The CA that the request is under.
    */
@@ -119,7 +103,7 @@
   /**
    * @brief The status of the request.
    */
-  Status status;
+  Status status = Status::BEFORE_CHALLENGE;
   /**
    * @brief The self-signed certificate in the request.
    */
diff --git a/src/detail/ca-sqlite.cpp b/src/detail/ca-sqlite.cpp
index db37397..05a4c80 100644
--- a/src/detail/ca-sqlite.cpp
+++ b/src/detail/ca-sqlite.cpp
@@ -135,31 +135,25 @@
   statement.bind(1, requestId.data(), requestId.size(), SQLITE_TRANSIENT);
 
   if (statement.step() == SQLITE_ROW) {
-    Name caName(statement.getBlock(1));
-    auto status = static_cast<Status>(statement.getInt(2));
-    auto challengeStatus = statement.getString(3);
-    security::Certificate cert(statement.getBlock(4));
-    auto challengeType = statement.getString(5);
-    auto challengeSecrets = statement.getString(6);
-    auto challengeTp = statement.getString(7);
-    auto remainingTries = statement.getInt(8);
-    auto remainingTime = statement.getInt(9);
-    auto requestType = static_cast<RequestType>(statement.getInt(10));
-    std::array<uint8_t, 16> encryptionKey;
-    std::memcpy(encryptionKey.data(), statement.getBlob(11), statement.getSize(11));
-    auto aesCounter = statement.getInt(12);
-    if (challengeType != "") {
-      return RequestState(caName, requestId, requestType, status, cert,
-                          challengeType, challengeStatus, time::fromIsoString(challengeTp),
-                          remainingTries, time::seconds(remainingTime),
-                          convertString2Json(challengeSecrets), std::move(encryptionKey), aesCounter);
+    RequestState state;
+    state.caPrefix = Name(statement.getBlock(1));
+    state.status = static_cast<Status>(statement.getInt(2));
+    state.cert = security::Certificate(statement.getBlock(4));
+    state.challengeType = statement.getString(5);
+    state.requestType = static_cast<RequestType>(statement.getInt(10));
+    std::memcpy(state.encryptionKey.data(), statement.getBlob(11), statement.getSize(11));
+    state.aesBlockCounter = statement.getInt(12);
+    if (state.challengeType != "") {
+      ChallengeState challengeState(statement.getString(3), time::fromIsoString(statement.getString(7)),
+                                    statement.getInt(8), time::seconds(statement.getInt(9)),
+                                    convertString2Json(statement.getString(6)));
+      state.challengeState = challengeState;
     }
-    else {
-      return RequestState(caName, requestId, requestType, status, cert, std::move(encryptionKey));
-    }
+    return state;
   }
   else {
-    NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) + " cannot be fetched from database"));
+    NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) +
+                                 " cannot be fetched from database"));
   }
 }
 
@@ -235,32 +229,22 @@
                              encryption_key, aes_block_counter
                              FROM RequestStates)_SQLTEXT_");
   while (statement.step() == SQLITE_ROW) {
-    RequestId requestId;
-    std::memcpy(requestId.data(), statement.getBlob(1), statement.getSize(1));
-    Name caName(statement.getBlock(2));
-    auto status = static_cast<Status>(statement.getInt(3));
-    auto challengeStatus = statement.getString(4);
-    security::Certificate cert(statement.getBlock(5));
-    auto challengeType = statement.getString(6);
-    auto challengeSecrets = statement.getString(7);
-    auto challengeTp = statement.getString(8);
-    auto remainingTries = statement.getInt(9);
-    auto remainingTime = statement.getInt(10);
-    auto requestType = static_cast<RequestType>(statement.getInt(11));
-    std::array<uint8_t, 16> encryptionKey;
-    std::memcpy(encryptionKey.data(), statement.getBlob(12), statement.getSize(12));
-    auto aesBlockCounter = statement.getInt(13);
-    if (challengeType != "") {
-      result.push_back(RequestState(caName, requestId, requestType, status, cert,
-                                    challengeType, challengeStatus, time::fromIsoString(challengeTp),
-                                    remainingTries, time::seconds(remainingTime),
-                                    convertString2Json(challengeSecrets),
-                                    std::move(encryptionKey), aesBlockCounter));
+    RequestState state;
+    std::memcpy(state.requestId.data(), statement.getBlob(1), statement.getSize(1));
+    state.caPrefix = Name(statement.getBlock(2));
+    state.status = static_cast<Status>(statement.getInt(3));
+    state.challengeType = statement.getString(6);
+    state.cert = security::Certificate(statement.getBlock(5));
+    state.requestType = static_cast<RequestType>(statement.getInt(11));
+    std::memcpy(state.encryptionKey.data(), statement.getBlob(12), statement.getSize(12));
+    state.aesBlockCounter = statement.getInt(13);
+    if (state.challengeType != "") {
+      ChallengeState challengeState(statement.getString(4), time::fromIsoString(statement.getString(8)),
+                                    statement.getInt(9), time::seconds(statement.getInt(10)),
+                                    convertString2Json(statement.getString(7)));
+      state.challengeState = challengeState;
     }
-    else {
-      result.push_back(RequestState(caName, requestId, requestType,
-                                    status, cert, std::move(encryptionKey), aesBlockCounter));
-    }
+    result.push_back(state);
   }
   return result;
 }
@@ -278,32 +262,22 @@
   statement.bind(1, caName.wireEncode(), SQLITE_TRANSIENT);
 
   while (statement.step() == SQLITE_ROW) {
-    RequestId requestId;
-    std::memcpy(requestId.data(), statement.getBlob(1), statement.getSize(1));
-    Name caName(statement.getBlock(2));
-    auto status = static_cast<Status>(statement.getInt(3));
-    auto challengeStatus = statement.getString(4);
-    security::Certificate cert(statement.getBlock(5));
-    auto challengeType = statement.getString(6);
-    auto challengeSecrets = statement.getString(7);
-    auto challengeTp = statement.getString(8);
-    auto remainingTries = statement.getInt(9);
-    auto remainingTime = statement.getInt(10);
-    auto requestType = static_cast<RequestType>(statement.getInt(11));
-    std::array<uint8_t, 16> encryptionKey;
-    std::memcpy(encryptionKey.data(), statement.getBlob(12), statement.getSize(12));
-    auto aesBlockCounter = statement.getInt(13);
-    if (challengeType != "") {
-      result.push_back(RequestState(caName, requestId, requestType, status, cert,
-                                    challengeType, challengeStatus, time::fromIsoString(challengeTp),
-                                    remainingTries, time::seconds(remainingTime),
-                                    convertString2Json(challengeSecrets),
-                                    std::move(encryptionKey), aesBlockCounter));
+    RequestState state;
+    std::memcpy(state.requestId.data(), statement.getBlob(1), statement.getSize(1));
+    state.caPrefix = Name(statement.getBlock(2));
+    state.status = static_cast<Status>(statement.getInt(3));
+    state.challengeType = statement.getString(6);
+    state.cert = security::Certificate(statement.getBlock(5));
+    state.requestType = static_cast<RequestType>(statement.getInt(11));
+    std::memcpy(state.encryptionKey.data(), statement.getBlob(12), statement.getSize(12));
+    state.aesBlockCounter = statement.getInt(13);
+    if (state.challengeType != "") {
+      ChallengeState challengeState(statement.getString(4), time::fromIsoString(statement.getString(8)),
+                                    statement.getInt(9), time::seconds(statement.getInt(10)),
+                                    convertString2Json(statement.getString(7)));
+      state.challengeState = challengeState;
     }
-    else {
-      result.push_back(RequestState(caName, requestId, requestType, status,
-                                    cert, std::move(encryptionKey), aesBlockCounter));
-    }
+    result.push_back(state);
   }
   return result;
 }