blob: 609b4265308f401ff2af3d0720d1daa6b715dd09 [file] [log] [blame]
Zhiyi Zhang19768a52017-01-18 14:44:15 -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 "json-helper.hpp"
22#include <boost/lexical_cast.hpp>
23
24namespace ndn {
25namespace ndncert {
26
27const JsonSection
28genResponseProbeJson(const Name& identifier, const Name& CaInformation)
29{
30 JsonSection root;
31
32 root.put(JSON_IDNENTIFIER, identifier.toUri());
33 root.put(JSON_CA_INFO, CaInformation.toUri());
34
35 return root;
36}
37
38const JsonSection
39genResponseNewJson(const CertificateRequest& request,
40 const std::list<std::tuple<std::string, std::string>> challenges)
41{
42 JsonSection root;
43 JsonSection challengesSection;
44 root.put(JSON_STATUS, boost::lexical_cast<std::string>(request.getStatus()));
45 root.put(JSON_REQUEST_ID, request.getRequestId());
46
47 for (const auto& entry : challenges) {
48 JsonSection challenge;
49 challenge.put(JSON_CHALLENGE_TYPE, std::get<0>(entry));
50 challenge.put(JSON_CHALLENGE_INSTRUCTION, std::get<1>(entry));
51 challengesSection.push_back(std::make_pair("", challenge));
52 }
53 root.add_child(JSON_CHALLENGES, challengesSection);
54
55 return root;
56}
57
58const JsonSection
59genResponsePollJson(const CertificateRequest& request)
60{
61 JsonSection root;
62 root.put(JSON_STATUS, boost::lexical_cast<std::string>(request.getStatus()));
63 root.put(JSON_CHALLENGE_TYPE, request.getChallengeType());
64 root.put(JSON_CHALLENGE_STATUS, request.getChallengeStatus());
65 root.put(JSON_CHALLENGE_INSTRUCTION, request.getChallengeInstruction());
66 return root;
67}
68
69const JsonSection
70genErrorJson(const std::string& errorInfo)
71{
72 JsonSection root;
73 root.put(JSON_STATUS, "error");
74 root.put(JSON_ERROR_INFO, errorInfo);
75 return root;
76}
77
78} // namespace ndncert
79} // namespace ndn