blob: ac1a21629c061cdfba21d0a3dbb73901858f768c [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
Zhiyi Zhang00a4a002017-03-01 10:17:36 -080027CertificateRequest::CertificateRequest() = default;
28
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080029CertificateRequest::CertificateRequest(const Name& caName,
30 const std::string& requestId,
31 const security::v2::Certificate& cert)
32 : m_caName(caName)
33 , m_requestId(requestId)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080034 , m_cert(static_cast<const Data&>(cert))
35{
36}
37
38CertificateRequest::CertificateRequest(const Name& caName,
39 const std::string& requestId,
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080040 const std::string& status,
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080041 const std::string& challengeType,
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080042 const std::string& challengeSecrets,
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080043 const security::v2::Certificate& cert)
44 : m_caName(caName)
45 , m_requestId(requestId)
46 , m_status(status)
47 , m_challengeType(challengeType)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080048 , m_cert(static_cast<const Data&>(cert))
49{
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080050 std::istringstream ss(challengeSecrets);
51 boost::property_tree::json_parser::read_json(ss, m_challengeSecrets);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080052}
53
54std::ostream&
55operator<<(std::ostream& os, const CertificateRequest& request)
56{
57 os << "Request CA name:\n";
58 os << " " << request.getCaName() << "\n";
59 os << "Request ID:\n";
60 os << " " << request.getRequestId() << "\n";
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080061 if (request.getStatus() != "") {
62 os << "Request Status:\n";
63 os << " " << request.getStatus() << "\n";
64 }
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080065 if (request.getChallengeType() != "") {
66 os << "Request Challenge Type:\n";
67 os << " " << request.getChallengeType() << "\n";
68 }
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080069 os << "Certificate:\n";
70 util::IndentedStream os2(os, " ");
71 os2 << request.getCert();
72 return os;
73}
74
75} // namespace ndncert
76} // namespace ndn