comparison 3rdparty/vmime/tests/security/digest/md5Test.cpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library. Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23
24 #include "tests/testUtils.hpp"
25
26 #include "vmime/security/digest/messageDigestFactory.hpp"
27
28
29 #define INIT_DIGEST(var, algo) \
30 vmime::shared_ptr <vmime::security::digest::messageDigest> var = \
31 vmime::security::digest::messageDigestFactory::getInstance()->create(algo)
32
33
34
35 VMIME_TEST_SUITE_BEGIN(md5Test)
36
37 VMIME_TEST_LIST_BEGIN
38 VMIME_TEST(testRFC1321_1)
39 VMIME_TEST(testRFC1321_2)
40 VMIME_TEST(testRFC1321_3)
41 VMIME_TEST(testRFC1321_4)
42 VMIME_TEST(testRFC1321_5)
43 VMIME_TEST(testRFC1321_6)
44 VMIME_TEST(testRFC1321_7)
45 VMIME_TEST(testUpdate1)
46 VMIME_TEST(testUpdate2)
47 VMIME_TEST(testUpdate3)
48 VMIME_TEST(testUpdate4)
49 VMIME_TEST(testUpdate5)
50 VMIME_TEST(testUpdate6)
51 VMIME_TEST(testUpdate7)
52 VMIME_TEST_LIST_END
53
54
55 // Test suites from RFC #1321
56
57 void testRFC1321_1()
58 {
59 INIT_DIGEST(algo, "md5");
60
61 algo->update("");
62 algo->finalize();
63
64 VASSERT_EQ("*", "d41d8cd98f00b204e9800998ecf8427e", algo->getHexDigest());
65 }
66
67 void testRFC1321_2()
68 {
69 INIT_DIGEST(algo, "md5");
70
71 algo->update("a");
72 algo->finalize();
73
74 VASSERT_EQ("*", "0cc175b9c0f1b6a831c399e269772661", algo->getHexDigest());
75 }
76
77 void testRFC1321_3()
78 {
79 INIT_DIGEST(algo, "md5");
80
81 algo->update("abc");
82 algo->finalize();
83
84 VASSERT_EQ("*", "900150983cd24fb0d6963f7d28e17f72", algo->getHexDigest());
85 }
86
87 void testRFC1321_4()
88 {
89 INIT_DIGEST(algo, "md5");
90
91 algo->update("message digest");
92 algo->finalize();
93
94 VASSERT_EQ("*", "f96b697d7cb7938d525a2f31aaf161d0", algo->getHexDigest());
95 }
96
97 void testRFC1321_5()
98 {
99 INIT_DIGEST(algo, "md5");
100
101 algo->update("abcdefghijklmnopqrstuvwxyz");
102 algo->finalize();
103
104 VASSERT_EQ("*", "c3fcd3d76192e4007dfb496cca67e13b", algo->getHexDigest());
105 }
106
107 void testRFC1321_6()
108 {
109 INIT_DIGEST(algo, "md5");
110
111 algo->update("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
112 algo->finalize();
113
114 VASSERT_EQ("*", "d174ab98d277d9f5a5611c2c9f419d9f", algo->getHexDigest());
115 }
116
117 void testRFC1321_7()
118 {
119 INIT_DIGEST(algo, "md5");
120
121 algo->update("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
122 algo->finalize();
123
124 VASSERT_EQ("*", "57edf4a22be3c955ac49da2e2107b67a", algo->getHexDigest());
125 }
126
127 void testReset()
128 {
129 INIT_DIGEST(algo, "md5");
130
131 algo->update("foo");
132 algo->update("bar");
133 algo->finalize();
134
135 algo->reset();
136 algo->finalize();
137
138 VASSERT_EQ("*", "d41d8cd98f00b204e9800998ecf8427e", algo->getHexDigest()); // empty string
139 }
140
141 void testUpdate1()
142 {
143 INIT_DIGEST(algo, "md5");
144
145 algo->update("");
146 algo->finalize();
147
148 VASSERT_EQ("*", "d41d8cd98f00b204e9800998ecf8427e", algo->getHexDigest());
149 }
150
151 void testUpdate2()
152 {
153 INIT_DIGEST(algo, "md5");
154
155 algo->update("a");
156 algo->update("");
157 algo->finalize();
158
159 VASSERT_EQ("2", "0cc175b9c0f1b6a831c399e269772661", algo->getHexDigest());
160 }
161
162 void testUpdate3()
163 {
164 INIT_DIGEST(algo, "md5");
165
166 algo->update("ab");
167 algo->update("c");
168 algo->finalize();
169
170 VASSERT_EQ("3", "900150983cd24fb0d6963f7d28e17f72", algo->getHexDigest());
171 }
172
173 void testUpdate4()
174 {
175 INIT_DIGEST(algo, "md5");
176
177 algo->update("");
178 algo->update("message");
179 algo->update(" ");
180 algo->update("digest");
181 algo->finalize();
182
183 VASSERT_EQ("4", "f96b697d7cb7938d525a2f31aaf161d0", algo->getHexDigest());
184 }
185
186 void testUpdate5()
187 {
188 INIT_DIGEST(algo, "md5");
189
190 algo->update("abcd");
191 algo->update("");
192 algo->update("efghijklmnop");
193 algo->update("qrstuvwx");
194 algo->update("yz");
195 algo->finalize();
196
197 VASSERT_EQ("5", "c3fcd3d76192e4007dfb496cca67e13b", algo->getHexDigest());
198 }
199
200 void testUpdate6()
201 {
202 INIT_DIGEST(algo, "md5");
203
204 algo->update("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012");
205 algo->update("345");
206 algo->update("6");
207 algo->update("7");
208 algo->update("89");
209 algo->finalize();
210
211 VASSERT_EQ("6", "d174ab98d277d9f5a5611c2c9f419d9f", algo->getHexDigest());
212 }
213
214 void testUpdate7()
215 {
216 INIT_DIGEST(algo, "md5");
217
218 algo->update("12345678901234567890123456789");
219 algo->update("01234567890123456789012345678901");
220 algo->update("234567890123456789");
221 algo->update("");
222 algo->update("0");
223 algo->finalize();
224
225 VASSERT_EQ("7", "57edf4a22be3c955ac49da2e2107b67a", algo->getHexDigest());
226 }
227
228 VMIME_TEST_SUITE_END
229