blob: 47fbc52a1551d554b0118a930dc1fcc8ae2c8a44 [file] [log] [blame]
Shock Jiang06cd2142014-11-23 17:36:02 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
3 * Copyright (c) 2014-2017, Regents of the University of California.
Shock Jiang06cd2142014-11-23 17:36:02 -08004 *
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 Xia2c509c22017-02-09 14:37:36 -080021
22#include <ndn-cxx/security/transform.hpp>
Shock Jiang06cd2142014-11-23 17:36:02 -080023
24namespace ndn {
25namespace ndns {
26
Yumin Xia2c509c22017-02-09 14:37:36 -080027using security::transform::base64Encode;
28using security::transform::streamSink;
29using security::transform::bufferSource;
30
Yumin Xiaa484ba72016-11-10 20:40:12 -080031NdnsContentType
32toNdnsContentType(const std::string& str)
Shock Jiang06cd2142014-11-23 17:36:02 -080033{
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 Xiaa484ba72016-11-10 20:40:12 -080040 else if (str == "blob")
41 return NDNS_BLOB;
42 else if (str == "link")
43 return NDNS_LINK;
Yumin Xia3c6b1fd2016-12-11 19:08:47 -080044 else if (str == "key")
45 return NDNS_LINK;
Shock Jiang06cd2142014-11-23 17:36:02 -080046 else
47 return NDNS_UNKNOWN;
48}
49
50void
51output(const Data& data, std::ostream& os, const bool isPretty)
52{
Shock Jiang06cd2142014-11-23 17:36:02 -080053 const Block& block = data.wireEncode();
54 if (!isPretty) {
Yumin Xia2c509c22017-02-09 14:37:36 -080055 bufferSource(block.wire(), block.size()) >> base64Encode() >> streamSink(os);
Shock Jiang06cd2142014-11-23 17:36:02 -080056 }
57 else {
58 os << "Name: " << data.getName().toUri() << std::endl;
59 os << "KeyLocator: " << data.getSignature().getKeyLocator().getName().toUri() << std::endl;
Yumin Xia2c509c22017-02-09 14:37:36 -080060 bufferSource(block.wire(), block.size()) >> base64Encode() >> streamSink(os);
Shock Jiang06cd2142014-11-23 17:36:02 -080061 os << std::endl;
62 }
63}
64
65} // namespace ndns
66} // namespace ndn