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_;
}