signature: disallow encoding invalid SignatureInfo
Also, check integer range when decoding SignatureInfo.
refs #3200
Change-Id: I1af4833211c9468ac7ecab48f7d0e88e9423b378
diff --git a/src/signature.cpp b/src/signature.cpp
index 3683449..4ac9d59 100644
--- a/src/signature.cpp
+++ b/src/signature.cpp
@@ -40,6 +40,15 @@
{
}
+tlv::SignatureTypeValue
+Signature::getType() const
+{
+ if (!*this) {
+ BOOST_THROW_EXCEPTION(Error("Signature is invalid"));
+ }
+ return static_cast<tlv::SignatureTypeValue>(m_info.getSignatureType());
+}
+
void
Signature::setInfo(const Block& info)
{
@@ -55,4 +64,10 @@
m_value = value;
}
+bool
+operator==(const Signature& lhs, const Signature& rhs)
+{
+ return lhs.getSignatureInfo() == rhs.getSignatureInfo() && lhs.getValue() == rhs.getValue();
+}
+
} // namespace ndn