mgmt: change output format for ID-CERTs
Change-Id: Id22d264a50e6412a2ad52082cb7ea27d1a84e1e4
Refs: #2250
diff --git a/src/mgmt/management-tool.cpp b/src/mgmt/management-tool.cpp
index 9edd131..a53b0aa 100644
--- a/src/mgmt/management-tool.cpp
+++ b/src/mgmt/management-tool.cpp
@@ -31,6 +31,7 @@
#include <boost/lexical_cast.hpp>
#include <ndn-cxx/util/regex.hpp>
+#include <ndn-cxx/util/indented-stream.hpp>
#include <ndn-cxx/encoding/oid.hpp>
#include <ndn-cxx/security/cryptopp.hpp>
@@ -480,19 +481,17 @@
os << std::endl;
if (printRaw && re.getNdnsType() == NDNS_RAW) {
- using namespace CryptoPP;
- std::stringstream sstream;
- StringSource ss(re.getAppContent().wire(), re.getAppContent().size(), true,
- new Base64Encoder(new FileSink(sstream), true, 64));
+ util::IndentedStream istream(os, "; ");
- std::string content = sstream.str();
- std::string delimiter = "\n";
- size_t pos = 0;
- std::string token;
- while ((pos = content.find(delimiter)) != std::string::npos) {
- token = content.substr(0, pos);
- os << "; " << token << std::endl;
- content.erase(0, pos + delimiter.length());
+ if (re.getRrType() == label::CERT_RR_TYPE) {
+ shared_ptr<Data> data = re.toData();
+ IdentityCertificate cert(*data);
+ cert.printCertificate(istream);
+ }
+ else {
+ using namespace CryptoPP;
+ StringSource ss(re.getAppContent().wire(), re.getAppContent().size(), true,
+ new Base64Encoder(new FileSink(istream), true, 64));
}
}
os << std::endl;
diff --git a/tests/unit/mgmt/management-tool.cpp b/tests/unit/mgmt/management-tool.cpp
index b6fb73c..b2b9806 100644
--- a/tests/unit/mgmt/management-tool.cpp
+++ b/tests/unit/mgmt/management-tool.cpp
@@ -836,14 +836,23 @@
"\n"
"/dsk-1416974006659 10 ID-CERT ; content-type=NDNS-Raw version=%FD%00%00%01I%EA%3Bz%0E "
"signed-by=/ndns-test/KEY/ksk-1416974006577/ID-CERT\n"
- "; Ff0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8yMDM4MDExOTAzMTQwOFowEzAR\n"
- "; BgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3DQEBAQUAA4IBDQAwggEIAoIB\n"
- "; AQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30PmKe4gWvtxzhb4vIngYbXGv2i\n"
- "; UzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK00rpTh648HjCSz+Awgp2nbiYA\n"
- "; AVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYToY9ee4xLSjqzXfLMyP1h8OHc\n"
- "; N/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0B5grCAQoPHwkfxkEnzQBA/fb\n"
- "; UdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz36Sks1DAO+1EvCRnjoH5vYmk\n"
- "; pMUBFue+6A40IQG4brM2CiIRAgER\n"
+ "; Certificate name:\n"
+ "; /ndns-test/KEY/dsk-1416974006659/ID-CERT/%FD%00%00%01I%EA%3Bz%0E\n"
+ "; Validity:\n"
+ "; NotBefore: 19700101T000000\n"
+ "; NotAfter: 20380119T031408\n"
+ "; Subject Description:\n"
+ "; 2.5.4.41: /ndns-test\n"
+ "; Public key bits: (RSA)\n"
+ "; MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAyBVC+xc/JpscSE/JdxbV\n"
+ "; pvgrh/fokNFI/2t9D5inuIFr7cc4W+LyJ4GG1xr9olMx7MHamJU1Xg3VunjhSjL8\n"
+ "; mOaeXlbS6gxWexBCtNK6U4euPB4wks/gMIKdp24mAAFb4T+mBfjcRgR+NdrjyO5C\n"
+ "; 2OqM8qbDZmD/iuEmE6GPXnuMS0o6s13yzMj9YfDh3Df2jZnHESZcmG5Qpgg22T58\n"
+ "; 7t7bRx8Ha2EC3hb29AeYKwgEKDx8JH8ZBJ80AQP321HbyjXWshJLomzy5SJZo9nA\n"
+ "; bZOYlZPCQkomz92Zc9+kpLNQwDvtRLwkZ46B+b2JpKTFARbnvugONCEBuG6zNgoi\n"
+ "; EQIB\n"
+ "; Signature Information:\n"
+ "; Signature Type: Unknown Signature Type\n"
"\n";
BOOST_CHECK(testOutput.is_equal(expectedValue));