in src/native/diffs/core/item_definition.cpp [172:220]
item_definition::match_result item_definition::match(const item_definition &rhs) const
{
auto result = match_result::uncertain;
if (m_length != rhs.m_length)
{
return match_result::no_match;
}
for (auto algorithm : hashing::all_algorithms)
{
bool left_has_hash = m_hashes.count(algorithm) > 0;
bool right_has_hash = rhs.m_hashes.count(algorithm) > 0;
if (!left_has_hash && !right_has_hash)
{
continue;
}
if (!right_has_hash)
{
continue;
}
else if (!left_has_hash)
{
continue;
}
auto left_hash = &m_hashes.find(algorithm)->second;
auto right_hash = &rhs.m_hashes.find(algorithm)->second;
// ok, both have this hash, compare the bytes
if (left_hash->m_hash_data.size() != right_hash->m_hash_data.size())
{
throw errors::user_exception(errors::error_code::item_definition_hash_size_mismatch);
}
auto cmp =
std::memcmp(left_hash->m_hash_data.data(), right_hash->m_hash_data.data(), right_hash->m_hash_data.size());
if (cmp != 0)
{
return match_result::no_match;
}
result = match_result::match;
}
return result;
}