exclude: allow decoding Exclude containing ImplicitSha256DigestComponent
Change-Id: Ibd598adcd7a96740fe48f19cbb99e5a6e19fe121
Refs: #2629
diff --git a/src/exclude.cpp b/src/exclude.cpp
index b48d245..89d052d 100644
--- a/src/exclude.cpp
+++ b/src/exclude.cpp
@@ -120,10 +120,14 @@
while (i != m_wire.elements_end())
{
- if (i->type() != tlv::NameComponent)
+ name::Component excludedComponent;
+ try {
+ excludedComponent = std::move(name::Component(*i));
+ }
+ catch (const name::Component::Error&) {
throw Error("Incorrect format of Exclude filter");
+ }
- name::Component excludedComponent(i->value(), i->value_size());
++i;
if (i != m_wire.elements_end())
diff --git a/tests/unit-tests/exclude.t.cpp b/tests/unit-tests/exclude.t.cpp
index a211f15..88b692a 100644
--- a/tests/unit-tests/exclude.t.cpp
+++ b/tests/unit-tests/exclude.t.cpp
@@ -189,6 +189,34 @@
// const uint8_t ANY_COMPONENT_ANY[] = { 0x10, 0x07, 0x13, 0x00, 0x08, 0x01, 0x54, 0x13, 0x00 };
// BOOST_CHECK_THROW(e2.wireDecode(Block(ANY_COMPONENT_ANY, sizeof(ANY_COMPONENT_ANY))),
// Exclude::Error);
+
+ uint8_t WIRE[] = {
+ 0x10, 0x20, // Exclude
+ 0x01, 0x1E, // ImplicitSha256DigestComponent with incorrect length
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd
+ };
+
+ BOOST_CHECK_THROW(Exclude().wireDecode(Block(WIRE, sizeof(WIRE))), Exclude::Error);
+}
+
+BOOST_AUTO_TEST_CASE(ImplicitSha256Digest)
+{
+ uint8_t WIRE[] = {
+ 0x10, 0x22, // Exclude
+ 0x01, 0x20, // ImplicitSha256DigestComponent
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
+ 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd
+ };
+
+ Block block(WIRE, sizeof(WIRE));
+
+ Exclude exclude;
+ BOOST_CHECK_NO_THROW(exclude.wireDecode(block));
}
BOOST_AUTO_TEST_SUITE_END()