blob: a7cc897bd5c21b71cbe03bb7554e44a9aa718130 [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
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080039genResponseNewJson(const std::string& requestId, const std::list<std::string>& challenges)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080040{
41 JsonSection root;
42 JsonSection challengesSection;
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080043 root.put(JSON_REQUEST_ID, requestId);
Zhiyi Zhang19768a52017-01-18 14:44:15 -080044
45 for (const auto& entry : challenges) {
46 JsonSection challenge;
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080047 challenge.put(JSON_CHALLENGE_TYPE, entry);
Zhiyi Zhang19768a52017-01-18 14:44:15 -080048 challengesSection.push_back(std::make_pair("", challenge));
49 }
50 root.add_child(JSON_CHALLENGES, challengesSection);
51
52 return root;
53}
54
55const JsonSection
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080056genResponseChallengeJson(const std::string& requestId, const std::string& challengeType,
57 const std::string& status, const Name& name)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080058{
59 JsonSection root;
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080060 root.put(JSON_REQUEST_ID, requestId);
61 root.put(JSON_CHALLENGE_TYPE, challengeType);
62 root.put(JSON_STATUS, status);
63 if (name.toUri() != "") {
64 root.put(JSON_CERTIFICATE, name.toUri());
65 }
Zhiyi Zhang19768a52017-01-18 14:44:15 -080066 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