blob: 22b67b05e71e612801113c24d3b3b653e7de17cb [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -07003 * Copyright (c) 2017-2019, Regents of the University of California.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08004 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
21#include "certificate-request.hpp"
22#include <ndn-cxx/util/indented-stream.hpp>
23
24namespace ndn {
25namespace ndncert {
26
Zhiyi Zhang00a4a002017-03-01 10:17:36 -080027CertificateRequest::CertificateRequest() = default;
28
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070029CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int status,
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080030 const security::v2::Certificate& cert)
31 : m_caName(caName)
32 , m_requestId(requestId)
33 , m_status(status)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070034 , m_cert(cert)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080035{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070036}
37
38CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int status,
39 const std::string& challengeStatus, const std::string& challengeType,
40 const std::string& challengeTp, int remainingTime, int remainingTries,
41 const JsonSection& challengeSecrets, const security::v2::Certificate& cert)
42 : m_caName(caName)
43 , m_requestId(requestId)
44 , m_status(status)
45 , m_cert(cert)
46 , m_challengeStatus(challengeStatus)
47 , m_challengeType(challengeType)
48 , m_challengeTp(challengeTp)
49 , m_remainingTime(remainingTime)
50 , m_remainingTries(remainingTries)
51 , m_challengeSecrets(challengeSecrets)
52{
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080053}
54
Zhiyi Zhang5f749a22019-06-12 17:02:33 -070055void
56CertificateRequest::setProbeToken(const shared_ptr<Data>& probeToken)
57{
58 m_probeToken = probeToken;
59}
60
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080061std::ostream&
62operator<<(std::ostream& os, const CertificateRequest& request)
63{
64 os << "Request CA name:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070065 os << " " << request.m_caName << "\n";
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080066 os << "Request ID:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070067 os << " " << request.m_requestId << "\n";
68 if (request.m_status != -1) {
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080069 os << "Request Status:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070070 os << " " << request.m_status << "\n";
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080071 }
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070072 if (request.m_challengeStatus != "") {
73 os << "Challenge Status:\n";
74 os << " " << request.m_challengeStatus << "\n";
75 }
76 if (request.m_challengeType != "") {
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080077 os << "Request Challenge Type:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070078 os << " " << request.m_challengeType << "\n";
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080079 }
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080080 os << "Certificate:\n";
81 util::IndentedStream os2(os, " ");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070082 os2 << request.m_cert;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080083 return os;
84}
85
86} // namespace ndncert
87} // namespace ndn