OLD | NEW |
| (Empty) |
1 // Copyright 2004-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // MD5 unittest | |
16 | |
17 #include <atlstr.h> | |
18 #include "omaha/base/debug.h" | |
19 #include "omaha/base/md5.h" | |
20 #include "omaha/base/string.h" | |
21 #include "omaha/testing/unit_test.h" | |
22 | |
23 namespace omaha { | |
24 | |
25 void CheckMD5 (char *string, TCHAR *correct_digest) { | |
26 ASSERT_TRUE(correct_digest); | |
27 ASSERT_TRUE(string); | |
28 | |
29 MD5_CTX context; | |
30 MD5Init (&context); | |
31 MD5Update (&context, (unsigned char *)string, strlen (string)); | |
32 unsigned char digest[16]; | |
33 MD5Final (digest, &context); | |
34 | |
35 const DWORD digest_len = 32+1; | |
36 TCHAR digest_string[digest_len]; | |
37 digest_string[31] = '\0'; | |
38 digest_string[0] = '\0'; | |
39 | |
40 for (int i = 0; i < 16; i++) { | |
41 SafeStrCat (digest_string, SPRINTF (_T("%02x"), digest[i]), digest_len); | |
42 } | |
43 | |
44 ASSERT_STREQ(digest_string, correct_digest); | |
45 } | |
46 | |
47 TEST(Md5Test, MD5) { | |
48 CheckMD5 ("", _T("d41d8cd98f00b204e9800998ecf8427e")); | |
49 CheckMD5 ("a", _T("0cc175b9c0f1b6a831c399e269772661")); | |
50 CheckMD5 ("abc", _T("900150983cd24fb0d6963f7d28e17f72")); | |
51 CheckMD5 ("message digest", _T("f96b697d7cb7938d525a2f31aaf161d0")); | |
52 CheckMD5 ("abcdefghijklmnopqrstuvwxyz", _T("c3fcd3d76192e4007dfb496cca67e13b
")); | |
53 CheckMD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
_T("d174ab98d277d9f5a5611c2c9f419d9f")); | |
54 CheckMD5 ("12345678901234567890123456789012345678901234567890123456789012345
678901234567890", _T("57edf4a22be3c955ac49da2e2107b67a")); | |
55 } | |
56 | |
57 } // namespace omaha | |
58 | |
OLD | NEW |