security: Correcting generation of SignatureSha256WithRsa to conforming to the packet format specification

KeyLocator block is required even if it is empty.  Before this commit,
an empty KeyLocator was omitted, which violated the format spec.

Change-Id: I3fc0f1d888e032aacb261886dd726e4c8748c4cb
diff --git a/include/ndn-cpp/key-locator.hpp b/include/ndn-cpp/key-locator.hpp
index 57b5f4b..2ff85f0 100644
--- a/include/ndn-cpp/key-locator.hpp
+++ b/include/ndn-cpp/key-locator.hpp
@@ -75,19 +75,23 @@
 inline const Block& 
 KeyLocator::wireEncode() const
 {
-  if (empty())
-    throw Error("Wire encoding requested, but KeyLocator is empty");
-
   if (wire_.hasWire())
     return wire_;
-  
-  if (type_ != KeyLocator_Name)
-    throw Error("Unsupported KeyLocator type");
-  
+
   // KeyLocator
-  wire_ = Block(Tlv::KeyLocator);
-  wire_.push_back(name_.wireEncode());
-  wire_.encode();
+
+  switch (type_) {
+  case KeyLocator_None:
+    wire_ = dataBlock(Tlv::KeyLocator, reinterpret_cast<const uint8_t*>(0), 0);
+    break;
+  case KeyLocator_Name:
+    wire_ = Block(Tlv::KeyLocator);
+    wire_.push_back(name_.wireEncode());
+    wire_.encode();
+    break;
+  default:
+    throw Error("Unsupported KeyLocator type");
+  }
   
   return wire_;
 }
diff --git a/include/ndn-cpp/security/signature-sha256-with-rsa.hpp b/include/ndn-cpp/security/signature-sha256-with-rsa.hpp
index 8eb26b1..b59c765 100644
--- a/include/ndn-cpp/security/signature-sha256-with-rsa.hpp
+++ b/include/ndn-cpp/security/signature-sha256-with-rsa.hpp
@@ -23,6 +23,7 @@
     
     type_ = Signature::Sha256WithRsa;
     info_.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa));
+    info_.push_back(keyLocator_.wireEncode());
   }
   
   SignatureSha256WithRsa(const Signature &signature)
@@ -50,7 +51,7 @@
   {
     keyLocator_ = keyLocator;
 
-    /// @todo Ensure that keylocator does not exist
+    info_.remove(ndn::Tlv::KeyLocator);
     info_.push_back(keyLocator_.wireEncode());
   }