Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -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 | #ifndef NDNCERT_JSON_HELPER_HPP |
| 22 | #define NDNCERT_JSON_HELPER_HPP |
| 23 | |
| 24 | #include "certificate-request.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 29 | const std::string JSON_IDNENTIFIER = "identifier"; |
| 30 | const std::string JSON_CA_INFO = "ca-info"; |
| 31 | const std::string JSON_STATUS = "status"; |
| 32 | const std::string JSON_REQUEST_ID = "request-id"; |
| 33 | const std::string JSON_CHALLENGES = "challenges"; |
| 34 | const std::string JSON_CHALLENGE_TYPE = "challenge-type"; |
| 35 | const std::string JSON_ERROR_INFO = "error-info"; |
| 36 | const std::string JSON_CERTIFICATE = "certificate"; |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * @brief Generate JSON file to response PROBE insterest |
| 40 | * |
| 41 | * Target JSON format: |
| 42 | * { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 43 | * "identifier": "", |
| 44 | * "ca-info": "" |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 45 | * } |
| 46 | */ |
| 47 | const JsonSection |
| 48 | genResponseProbeJson(const Name& identifier, const Name& CaInformation); |
| 49 | |
| 50 | /** |
| 51 | * @brief Generate JSON file to response NEW interest |
| 52 | * |
| 53 | * Target JSON format: |
| 54 | * { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 55 | * "request-id": "", |
| 56 | * "challenges": [ |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 57 | * { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 58 | * "challenge-type": "" |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 59 | * }, |
| 60 | * { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 61 | * "challenge-type": "" |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 62 | * }, |
| 63 | * ... |
| 64 | * ] |
| 65 | * } |
| 66 | */ |
| 67 | const JsonSection |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 68 | genResponseNewJson(const std::string& requestId, const std::list<std::string>& challenges); |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 69 | |
| 70 | /** |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 71 | * @brief Generate JSON file to response _SELECT, _VALIDATE, and _STATUS interest |
| 72 | * |
| 73 | * if certificate name is not present: |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 74 | * |
| 75 | * Target JSON format: |
| 76 | * { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 77 | * "request-id": "@p requestId", |
| 78 | * "challenge-type": "@p challengeType", |
| 79 | * "status": "@p status" |
| 80 | * } |
| 81 | * |
| 82 | * if certificate name is present: |
| 83 | * |
| 84 | * Target JSON format: |
| 85 | * { |
| 86 | * "request-id": "@p requestId", |
| 87 | * "challenge-type": "@p challengeType", |
| 88 | * "status": "@p status", |
| 89 | * "certificate":"@p name" |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 90 | * } |
| 91 | */ |
| 92 | const JsonSection |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 93 | genResponseChallengeJson(const std::string& requestId, const std::string& challengeType, |
| 94 | const std::string& status, const Name& name = Name()); |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * @brief Generate JSON file when there is an Error |
| 98 | * |
| 99 | * Target JSON format: |
| 100 | * { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 101 | * "status": "", |
| 102 | * "error-info": "" |
Zhiyi Zhang | 19768a5 | 2017-01-18 14:44:15 -0800 | [diff] [blame] | 103 | * } |
| 104 | */ |
| 105 | const JsonSection |
| 106 | genErrorJson(const std::string& errorInfo); |
| 107 | |
| 108 | } // namespace ndncert |
| 109 | } // namespace ndn |
| 110 | |
| 111 | #endif // NDNCERT_JSON_HELPER_HPP |