blob: d1a454559d220bf5f9e4c757356747268c5117b7 [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)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080032 , m_cert(static_cast<const Data&>(cert))
33{
34}
35
36CertificateRequest::CertificateRequest(const Name& caName,
37 const std::string& requestId,
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080038 const std::string& status,
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080039 const std::string& challengeType,
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080040 const std::string& challengeSecrets,
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080041 const security::v2::Certificate& cert)
42 : m_caName(caName)
43 , m_requestId(requestId)
44 , m_status(status)
45 , m_challengeType(challengeType)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080046 , m_cert(static_cast<const Data&>(cert))
47{
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080048 std::istringstream ss(challengeSecrets);
49 boost::property_tree::json_parser::read_json(ss, m_challengeSecrets);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080050}
51
52std::ostream&
53operator<<(std::ostream& os, const CertificateRequest& request)
54{
55 os << "Request CA name:\n";
56 os << " " << request.getCaName() << "\n";
57 os << "Request ID:\n";
58 os << " " << request.getRequestId() << "\n";
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080059 if (request.getStatus() != "") {
60 os << "Request Status:\n";
61 os << " " << request.getStatus() << "\n";
62 }
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080063 if (request.getChallengeType() != "") {
64 os << "Request Challenge Type:\n";
65 os << " " << request.getChallengeType() << "\n";
66 }
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080067 os << "Certificate:\n";
68 util::IndentedStream os2(os, " ");
69 os2 << request.getCert();
70 return os;
71}
72
73} // namespace ndncert
74} // namespace ndn