Rename RequestState to CaState
- to prevent confusion with RequesterState
Change-Id: I56048e289fded44bf39dd1fe6a5e26ddd3938b99
diff --git a/src/ca-state.cpp b/src/ca-state.cpp
new file mode 100644
index 0000000..e30fd66
--- /dev/null
+++ b/src/ca-state.cpp
@@ -0,0 +1,102 @@
+/* -*- 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 "ca-state.hpp"
+#include <ndn-cxx/util/indented-stream.hpp>
+
+namespace ndn {
+namespace ndncert {
+
+ChallengeState::ChallengeState(const std::string& challengeStatus,
+ const system_clock::TimePoint& challengeTp,
+ size_t remainingTries, time::seconds remainingTime,
+ JsonSection&& challengeSecrets)
+ : m_challengeStatus(challengeStatus)
+ , m_timestamp(challengeTp)
+ , m_remainingTries(remainingTries)
+ , m_remainingTime(remainingTime)
+ , m_secrets(std::move(challengeSecrets))
+{
+}
+
+CaState::CaState()
+ : m_requestType(RequestType::NOTINITIALIZED)
+ , m_status(Status::NOT_STARTED)
+{
+}
+
+CaState::CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
+ const security::v2::Certificate& cert, Block encryptionKey)
+ : m_caPrefix(caName)
+ , m_requestId(requestId)
+ , m_requestType(requestType)
+ , m_status(status)
+ , m_cert(cert)
+ , m_encryptionKey(std::move(encryptionKey))
+{
+}
+
+CaState::CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
+ const security::v2::Certificate& cert, const std::string& challengeType,
+ const std::string& challengeStatus, const system_clock::TimePoint& challengeTp,
+ size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
+ Block encryptionKey)
+ : m_caPrefix(caName)
+ , m_requestId(requestId)
+ , m_requestType(requestType)
+ , m_status(status)
+ , m_cert(cert)
+ , m_encryptionKey(std::move(encryptionKey))
+ , m_challengeType(challengeType)
+ , m_challengeState(ChallengeState(challengeStatus, challengeTp, remainingTries, remainingTime, std::move(challengeSecrets)))
+{
+}
+
+std::ostream&
+operator<<(std::ostream& os, const CaState& request)
+{
+ os << "Request's CA name:\n";
+ os << " " << request.m_caPrefix << "\n";
+ os << "Request's request ID:\n";
+ os << " " << request.m_requestId << "\n";
+ os << "Request's status:\n";
+ os << " " << statusToString(request.m_status) << "\n";
+ os << "Request's challenge type:\n";
+ os << " " << request.m_challengeType << "\n";
+ if (request.m_challengeState) {
+ os << "Challenge Status:\n";
+ os << " " << request.m_challengeState->m_challengeStatus << "\n";
+ os << "Challenge remaining tries:\n";
+ os << " " << request.m_challengeState->m_remainingTries << " times\n";
+ os << "Challenge remaining time:\n";
+ os << " " << request.m_challengeState->m_remainingTime.count() << " seconds\n";
+ os << "Challenge last update:\n";
+ os << " " << time::toIsoString(request.m_challengeState->m_timestamp) << "\n";
+ os << "Challenge secret:\n";
+ os << " " << convertJson2String(request.m_challengeState->m_secrets) << "\n";
+ }
+ os << "Certificate:\n";
+ util::IndentedStream os2(os, " ");
+ os2 << request.m_cert;
+ return os;
+}
+
+} // namespace ndncert
+} // namespace ndn