blob: b205531ecd47ada2bda4d373ff81a59d52021425 [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
tylerliu182bc532020-09-25 01:54:45 -07003 * Copyright (c) 2017-2020, 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 Zhang48f23782020-09-28 12:11:24 -070029CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int requestType, Status status,
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080030 const security::v2::Certificate& cert)
Zhiyi Zhang48f23782020-09-28 12:11:24 -070031 : m_caPrefix(caName)
32 , m_requestId(requestId)
33 , m_requestType(requestType)
34 , m_status(status)
35 , m_cert(cert)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080036{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070037}
38
Zhiyi Zhang48f23782020-09-28 12:11:24 -070039CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int requestType, Status status,
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070040 const std::string& challengeStatus, const std::string& challengeType,
41 const std::string& challengeTp, int remainingTime, int remainingTries,
42 const JsonSection& challengeSecrets, const security::v2::Certificate& cert)
Zhiyi Zhang48f23782020-09-28 12:11:24 -070043 : m_caPrefix(caName)
44 , m_requestId(requestId)
45 , m_requestType(requestType)
46 , m_status(status)
47 , m_cert(cert)
48 , m_challengeStatus(challengeStatus)
49 , m_challengeType(challengeType)
50 , m_challengeTp(challengeTp)
51 , m_remainingTime(remainingTime)
52 , m_remainingTries(remainingTries)
53 , m_challengeSecrets(challengeSecrets)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070054{
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080055}
56
Zhiyi Zhang5f749a22019-06-12 17:02:33 -070057void
58CertificateRequest::setProbeToken(const shared_ptr<Data>& probeToken)
59{
60 m_probeToken = probeToken;
61}
62
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080063std::ostream&
64operator<<(std::ostream& os, const CertificateRequest& request)
65{
66 os << "Request CA name:\n";
Suyong Won256c9062020-05-11 02:45:56 -070067 os << " " << request.m_caPrefix << "\n";
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080068 os << "Request ID:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070069 os << " " << request.m_requestId << "\n";
Zhiyi Zhang48f23782020-09-28 12:11:24 -070070 os << "Request Status:\n";
71 os << " " << statusToString(request.m_status) << "\n";
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
Zhiyi Zhang48f23782020-09-28 12:11:24 -070086} // namespace ndncert
87} // namespace ndn