Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 24 | namespace ndn { |
| 25 | namespace ndncert { |
| 26 | |
Zhiyi Zhang | 00a4a00 | 2017-03-01 10:17:36 -0800 | [diff] [blame] | 27 | CertificateRequest::CertificateRequest() = default; |
| 28 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 29 | CertificateRequest::CertificateRequest(const Name& caName, |
| 30 | const std::string& requestId, |
| 31 | const security::v2::Certificate& cert) |
| 32 | : m_caName(caName) |
| 33 | , m_requestId(requestId) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 34 | , m_cert(static_cast<const Data&>(cert)) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | CertificateRequest::CertificateRequest(const Name& caName, |
| 39 | const std::string& requestId, |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 40 | const std::string& status, |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 41 | const std::string& challengeType, |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 42 | const std::string& challengeSecrets, |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 43 | const security::v2::Certificate& cert) |
| 44 | : m_caName(caName) |
| 45 | , m_requestId(requestId) |
| 46 | , m_status(status) |
| 47 | , m_challengeType(challengeType) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 48 | , m_cert(static_cast<const Data&>(cert)) |
| 49 | { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 50 | std::istringstream ss(challengeSecrets); |
| 51 | boost::property_tree::json_parser::read_json(ss, m_challengeSecrets); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | std::ostream& |
| 55 | operator<<(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 Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 61 | if (request.getStatus() != "") { |
| 62 | os << "Request Status:\n"; |
| 63 | os << " " << request.getStatus() << "\n"; |
| 64 | } |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 65 | if (request.getChallengeType() != "") { |
| 66 | os << "Request Challenge Type:\n"; |
| 67 | os << " " << request.getChallengeType() << "\n"; |
| 68 | } |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 69 | os << "Certificate:\n"; |
| 70 | util::IndentedStream os2(os, " "); |
| 71 | os2 << request.getCert(); |
| 72 | return os; |
| 73 | } |
| 74 | |
| 75 | } // namespace ndncert |
| 76 | } // namespace ndn |