From 850148f77582cf9b87e06563d62c4ec0021eac08 Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Wed, 12 Mar 2014 14:05:44 +0100 Subject: [PATCH] Add SHA1 test for Poco::Crypto::DigestEngine --- Crypto/testsuite/src/DigestEngineTest.cpp | 17 +++++++++++++++++ Crypto/testsuite/src/DigestEngineTest.h | 1 + 2 files changed, 18 insertions(+) diff --git a/Crypto/testsuite/src/DigestEngineTest.cpp b/Crypto/testsuite/src/DigestEngineTest.cpp index bc7e150d8..ed3be1688 100644 --- a/Crypto/testsuite/src/DigestEngineTest.cpp +++ b/Crypto/testsuite/src/DigestEngineTest.cpp @@ -78,6 +78,22 @@ void DigestEngineTest::testMD5() assert (DigestEngine::digestToHex(engine.digest()) == "57edf4a22be3c955ac49da2e2107b67a"); } +void DigestEngineTest::testSHA1() +{ + DigestEngine engine("SHA1"); + + // test vectors from FIPS 180-1 + + engine.update("abc"); + assert (DigestEngine::digestToHex(engine.digest()) == "a9993e364706816aba3e25717850c26c9cd0d89d"); + + engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); + assert (DigestEngine::digestToHex(engine.digest()) == "84983e441c3bd26ebaae4aa1f95129e5e54670f1"); + + for (int i = 0; i < 1000000; ++i) + engine.update('a'); + assert (DigestEngine::digestToHex(engine.digest()) == "34aa973cd4c4daa4f61eeb2bdbad27316534016f"); +} void DigestEngineTest::setUp() { @@ -94,6 +110,7 @@ CppUnit::Test* DigestEngineTest::suite() CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DigestEngineTest"); CppUnit_addTest(pSuite, DigestEngineTest, testMD5); + CppUnit_addTest(pSuite, DigestEngineTest, testSHA1); return pSuite; } diff --git a/Crypto/testsuite/src/DigestEngineTest.h b/Crypto/testsuite/src/DigestEngineTest.h index 24206436b..9872f6a59 100644 --- a/Crypto/testsuite/src/DigestEngineTest.h +++ b/Crypto/testsuite/src/DigestEngineTest.h @@ -47,6 +47,7 @@ public: ~DigestEngineTest(); void testMD5(); + void testSHA1(); void setUp(); void tearDown();