Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California. |
Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
| 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 7 | * |
| 8 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "util.hpp" |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 21 | |
| 22 | #include <ndn-cxx/security/transform.hpp> |
Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 23 | |
| 24 | namespace ndn { |
| 25 | namespace ndns { |
| 26 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 27 | using security::transform::base64Encode; |
| 28 | using security::transform::streamSink; |
| 29 | using security::transform::bufferSource; |
| 30 | |
Yumin Xia | a484ba7 | 2016-11-10 20:40:12 -0800 | [diff] [blame] | 31 | NdnsContentType |
| 32 | toNdnsContentType(const std::string& str) |
Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 33 | { |
| 34 | if (str == "resp") |
| 35 | return NDNS_RESP; |
| 36 | else if (str == "nack") |
| 37 | return NDNS_NACK; |
| 38 | else if (str == "auth") |
| 39 | return NDNS_AUTH; |
Yumin Xia | a484ba7 | 2016-11-10 20:40:12 -0800 | [diff] [blame] | 40 | else if (str == "blob") |
| 41 | return NDNS_BLOB; |
| 42 | else if (str == "link") |
| 43 | return NDNS_LINK; |
Yumin Xia | 3c6b1fd | 2016-12-11 19:08:47 -0800 | [diff] [blame] | 44 | else if (str == "key") |
| 45 | return NDNS_LINK; |
Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 46 | else |
| 47 | return NDNS_UNKNOWN; |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | output(const Data& data, std::ostream& os, const bool isPretty) |
| 52 | { |
Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 53 | const Block& block = data.wireEncode(); |
| 54 | if (!isPretty) { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 55 | bufferSource(block.wire(), block.size()) >> base64Encode() >> streamSink(os); |
Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 56 | } |
| 57 | else { |
| 58 | os << "Name: " << data.getName().toUri() << std::endl; |
| 59 | os << "KeyLocator: " << data.getSignature().getKeyLocator().getName().toUri() << std::endl; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame^] | 60 | bufferSource(block.wire(), block.size()) >> base64Encode() >> streamSink(os); |
Shock Jiang | 06cd214 | 2014-11-23 17:36:02 -0800 | [diff] [blame] | 61 | os << std::endl; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | } // namespace ndns |
| 66 | } // namespace ndn |