Commit | Line | Data |
---|---|---|
69d568dd TC |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
20 | /** | |
21 | tests for the module "crypto" | |
22 | ||
23 | @copyright Intra2net AG | |
24 | */ | |
25 | #define BOOST_TEST_DYN_LINK | |
26 | #include <boost/test/unit_test.hpp> | |
27 | #include <vector> | |
28 | #include <tmpfstream.hpp> | |
29 | #include <iostream> | |
30 | #include <fstream> | |
31 | #include <string> | |
32 | ||
33 | #include "crypto.hxx" | |
34 | ||
35 | using namespace std; | |
36 | using namespace I2n; | |
37 | ||
38 | ||
39 | class TestCryptoFixture | |
40 | { | |
41 | protected: | |
42 | ||
d87beebd | 43 | string Filename; |
69d568dd TC |
44 | |
45 | tmpfstream Tempfile; | |
46 | ||
47 | void write_tempfile() | |
48 | { | |
49 | string tmpfile_name = "/tmp/libi2ncommon_test_crypto_XXXXXX"; | |
50 | Tempfile.open(tmpfile_name); | |
51 | Tempfile << "Long Data and or Password"; | |
52 | Tempfile.close(); | |
53 | ||
d87beebd | 54 | Filename = Tempfile.get_tmp_filename(); |
69d568dd TC |
55 | } |
56 | ||
57 | public: | |
58 | TestCryptoFixture() | |
59 | { | |
60 | write_tempfile(); | |
61 | } | |
62 | ||
63 | ~TestCryptoFixture() | |
64 | { | |
65 | Tempfile.unlink(); | |
66 | } | |
67 | }; | |
68 | ||
69 | BOOST_FIXTURE_TEST_SUITE(Crypto, TestCryptoFixture) | |
70 | ||
71 | BOOST_AUTO_TEST_CASE(CheckHashMD5) | |
72 | { | |
73 | const string hash = hash_data("Long Data and or Password", | |
74 | MD5); | |
75 | BOOST_CHECK_EQUAL(hash, string("E5952C81BBD04F9CB748433B9431F674")); | |
76 | } | |
77 | ||
78 | BOOST_AUTO_TEST_CASE(CheckHashSHA1) | |
79 | { | |
80 | const string hash = hash_data("Long Data and or Password", | |
81 | SHA1); | |
82 | BOOST_CHECK_EQUAL(hash, string("5935A22DAA087672FE2EA0E4485D58BC77E6068D")); | |
83 | } | |
84 | ||
85 | BOOST_AUTO_TEST_CASE(CheckHashSHA256) | |
86 | { | |
87 | const string hash = hash_data("Long Data and or Password", | |
88 | SHA256); | |
89 | BOOST_CHECK_EQUAL(hash, string("6D7F287A7E01ADF1A66C19D61C8D5A3BD68C1F" | |
90 | "10565A6D37A5920B09152D62CE")); | |
91 | } | |
92 | ||
93 | BOOST_AUTO_TEST_CASE(CheckHashSHA384) | |
94 | { | |
95 | const string hash = hash_data("Long Data and or Password", | |
96 | SHA384); | |
97 | BOOST_CHECK_EQUAL(hash, string("1D879CCDFF4E50C32318A1F0FB8AF8A0B" | |
98 | "150432CECAF41E5C7C0C75688E1F776" | |
99 | "14CA70407A9BC97FDD1CEC4CF291B66B")); | |
100 | } | |
101 | ||
102 | BOOST_AUTO_TEST_CASE(CheckHashSHA512) | |
103 | { | |
104 | const string hash = hash_file(Filename, | |
105 | SHA512); | |
106 | BOOST_CHECK_EQUAL(hash, string("CBD561B4D1E13C08672CBCCAC855FAC3F4" | |
107 | "7672548D0B61B0BB201017E4D93B239E" | |
108 | "969DB3588F1466F34FB27A7D0AEFE203" | |
109 | "594808E16659BEDD4B25F34EC46CDB")); | |
110 | } | |
111 | ||
112 | BOOST_AUTO_TEST_CASE(CheckHashFileMD5) | |
113 | { | |
114 | const string hash = hash_file(Filename, | |
115 | MD5); | |
116 | BOOST_CHECK_EQUAL(hash, string("E5952C81BBD04F9CB748433B9431F674")); | |
117 | } | |
118 | ||
119 | BOOST_AUTO_TEST_CASE(CheckHashFileSHA1) | |
120 | { | |
121 | const string hash = hash_file(Filename, | |
122 | SHA1); | |
123 | BOOST_CHECK_EQUAL(hash, string("5935A22DAA087672FE2EA0E4485D58BC77E6068D")); | |
124 | } | |
125 | ||
126 | BOOST_AUTO_TEST_CASE(CheckHashFileSHA256) | |
127 | { | |
128 | const string hash = hash_file(Filename, | |
129 | SHA256); | |
130 | BOOST_CHECK_EQUAL(hash, string("6D7F287A7E01ADF1A66C19D61C8D5A3BD68C1F" | |
131 | "10565A6D37A5920B09152D62CE")); | |
132 | } | |
133 | ||
134 | BOOST_AUTO_TEST_CASE(CheckHashFileSHA384) | |
135 | { | |
136 | const string hash = hash_file(Filename, | |
137 | SHA384); | |
138 | BOOST_CHECK_EQUAL(hash, string("1D879CCDFF4E50C32318A1F0FB8AF8A0B" | |
139 | "150432CECAF41E5C7C0C75688E1F776" | |
140 | "14CA70407A9BC97FDD1CEC4CF291B66B")); | |
141 | } | |
142 | ||
143 | BOOST_AUTO_TEST_CASE(CheckHashFileSHA512) | |
144 | { | |
145 | const string hash = hash_file(Filename, | |
146 | SHA512); | |
147 | BOOST_CHECK_EQUAL(hash, string("CBD561B4D1E13C08672CBCCAC855FAC3F4" | |
148 | "7672548D0B61B0BB201017E4D93B239E" | |
149 | "969DB3588F1466F34FB27A7D0AEFE203" | |
150 | "594808E16659BEDD4B25F34EC46CDB")); | |
151 | } | |
152 | ||
153 | BOOST_AUTO_TEST_SUITE_END() |