1 | // |
---|---|
2 | // SHA1EngineTest.cpp |
3 | // |
4 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
5 | // and Contributors. |
6 | // |
7 | // SPDX-License-Identifier: BSL-1.0 |
8 | // |
9 | |
10 | |
11 | #include "SHA1EngineTest.h" |
12 | #include "Poco/CppUnit/TestCaller.h" |
13 | #include "Poco/CppUnit/TestSuite.h" |
14 | #include "Poco/SHA1Engine.h" |
15 | |
16 | |
17 | using Poco::SHA1Engine; |
18 | using Poco::DigestEngine; |
19 | |
20 | |
21 | SHA1EngineTest::SHA1EngineTest(const std::string& rName): CppUnit::TestCase(rName) |
22 | { |
23 | } |
24 | |
25 | |
26 | SHA1EngineTest::~SHA1EngineTest() |
27 | { |
28 | } |
29 | |
30 | |
31 | void SHA1EngineTest::testSHA1() |
32 | { |
33 | SHA1Engine engine; |
34 | |
35 | // test vectors from FIPS 180-1 |
36 | |
37 | engine.update("abc"); |
38 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "a9993e364706816aba3e25717850c26c9cd0d89d"); |
39 | |
40 | engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); |
41 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "84983e441c3bd26ebaae4aa1f95129e5e54670f1"); |
42 | |
43 | for (int i = 0; i < 1000000; ++i) |
44 | engine.update('a'); |
45 | assertTrue (DigestEngine::digestToHex(engine.digest()) == "34aa973cd4c4daa4f61eeb2bdbad27316534016f"); |
46 | } |
47 | |
48 | |
49 | void SHA1EngineTest::setUp() |
50 | { |
51 | } |
52 | |
53 | |
54 | void SHA1EngineTest::tearDown() |
55 | { |
56 | } |
57 | |
58 | |
59 | CppUnit::Test* SHA1EngineTest::suite() |
60 | { |
61 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SHA1EngineTest"); |
62 | |
63 | CppUnit_addTest(pSuite, SHA1EngineTest, testSHA1); |
64 | |
65 | return pSuite; |
66 | } |
67 |