Browse Source

Fix hash function comparator

Tatsuhiro Tsujikawa 11 years ago
parent
commit
c0b8b471ab
2 changed files with 5 additions and 2 deletions
  1. 4 1
      src/MessageDigest.cc
  2. 1 1
      test/MessageDigestTest.cc

+ 4 - 1
src/MessageDigest.cc

@@ -135,9 +135,12 @@ bool MessageDigest::isStronger(const std::string& lhs, const std::string& rhs)
                              FindHashTypeEntry(lhs));
   auto rEntry = std::find_if(std::begin(hashTypes), std::end(hashTypes),
                              FindHashTypeEntry(rhs));
-  if(lEntry == std::end(hashTypes) || rEntry == std::end(hashTypes)) {
+  if(lEntry == std::end(hashTypes)) {
     return false;
   }
+  if(rEntry == std::end(hashTypes)) {
+    return true;
+  }
   return lEntry->strength > rEntry->strength;
 }
 

+ 1 - 1
test/MessageDigestTest.cc

@@ -76,7 +76,7 @@ void MessageDigestTest::testIsStronger()
   CPPUNIT_ASSERT(MessageDigest::isStronger("sha-1", "md5"));
   CPPUNIT_ASSERT(!MessageDigest::isStronger("md5", "sha-1"));
   CPPUNIT_ASSERT(!MessageDigest::isStronger("unknown", "sha-1"));
-  CPPUNIT_ASSERT(!MessageDigest::isStronger("sha-1", "unknown"));
+  CPPUNIT_ASSERT(MessageDigest::isStronger("sha-1", "unknown"));
 }
 
 void MessageDigestTest::testIsValidHash()