Add internal md5 and sha1 message digests

This commit is contained in:
Nils Maier 2013-09-20 22:39:33 +02:00
parent a1deb0e9f1
commit 38bdea4e06
9 changed files with 679 additions and 1 deletions

View file

@ -18,9 +18,11 @@ class MessageDigestTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
std::unique_ptr<MessageDigest> sha1_;
std::unique_ptr<MessageDigest> md5_;
public:
void setUp()
{
md5_ = MessageDigest::create("md5");
sha1_ = MessageDigest::sha1();
}
@ -37,6 +39,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MessageDigestTest );
void MessageDigestTest::testDigest()
{
md5_->update("aria2", 5);
CPPUNIT_ASSERT_EQUAL(std::string("2c90cadbef42945f0dcff2b959977ff8"),
util::toHex(md5_->digest()));
sha1_->update("aria2", 5);
CPPUNIT_ASSERT_EQUAL(std::string("f36003f22b462ffa184390533c500d8989e9f681"),
util::toHex(sha1_->digest()));
@ -44,6 +50,7 @@ void MessageDigestTest::testDigest()
void MessageDigestTest::testSupports()
{
CPPUNIT_ASSERT(MessageDigest::supports("md5"));
CPPUNIT_ASSERT(MessageDigest::supports("sha-1"));
// Fails because sha1 is not valid name.
CPPUNIT_ASSERT(!MessageDigest::supports("sha1"));
@ -51,6 +58,7 @@ void MessageDigestTest::testSupports()
void MessageDigestTest::testGetDigestLength()
{
CPPUNIT_ASSERT_EQUAL((size_t)16, MessageDigest::getDigestLength("md5"));
CPPUNIT_ASSERT_EQUAL((size_t)20, MessageDigest::getDigestLength("sha-1"));
CPPUNIT_ASSERT_EQUAL((size_t)20, sha1_->getDigestLength());
}