encoding: avoid UB when casting to tlv::SignatureTypeValue
Change-Id: I52ec0bef8527b6a52208dc07be75e790e504c47e
Refs: #4370
diff --git a/tests/unit-tests/encoding/tlv.t.cpp b/tests/unit-tests/encoding/tlv.t.cpp
index 52b46ad..6a14c68 100644
--- a/tests/unit-tests/encoding/tlv.t.cpp
+++ b/tests/unit-tests/encoding/tlv.t.cpp
@@ -469,17 +469,10 @@
BOOST_AUTO_TEST_CASE(PrintSignatureTypeValue)
{
- SignatureTypeValue value = DigestSha256;
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(value), "DigestSha256");
-
- value = SignatureSha256WithRsa;
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(value), "SignatureSha256WithRsa");
-
- value = SignatureSha256WithEcdsa;
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(value), "SignatureSha256WithEcdsa");
-
- value = static_cast<SignatureTypeValue>(-1);
- BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(value), "Unknown Signature Type");
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(DigestSha256), "DigestSha256");
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(SignatureSha256WithRsa), "SignatureSha256WithRsa");
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(SignatureSha256WithEcdsa), "SignatureSha256WithEcdsa");
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<SignatureTypeValue>(200)), "Unknown Signature Type");
}
BOOST_AUTO_TEST_SUITE_END() // PrintHelpers
diff --git a/tests/unit-tests/security/signing-info.t.cpp b/tests/unit-tests/security/signing-info.t.cpp
index 2b40a09..9a64a53 100644
--- a/tests/unit-tests/security/signing-info.t.cpp
+++ b/tests/unit-tests/security/signing-info.t.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -191,12 +191,12 @@
info2 = SigningInfo("id:/my-id");
info1.setDigestAlgorithm(DigestAlgorithm::SHA256);
info2.setDigestAlgorithm(DigestAlgorithm::SHA256);
- SignatureInfo sigInfo1(tlv::SignatureTypeValue::DigestSha256);
+ SignatureInfo sigInfo1(tlv::DigestSha256);
info1.setSignatureInfo(sigInfo1);
info2.setSignatureInfo(sigInfo1);
BOOST_CHECK_EQUAL(info1, info2);
// Change signature info, check inequality
- SignatureInfo sigInfo2(tlv::SignatureTypeValue::SignatureSha256WithRsa);
+ SignatureInfo sigInfo2(tlv::SignatureSha256WithRsa);
info2.setSignatureInfo(sigInfo2);
BOOST_CHECK_NE(info1, info2);
}
diff --git a/tests/unit-tests/signature-info.t.cpp b/tests/unit-tests/signature-info.t.cpp
index 828bcf8..9ca9cff 100644
--- a/tests/unit-tests/signature-info.t.cpp
+++ b/tests/unit-tests/signature-info.t.cpp
@@ -50,6 +50,8 @@
BOOST_CHECK_EQUAL(info.hasKeyLocator(), false);
BOOST_CHECK_THROW(info.getKeyLocator(), SignatureInfo::Error);
+ BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(info), "Invalid SignatureInfo");
+
SignatureInfo sha256Info(tlv::DigestSha256);
BOOST_CHECK_EQUAL(sha256Info.getSignatureType(), tlv::DigestSha256);
BOOST_CHECK_EQUAL(sha256Info.hasKeyLocator(), false);