interest: add signature fields

refs #4804

Change-Id: I4c8ecf65a3616833020d8edf8ba3d0c2d8427e87
diff --git a/ndn-cxx/interest.cpp b/ndn-cxx/interest.cpp
index 5ebc21e..8f69fcb 100644
--- a/ndn-cxx/interest.cpp
+++ b/ndn-cxx/interest.cpp
@@ -31,6 +31,8 @@
 #include <boost/stacktrace/stacktrace.hpp>
 #endif
 
+#include <boost/range/adaptor/reversed.hpp>
+
 #include <cstring>
 #include <iostream>
 #include <sstream>
@@ -121,9 +123,9 @@
   size_t totalLength = 0;
 
   // ApplicationParameters and following elements (in reverse order)
-  std::for_each(m_parameters.rbegin(), m_parameters.rend(), [&] (const Block& b) {
-    totalLength += encoder.prependBlock(b);
-  });
+  for (const auto& block : m_parameters | boost::adaptors::reversed) {
+    totalLength += encoder.prependBlock(block);
+  }
 
   // HopLimit
   if (getHopLimit()) {
@@ -526,6 +528,110 @@
   return *this;
 }
 
+bool
+Interest::isSigned() const noexcept
+{
+  return m_parameters.size() >= 3 &&
+         getSignatureInfo().has_value() &&
+         getSignatureValue().isValid() &&
+         !m_name.empty() &&
+         m_name[-1].type() == tlv::ParametersSha256DigestComponent;
+}
+
+optional<SignatureInfo>
+Interest::getSignatureInfo() const
+{
+  auto blockIt = findFirstParameter(tlv::InterestSignatureInfo);
+  if (blockIt != m_parameters.end()) {
+    return make_optional<SignatureInfo>(*blockIt, SignatureInfo::Type::Interest);
+  }
+  return nullopt;
+}
+
+Interest&
+Interest::setSignatureInfo(const SignatureInfo& info)
+{
+  // Prepend empty ApplicationParameters element if none present
+  if (m_parameters.empty()) {
+    m_parameters.push_back(makeEmptyBlock(tlv::ApplicationParameters));
+  }
+
+  // Find first existing InterestSignatureInfo (if any)
+  auto infoIt = std::find_if(m_parameters.begin(), m_parameters.end(), [] (const Block& block) {
+    return block.type() == tlv::InterestSignatureInfo;
+  });
+
+  Block encodedInfo = info.wireEncode(SignatureInfo::Type::Interest);
+  if (infoIt != m_parameters.end()) {
+    if (*infoIt == encodedInfo) {
+      // New InterestSignatureInfo is the same as the old InterestSignatureInfo
+      return *this;
+    }
+
+    // Replace existing InterestSignatureInfo
+    *infoIt = std::move(encodedInfo);
+  }
+  else {
+    // Place before first InterestSignatureValue element (if any), else at end
+    auto valueIt = findFirstParameter(tlv::InterestSignatureValue);
+    m_parameters.insert(valueIt, std::move(encodedInfo));
+  }
+
+  addOrReplaceParametersDigestComponent();
+  m_wire.reset();
+  return *this;
+}
+
+Block
+Interest::getSignatureValue() const
+{
+  auto blockIt = findFirstParameter(tlv::InterestSignatureValue);
+  if (blockIt != m_parameters.end()) {
+    return *blockIt;
+  }
+  return {};
+}
+
+Interest&
+Interest::setSignatureValue(ConstBufferPtr value)
+{
+  if (value == nullptr) {
+    NDN_THROW(std::invalid_argument("InterestSignatureValue buffer cannot be nullptr"));
+  }
+
+  // Ensure presence of InterestSignatureInfo
+  auto infoIt = findFirstParameter(tlv::InterestSignatureInfo);
+  if (infoIt == m_parameters.end()) {
+    NDN_THROW(Error("InterestSignatureInfo must be present to set InterestSignatureValue"));
+  }
+
+  auto valueIt = std::find_if(m_parameters.begin(), m_parameters.end(), [] (const Block& block) {
+    return block.type() == tlv::InterestSignatureValue;
+  });
+
+  Block valueBlock(tlv::InterestSignatureValue, std::move(value));
+  if (valueIt != m_parameters.end()) {
+    if (*valueIt == valueBlock) {
+      // New InterestSignatureValue is the same as the old InterestSignatureValue
+      return *this;
+    }
+
+    // Replace existing InterestSignatureValue
+    *valueIt = std::move(valueBlock);
+  }
+  else {
+    // Place after first InterestSignatureInfo element
+    valueIt = m_parameters.insert(std::next(infoIt), std::move(valueBlock));
+  }
+
+  // computeParametersDigest needs encoded SignatureValue
+  valueIt->encode();
+
+  addOrReplaceParametersDigestComponent();
+  m_wire.reset();
+  return *this;
+}
+
 // ---- ParametersSha256DigestComponent support ----
 
 bool
@@ -558,9 +664,9 @@
   OBufferStream out;
   in >> digestFilter(DigestAlgorithm::SHA256) >> streamSink(out);
 
-  std::for_each(m_parameters.begin(), m_parameters.end(), [&] (const Block& b) {
-    in.write(b.wire(), b.size());
-  });
+  for (const auto& block : m_parameters) {
+    in.write(block.wire(), block.size());
+  }
   in.end();
 
   return out.buf();
@@ -600,6 +706,14 @@
   return pos;
 }
 
+std::vector<Block>::const_iterator
+Interest::findFirstParameter(uint32_t type) const
+{
+  return std::find_if(m_parameters.begin(), m_parameters.end(), [type] (const Block& block) {
+    return block.type() == type;
+  });
+}
+
 // ---- operators ----
 
 std::ostream&
diff --git a/ndn-cxx/interest.hpp b/ndn-cxx/interest.hpp
index f69b855..701c1de 100644
--- a/ndn-cxx/interest.hpp
+++ b/ndn-cxx/interest.hpp
@@ -25,6 +25,7 @@
 #include "ndn-cxx/delegation-list.hpp"
 #include "ndn-cxx/detail/packet-base.hpp"
 #include "ndn-cxx/name.hpp"
+#include "ndn-cxx/signature-info.hpp"
 #include "ndn-cxx/util/string-helper.hpp"
 #include "ndn-cxx/util/time.hpp"
 
@@ -327,6 +328,10 @@
     return !m_parameters.empty();
   }
 
+  /** @brief Get the ApplicationParameters
+   *
+   *  If the element is not present, an invalid Block will be returned.
+   */
   Block
   getApplicationParameters() const
   {
@@ -378,11 +383,46 @@
   /** @brief Remove the ApplicationParameters element from this Interest.
    *  @post hasApplicationParameters() == false
    *
-   *  This function will also remove any ParametersSha256DigestComponents from the Interest's name.
+   *  This function will also remove any InterestSignatureInfo and InterestSignatureValue elements
+   *  in the Interest, as well as any ParametersSha256DigestComponents in the Interest's name.
    */
   Interest&
   unsetApplicationParameters();
 
+  /** @brief Return whether the Interest is signed
+   *  @warning This function only determines whether signature information is present in the
+   *           Interest and does not verify that the signature is valid.
+   */
+  bool
+  isSigned() const noexcept;
+
+  /** @brief Get the InterestSignatureInfo
+   *  @retval nullopt InterestSignatureInfo is not present
+   */
+  optional<SignatureInfo>
+  getSignatureInfo() const;
+
+  /** @brief Set the InterestSignatureInfo
+   */
+  Interest&
+  setSignatureInfo(const SignatureInfo& info);
+
+  /** @brief Get the InterestSignatureValue
+   *
+   *  If the element is not present, an invalid Block will be returned.
+   */
+  Block
+  getSignatureValue() const;
+
+  /** @brief Set the InterestSignatureValue
+   *  @param value Buffer containing the TLV-VALUE of the InterestSignatureValue; must not be nullptr
+   *  @throw Error InterestSignatureInfo is unset
+   *
+   *  InterestSignatureInfo must be set before setting InterestSignatureValue
+   */
+  Interest&
+  setSignatureValue(ConstBufferPtr value);
+
 public: // ParametersSha256DigestComponent support
   static bool
   getAutoCheckParametersDigest()
@@ -432,6 +472,9 @@
   static ssize_t
   findParametersDigestComponent(const Name& name);
 
+  std::vector<Block>::const_iterator
+  findFirstParameter(uint32_t type) const;
+
 #ifdef NDN_CXX_HAVE_TESTS
 public:
   /// If true, not setting CanBePrefix results in an error in wireEncode().
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index 1787b87..abb4280 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -62,6 +62,9 @@
   BOOST_CHECK_EQUAL(i.hasApplicationParameters(), false);
   BOOST_CHECK_EQUAL(i.getApplicationParameters().isValid(), false);
   BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
+  BOOST_CHECK(i.getSignatureInfo() == nullopt);
+  BOOST_CHECK_EQUAL(i.getSignatureValue().isValid(), false);
+  BOOST_CHECK_EQUAL(i.isSigned(), false);
 }
 
 BOOST_AUTO_TEST_SUITE(Encode)
@@ -98,6 +101,9 @@
   BOOST_CHECK(i2.getHopLimit() == nullopt);
   BOOST_CHECK_EQUAL(i2.hasApplicationParameters(), false);
   BOOST_CHECK_EQUAL(i2.getApplicationParameters().isValid(), false);
+  BOOST_CHECK(i2.getSignatureInfo() == nullopt);
+  BOOST_CHECK_EQUAL(i2.getSignatureValue().isValid(), false);
+  BOOST_CHECK_EQUAL(i2.isSigned(), false);
 }
 
 BOOST_AUTO_TEST_CASE(WithParameters)
@@ -140,6 +146,9 @@
   BOOST_CHECK(i2.getHopLimit() == nullopt);
   BOOST_CHECK_EQUAL(i2.hasApplicationParameters(), true);
   BOOST_CHECK_EQUAL(i2.getApplicationParameters(), "2404C0C1C2C3"_block);
+  BOOST_CHECK(i2.getSignatureInfo() == nullopt);
+  BOOST_CHECK_EQUAL(i2.getSignatureValue().isValid(), false);
+  BOOST_CHECK_EQUAL(i2.isSigned(), false);
 }
 
 BOOST_AUTO_TEST_CASE(Full)
@@ -199,6 +208,146 @@
   BOOST_CHECK_EQUAL(i2.getApplicationParameters(), "2404C0C1C2C3"_block);
 }
 
+BOOST_AUTO_TEST_CASE(Signed)
+{
+  const uint8_t WIRE[] = {
+    0x05, 0x77, // Interest
+          0x07, 0x36, // Name
+                0x08, 0x05, // GenericNameComponent
+                      0x6c, 0x6f, 0x63, 0x61, 0x6c,
+                0x08, 0x03, // GenericNameComponent
+                      0x6e, 0x64, 0x6e,
+                0x08, 0x06, // GenericNameComponent
+                      0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
+                0x02, 0x20, // ParametersSha256DigestComponent
+                      0x6f, 0x29, 0x58, 0x60, 0x53, 0xee, 0x9f, 0xcc,
+                      0xd8, 0xa4, 0x22, 0x12, 0x29, 0x25, 0x28, 0x7c,
+                      0x0a, 0x18, 0x43, 0x5f, 0x40, 0x74, 0xc4, 0x0a,
+                      0xbb, 0x0d, 0x5b, 0x30, 0xe4, 0xaa, 0x62, 0x20,
+          0x12, 0x00, // MustBeFresh
+          0x0a, 0x04, // Nonce
+                0x4c, 0x1e, 0xcb, 0x4a,
+          0x24, 0x04, // ApplicationParameters
+                0xc0, 0xc1, 0xc2, 0xc3,
+          0x2c, 0x0d, // InterestSignatureInfo
+                0x1b, 0x01, // SignatureType
+                      0x00,
+                0x26, 0x08, // SignatureNonce
+                      0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+          0x2e, 0x20, // InterestSignatureValue
+                0x12, 0x47, 0x1a, 0xe0, 0xf8, 0x72, 0x3a, 0xc1,
+                0x15, 0x6c, 0x37, 0x0a, 0x38, 0x71, 0x1e, 0xbe,
+                0xbf, 0x28, 0x17, 0xde, 0x9b, 0x2d, 0xd9, 0x4e,
+                0x9b, 0x7e, 0x62, 0xf1, 0x17, 0xb8, 0x76, 0xc1,
+  };
+
+  SignatureInfo si(tlv::DigestSha256);
+  std::vector<uint8_t> nonce{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+  si.setNonce(nonce);
+  Block sv("2E20 12471AE0F8723AC1156C370A38711EBEBF2817DE9B2DD94E9B7E62F117B876C1"_block);
+
+  Interest i1(Block(WIRE, sizeof(WIRE)));
+  BOOST_CHECK_EQUAL(i1.getName(),
+                    "/local/ndn/prefix/params-sha256=6f29586053ee9fccd8a422122925287c0a18435f4074c40abb0d5b30e4aa6220");
+  BOOST_CHECK_EQUAL(i1.getCanBePrefix(), false);
+  BOOST_CHECK_EQUAL(i1.getMustBeFresh(), true);
+  BOOST_CHECK_EQUAL(i1.hasNonce(), true);
+  BOOST_CHECK_EQUAL(i1.getNonce(), 0x4c1ecb4a);
+  BOOST_CHECK_EQUAL(i1.getSignatureInfo()->getSignatureType(), tlv::DigestSha256);
+  BOOST_CHECK(i1.getSignatureInfo()->getNonce() == nonce);
+  BOOST_CHECK_EQUAL_COLLECTIONS(i1.getSignatureValue().begin(), i1.getSignatureValue().end(),
+                                sv.begin(), sv.end());
+  BOOST_CHECK_EQUAL(i1.getApplicationParameters(), "2404C0C1C2C3"_block);
+  BOOST_CHECK_EQUAL(i1.isParametersDigestValid(), true);
+
+  // Reset wire
+  BOOST_CHECK_EQUAL(i1.hasWire(), true);
+  i1.setCanBePrefix(true);
+  i1.setCanBePrefix(false);
+  BOOST_CHECK_EQUAL(i1.hasWire(), false);
+
+  Block wire1 = i1.wireEncode();
+  BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
+
+  Interest i2("/local/ndn/prefix");
+  i2.setCanBePrefix(false);
+  i2.setMustBeFresh(true);
+  i2.setNonce(0x4c1ecb4a);
+  i2.setApplicationParameters("2404C0C1C2C3"_block);
+  i2.setSignatureInfo(si);
+  i2.setSignatureValue(make_shared<Buffer>(sv.value(), sv.value_size()));
+  BOOST_CHECK_EQUAL(i2.isParametersDigestValid(), true);
+
+  Block wire2 = i2.wireEncode();
+  BOOST_CHECK_EQUAL_COLLECTIONS(wire2.begin(), wire2.end(), WIRE, WIRE + sizeof(WIRE));
+}
+
+BOOST_AUTO_TEST_CASE(SignedApplicationElements)
+{
+  const uint8_t WIRE[] = {
+    0x05, 0x8f, // Interest
+          0x07, 0x36, // Name
+                0x08, 0x05, // GenericNameComponent
+                      0x6c, 0x6f, 0x63, 0x61, 0x6c,
+                0x08, 0x03, // GenericNameComponent
+                      0x6e, 0x64, 0x6e,
+                0x08, 0x06, // GenericNameComponent
+                      0x70, 0x72, 0x65, 0x66, 0x69, 0x78,
+                0x02, 0x20, // ParametersSha256DigestComponent
+                      0xbc, 0x36, 0x30, 0xa4, 0xd6, 0x5e, 0x0d, 0xb5,
+                      0x48, 0x3d, 0xfa, 0x0d, 0x28, 0xb3, 0x31, 0x2f,
+                      0xca, 0xc1, 0xd4, 0x41, 0xec, 0x89, 0x61, 0xd4,
+                      0x17, 0x5e, 0x61, 0x75, 0x17, 0x78, 0x10, 0x8e,
+          0x12, 0x00, // MustBeFresh
+          0x0a, 0x04, // Nonce
+                0x4c, 0x1e, 0xcb, 0x4a,
+          0x24, 0x04, // ApplicationParameters
+                0xc0, 0xc1, 0xc2, 0xc3,
+          0xfd, 0x01, 0xfe, 0x08, // Application-specific element (Type 510)
+                0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,
+          0x2c, 0x0d, // InterestSignatureInfo
+                0x1b, 0x01, // SignatureType
+                      0x00,
+                0x26, 0x08, // SignatureNonce
+                      0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+          0x2e, 0x20, // InterestSignatureValue
+                0x12, 0x47, 0x1a, 0xe0, 0xf8, 0x72, 0x3a, 0xc1,
+                0x15, 0x6c, 0x37, 0x0a, 0x38, 0x71, 0x1e, 0xbe,
+                0xbf, 0x28, 0x17, 0xde, 0x9b, 0x2d, 0xd9, 0x4e,
+                0x9b, 0x7e, 0x62, 0xf1, 0x17, 0xb8, 0x76, 0xc1,
+          0xfd, 0x02, 0x00, 0x08, // Application-specific element (Type 512)
+                0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88
+  };
+
+  SignatureInfo si(tlv::DigestSha256);
+  std::vector<uint8_t> nonce{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+  si.setNonce(nonce);
+  Block sv("2E20 12471AE0F8723AC1156C370A38711EBEBF2817DE9B2DD94E9B7E62F117B876C1"_block);
+
+  Interest i1(Block(WIRE, sizeof(WIRE)));
+  BOOST_CHECK_EQUAL(i1.getName(),
+                    "/local/ndn/prefix/params-sha256=bc3630a4d65e0db5483dfa0d28b3312fcac1d441ec8961d4175e61751778108e");
+  BOOST_CHECK_EQUAL(i1.getCanBePrefix(), false);
+  BOOST_CHECK_EQUAL(i1.getMustBeFresh(), true);
+  BOOST_CHECK_EQUAL(i1.hasNonce(), true);
+  BOOST_CHECK_EQUAL(i1.getNonce(), 0x4c1ecb4a);
+  BOOST_CHECK_EQUAL(i1.getSignatureInfo()->getSignatureType(), tlv::DigestSha256);
+  BOOST_CHECK(i1.getSignatureInfo()->getNonce() == nonce);
+  BOOST_CHECK_EQUAL_COLLECTIONS(i1.getSignatureValue().begin(), i1.getSignatureValue().end(),
+                                sv.begin(), sv.end());
+  BOOST_CHECK_EQUAL(i1.getApplicationParameters(), "2404C0C1C2C3"_block);
+  BOOST_CHECK_EQUAL(i1.isParametersDigestValid(), true);
+
+  // Reset wire
+  BOOST_CHECK_EQUAL(i1.hasWire(), true);
+  i1.setCanBePrefix(true);
+  i1.setCanBePrefix(false);
+  BOOST_CHECK_EQUAL(i1.hasWire(), false);
+
+  Block wire1 = i1.wireEncode();
+  BOOST_CHECK_EQUAL_COLLECTIONS(wire1.begin(), wire1.end(), WIRE, WIRE + sizeof(WIRE));
+}
+
 BOOST_AUTO_TEST_CASE(MissingApplicationParameters)
 {
   Interest i;
@@ -745,6 +894,75 @@
   BOOST_CHECK_THROW(i.setApplicationParameters(nullptr), std::invalid_argument);
 }
 
+BOOST_AUTO_TEST_CASE(SetSignature)
+{
+  Interest i;
+  i.setCanBePrefix(false);
+  BOOST_CHECK(i.getSignatureInfo() == nullopt);
+  BOOST_CHECK_EQUAL(i.isSigned(), false);
+
+  // Throws because attempting to set InterestSignatureValue without set InterestSignatureInfo
+  Block sv1("2E04 01020304"_block);
+  auto svBuffer1 = make_shared<Buffer>(sv1.value(), sv1.value_size());
+  BOOST_CHECK_THROW(i.setSignatureValue(svBuffer1), tlv::Error);
+
+  // Simple set/get case for InterestSignatureInfo (no prior set)
+  SignatureInfo si1(tlv::SignatureSha256WithEcdsa);
+  i.setSignatureInfo(si1);
+  BOOST_CHECK(i.getSignatureInfo() == si1);
+  BOOST_CHECK_EQUAL(i.isSigned(), false);
+
+  // Simple set/get case for InterestSignatureValue (no prior set)
+  BOOST_CHECK_EQUAL(i.getSignatureValue().isValid(), false);
+  i.setSignatureValue(svBuffer1);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv1);
+  BOOST_CHECK_EQUAL(i.isSigned(), true);
+
+  // Throws because attempting to set InterestSignatureValue to nullptr
+  BOOST_CHECK_THROW(i.setSignatureValue(nullptr), std::invalid_argument);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv1);
+  BOOST_CHECK_EQUAL(i.isSigned(), true);
+
+  // Ensure that wire is not reset if specified InterestSignatureInfo is same
+  i.wireEncode();
+  BOOST_CHECK_EQUAL(i.hasWire(), true);
+  i.setSignatureInfo(si1);
+  BOOST_CHECK_EQUAL(i.hasWire(), true);
+  BOOST_CHECK(i.getSignatureInfo() == si1);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv1);
+  BOOST_CHECK_EQUAL(i.isSigned(), true);
+
+  // Ensure that wire is reset if specified InterestSignatureInfo is different
+  i.wireEncode();
+  BOOST_CHECK_EQUAL(i.hasWire(), true);
+  SignatureInfo si2(tlv::SignatureSha256WithRsa);
+  i.setSignatureInfo(si2);
+  BOOST_CHECK_EQUAL(i.hasWire(), false);
+  BOOST_CHECK(i.getSignatureInfo() == si2);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv1);
+  BOOST_CHECK_EQUAL(i.isSigned(), true);
+
+  // Ensure that wire is not reset if specified InterestSignatureValue is same
+  i.wireEncode();
+  BOOST_CHECK_EQUAL(i.hasWire(), true);
+  i.setSignatureValue(svBuffer1);
+  BOOST_CHECK_EQUAL(i.hasWire(), true);
+  BOOST_CHECK(i.getSignatureInfo() == si2);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv1);
+  BOOST_CHECK_EQUAL(i.isSigned(), true);
+
+  // Ensure that wire is reset if specified InterestSignatureValue is different
+  i.wireEncode();
+  BOOST_CHECK_EQUAL(i.hasWire(), true);
+  Block sv2("2E04 99887766"_block);
+  auto svBuffer2 = make_shared<Buffer>(sv2.value(), sv2.value_size());
+  i.setSignatureValue(svBuffer2);
+  BOOST_CHECK_EQUAL(i.hasWire(), false);
+  BOOST_CHECK(i.getSignatureInfo() == si2);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv2);
+  BOOST_CHECK_EQUAL(i.isSigned(), true);
+}
+
 BOOST_AUTO_TEST_CASE(ParametersSha256DigestComponent)
 {
   Interest i("/I");
@@ -784,6 +1002,43 @@
                     "/A/B/C/params-sha256=ff9100e04eaadcf30674d98026a051ba25f56b69bfa026dcccd72c6ea0f7315a");
   BOOST_CHECK_EQUAL(i.hasApplicationParameters(), true);
   BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
+
+  SignatureInfo si(tlv::SignatureSha256WithEcdsa);
+  i.setSignatureInfo(si); // updates ParametersSha256DigestComponent
+  BOOST_CHECK_EQUAL(i.getName(),
+                    "/A/B/C/params-sha256=6400cae1730c15fd7854b26be05794d53685423c94bc61e59c49bd640d646ae8");
+  BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
+  BOOST_CHECK_EQUAL(i.getApplicationParameters(), "2404 C0C1C2C3"_block);
+  BOOST_CHECK(i.getSignatureInfo() == si);
+
+  i.unsetApplicationParameters(); // removes ParametersSha256DigestComponent and InterestSignatureInfo
+  BOOST_CHECK(i.getSignatureInfo() == nullopt);
+  BOOST_CHECK_EQUAL(i.getSignatureValue().isValid(), false);
+  BOOST_CHECK_EQUAL(i.getName(), "/A/B/C");
+
+  i.setSignatureInfo(si); // auto-adds an empty ApplicationParameters element
+  BOOST_CHECK_EQUAL(i.getName(),
+                    "/A/B/C/params-sha256=d2ac0eb1f60f60ab206fb80bf1d0f73cfef353bbec43ba6ea626117f671ca3bb");
+  BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
+  BOOST_CHECK_EQUAL(i.getApplicationParameters(), "2400"_block);
+  BOOST_CHECK(i.getSignatureInfo() == si);
+
+  Block sv("2E04 01020304"_block);
+  i.setSignatureValue(make_shared<Buffer>(sv.value(), sv.value_size())); // updates ParametersDigestSha256Component
+  BOOST_CHECK_EQUAL(i.getName(),
+                    "/A/B/C/params-sha256=f649845ef944638390d1c689e2f0618ea02e471eff236110cbeb822d5932d342");
+  BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
+  BOOST_CHECK_EQUAL(i.getApplicationParameters(), "2400"_block);
+  BOOST_CHECK(i.getSignatureInfo() == si);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv);
+
+  i.setApplicationParameters("2404C0C1C2C3"_block); // updates ParametersSha256DigestComponent
+  BOOST_CHECK_EQUAL(i.getName(),
+                    "/A/B/C/params-sha256=c5d7e567e6b251ddf36f7a6dbed95235b2d4a0b36215bb0f3cc403ac64ad0284");
+  BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
+  BOOST_CHECK_EQUAL(i.getApplicationParameters(), "2404 C0C1C2C3"_block);
+  BOOST_CHECK(i.getSignatureInfo() == si);
+  BOOST_CHECK_EQUAL(i.getSignatureValue(), sv);
 }
 
 BOOST_AUTO_TEST_CASE(ToUri)