]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | // libs/uuid/test/test_md5.cpp --------------------------------// |
2 | ||
3 | // (C) Copyright 2017 James E. King, III | |
4 | ||
5 | // Distributed under the Boost Software License, Version 1.0. (See | |
6 | // accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | #include <boost/cstdint.hpp> | |
10 | #include <boost/detail/lightweight_test.hpp> | |
11 | #include <boost/uuid/detail/md5.hpp> | |
12 | ||
13 | int main(int, char**) | |
14 | { | |
15 | typedef struct | |
16 | { | |
17 | const char * data; | |
18 | boost::uint32_t len; | |
19 | unsigned char expected[16]; | |
20 | } Expectation; | |
21 | ||
22 | /* http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/ */ | |
23 | Expectation expectations[3] = { | |
24 | { "The quick brown fox jumps over the lazy dog", 43, | |
25 | { 0x9e, 0x10, 0x7d, 0x9d, 0x37, 0x2b, 0xb6, 0x82, | |
26 | 0x6b, 0xd8, 0x1d, 0x35, 0x42, 0xa4, 0x19, 0xd6 }}, | |
27 | { "Test vector from febooti.com", 28, | |
28 | { 0x50, 0x0a, 0xb6, 0x61, 0x3c, 0x6d, 0xb7, 0xfb, | |
29 | 0xd3, 0x0c, 0x62, 0xf5, 0xff, 0x57, 0x3d, 0x0f }}, | |
30 | { "", 0, | |
31 | { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, | |
32 | 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e }} | |
33 | }; | |
34 | ||
35 | for (boost::uint32_t i = 0; i < 3; ++i) { | |
36 | boost::uuids::detail::md5 hash; | |
37 | hash.process_bytes(expectations[i].data, expectations[i].len); | |
38 | boost::uuids::detail::md5::digest_type result; | |
39 | hash.get_digest(result); | |
40 | BOOST_TEST_EQ(0, memcmp(result, expectations[i].expected, | |
41 | sizeof(boost::uuids::detail::md5::digest_type))); | |
42 | BOOST_TEST_EQ(hash.get_version(), 0x03); | |
43 | ||
44 | } | |
45 | ||
46 | return boost::report_errors(); | |
47 | } |