Safe overloading with std::equal
Since C++20, there is a safer way to overload std::equal:
template< class InputIt1, class InputIt2 >
constexpr bool equal( InputIt1 first1, InputIt1 last1,
InputIt2 first2, InputIt2 last2 );
Because if they are different lengths, it won't run past on either
side. In theory, they should always be the same length.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I1d25331521c1590b5f448f93b657f58f9f06d778
diff --git a/integrity_algo.cpp b/integrity_algo.cpp
index 43035dc..dc87625 100644
--- a/integrity_algo.cpp
+++ b/integrity_algo.cpp
@@ -41,14 +41,16 @@
bool AlgoSHA1::verifyIntegrityData(
const std::vector<uint8_t>& packet, const size_t length,
- std::vector<uint8_t>::const_iterator integrityData) const
+ std::vector<uint8_t>::const_iterator integrityDataBegin,
+ std::vector<uint8_t>::const_iterator integrityDataEnd) const
{
auto output = generateHMAC(
packet.data() + message::parser::RMCP_SESSION_HEADER_SIZE, length);
// Verify if the generated integrity data for the packet and the received
// integrity data matches.
- return (std::equal(output.begin(), output.end(), integrityData));
+ return (std::equal(output.begin(), output.end(), integrityDataBegin,
+ integrityDataEnd));
}
std::vector<uint8_t>
@@ -105,14 +107,16 @@
bool AlgoSHA256::verifyIntegrityData(
const std::vector<uint8_t>& packet, const size_t length,
- std::vector<uint8_t>::const_iterator integrityData) const
+ std::vector<uint8_t>::const_iterator integrityDataBegin,
+ std::vector<uint8_t>::const_iterator integrityDataEnd) const
{
auto output = generateHMAC(
packet.data() + message::parser::RMCP_SESSION_HEADER_SIZE, length);
// Verify if the generated integrity data for the packet and the received
// integrity data matches.
- return (std::equal(output.begin(), output.end(), integrityData));
+ return (std::equal(output.begin(), output.end(), integrityDataBegin,
+ integrityDataEnd));
}
std::vector<uint8_t>