blob: 81fa829f0690d7a4b3fb268bfb67a208b5e429e3 [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
Zhiyi Zhang0fd71cc2017-03-01 10:18:58 -080028genResponseProbeJson(const Name& identifier, const Name& caInformation)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080029{
30 JsonSection root;
31
32 root.put(JSON_IDNENTIFIER, identifier.toUri());
Zhiyi Zhang0fd71cc2017-03-01 10:18:58 -080033 root.put(JSON_CA_INFO, caInformation.toUri());
Zhiyi Zhang19768a52017-01-18 14:44:15 -080034
35 return root;
36}
37
38const JsonSection
Zhiyi Zhang0fd71cc2017-03-01 10:18:58 -080039genResponseNewJson(const std::string& requestId, const std::string& status,
40 const std::list<std::string>& challenges)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080041{
42 JsonSection root;
43 JsonSection challengesSection;
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080044 root.put(JSON_REQUEST_ID, requestId);
Zhiyi Zhang0fd71cc2017-03-01 10:18:58 -080045 root.put(JSON_STATUS, status);
Zhiyi Zhang19768a52017-01-18 14:44:15 -080046
47 for (const auto& entry : challenges) {
48 JsonSection challenge;
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080049 challenge.put(JSON_CHALLENGE_TYPE, entry);
Zhiyi Zhang19768a52017-01-18 14:44:15 -080050 challengesSection.push_back(std::make_pair("", challenge));
51 }
52 root.add_child(JSON_CHALLENGES, challengesSection);
53
54 return root;
55}
56
57const JsonSection
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080058genResponseChallengeJson(const std::string& requestId, const std::string& challengeType,
59 const std::string& status, const Name& name)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080060{
61 JsonSection root;
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080062 root.put(JSON_REQUEST_ID, requestId);
63 root.put(JSON_CHALLENGE_TYPE, challengeType);
64 root.put(JSON_STATUS, status);
65 if (name.toUri() != "") {
66 root.put(JSON_CERTIFICATE, name.toUri());
67 }
Zhiyi Zhang19768a52017-01-18 14:44:15 -080068 return root;
69}
70
71const JsonSection
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070072genFailureJson(const std::string& requestId, const std::string& challengeType,
73 const std::string& status, const std::string& failureInfo)
Zhiyi Zhang19768a52017-01-18 14:44:15 -080074{
75 JsonSection root;
Zhiyi Zhanga9bda732017-05-20 22:58:55 -070076 root.put(JSON_REQUEST_ID, requestId);
77 root.put(JSON_CHALLENGE_TYPE, challengeType);
78 root.put(JSON_STATUS, status);
79 root.put(JSON_FAILURE_INFO, failureInfo);
Zhiyi Zhang19768a52017-01-18 14:44:15 -080080 return root;
81}
82
83} // namespace ndncert
84} // namespace ndn