signature-info: Fix encoding of type-specific TLV

This commit also introduces operator<< for SignatureInfo

Change-Id: Iddf5b77d9dab9f7b1764500726e6d5b1e13aedbb
Refs: #3914
diff --git a/src/signature-info.cpp b/src/signature-info.cpp
index 821d5a7..3d789dc 100644
--- a/src/signature-info.cpp
+++ b/src/signature-info.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -145,7 +145,7 @@
 
   for (std::list<Block>::const_reverse_iterator i = m_otherTlvs.rbegin();
        i != m_otherTlvs.rend(); i++) {
-    totalLength += encoder.appendBlock(*i);
+    totalLength += encoder.prependBlock(*i);
   }
 
   if (m_hasKeyLocator)
@@ -230,4 +230,21 @@
           m_otherTlvs == rhs.m_otherTlvs);
 }
 
+std::ostream&
+operator<<(std::ostream& os, const SignatureInfo& info)
+{
+  os << static_cast<tlv::SignatureTypeValue>(info.getSignatureType());
+  if (info.hasKeyLocator()) {
+    os << " " << info.getKeyLocator();
+  }
+  if (!info.m_otherTlvs.empty()) {
+    os << " { ";
+    for (const auto& block : info.m_otherTlvs) {
+      os << block.type() << " ";
+    }
+    os << "}";
+  }
+  return os;
+}
+
 } // namespace ndn
diff --git a/src/signature-info.hpp b/src/signature-info.hpp
index 4ee8e64..fc99542 100644
--- a/src/signature-info.hpp
+++ b/src/signature-info.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -145,8 +145,14 @@
   std::list<Block> m_otherTlvs;
 
   mutable Block m_wire;
+
+  friend std::ostream&
+  operator<<(std::ostream& os, const SignatureInfo& info);
 };
 
+std::ostream&
+operator<<(std::ostream& os, const SignatureInfo& info);
+
 } // namespace ndn
 
 #endif // NDN_SIGNATURE_INFO_HPP