blob: 80b5a454fc8f22ef285b72715dfeff0b3ae6666c [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
4 *
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
27CertificateRequest::CertificateRequest(const Name& caName,
28 const std::string& requestId,
29 const security::v2::Certificate& cert)
30 : m_caName(caName)
31 , m_requestId(requestId)
32 , m_status(Pending)
33 , m_cert(static_cast<const Data&>(cert))
34{
35}
36
37CertificateRequest::CertificateRequest(const Name& caName,
38 const std::string& requestId,
39 const ApplicationStatus& status,
40 const std::string& challengeType,
41 const std::string& challengeStatus,
42 const std::string& challengeDefinedField,
43 const security::v2::Certificate& cert)
44 : m_caName(caName)
45 , m_requestId(requestId)
46 , m_status(status)
47 , m_challengeType(challengeType)
48 , m_challengeStatus(challengeStatus)
49 , m_challengeDefinedField(challengeDefinedField)
50 , m_cert(static_cast<const Data&>(cert))
51{
52}
53
54std::ostream&
55operator<<(std::ostream& os, CertificateRequest::ApplicationStatus status)
56{
57 std::string statusString;
58 switch (status) {
59 case CertificateRequest::Pending: {
60 statusString = "pending";
61 break;
62 }
63 case CertificateRequest::Verifying: {
64 statusString = "verifying";
65 break;
66 }
67 case CertificateRequest::Success: {
68 statusString = "success";
69 break;
70 }
71 case CertificateRequest::Failure: {
72 statusString = "failure";
73 break;
74 }
75 }
76 os << statusString;
77 return os;
78}
79
80std::ostream&
81operator<<(std::ostream& os, const CertificateRequest& request)
82{
83 os << "Request CA name:\n";
84 os << " " << request.getCaName() << "\n";
85 os << "Request ID:\n";
86 os << " " << request.getRequestId() << "\n";
87 os << "Request Status:\n";
88 os << " " << request.getStatus() << "\n";
89 if (request.getChallengeType() != "") {
90 os << "Request Challenge Type:\n";
91 os << " " << request.getChallengeType() << "\n";
92 }
93 if (request.getChallengeStatus() != "") {
94 os << "Request Challenge Status:\n";
95 os << " " << request.getChallengeStatus() << "\n";
96 }
97 os << "Certificate:\n";
98 util::IndentedStream os2(os, " ");
99 os2 << request.getCert();
100 return os;
101}
102
103} // namespace ndncert
104} // namespace ndn