• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2019 James E. King III
3 //
4 // Permission to copy, use, modify, sell and
5 // distribute this software is granted provided this copyright notice appears
6 // in all copies. This software is provided "as is" without express or implied
7 // warranty, and with no claim as to its suitability for any purpose.
8 //
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // https://www.boost.org/LICENSE_1_0.txt)
12 //
13 
14 #ifndef BOOST_UUID_TEST_ENDIAN_2019
15 #define BOOST_UUID_TEST_ENDIAN_2019
16 
17 #include <boost/predef/other/endian.h>
18 
19 namespace boost {
20 namespace uuids {
21 namespace test {
22 
23 //
24 // A utility to copy a raw digest out from one of the detail hash functions
25 // to a byte string for comparisons in testing to known values.
26 //
copy_raw_digest(unsigned char * out,const unsigned int * in,size_t inlen)27 static void copy_raw_digest(unsigned char* out, const unsigned int *in, size_t inlen)
28 {
29     for (size_t chunk = 0; chunk < inlen; ++chunk)
30     {
31         const unsigned char * cin = reinterpret_cast<const unsigned char *>(&in[chunk]);
32         for (size_t byte = 0; byte < 4; ++byte)
33         {
34 #if BOOST_ENDIAN_LITTLE_BYTE
35             *out++ = *(cin + (3-byte));
36 #else
37             *out++ = *(cin + byte);
38 #endif
39         }
40     }
41 }
42 
43 //
44 // A utility to compare and report two raw hashes
45 //
test_digest_equal_array(char const * file,int line,char const * function,const unsigned char * lhs,const unsigned char * rhs,size_t len)46 static void test_digest_equal_array(char const * file, int line, char const * function,
47                              const unsigned char *lhs,
48                              const unsigned char *rhs,
49                              size_t len)
50 {
51     for (size_t i=0; i<len; i++) {
52         if ( lhs[i] != rhs[i]) {
53             std::cerr << file << "(" << line << "): digest [";
54             for (size_t l=0; l<len; l++) {
55                 std::cerr << std::hex << (int)lhs[l];
56             }
57 
58             std::cerr << "] not equal [";
59             for (size_t r=0; r<len; r++) {
60                 std::cerr << std::hex << (int)rhs[r];
61             }
62             std::cerr << "] in function '" << function << "'" << std::endl;
63             ++boost::detail::test_errors();
64             return;
65         }
66     }
67 }
68 
69 }
70 }
71 }
72 
73 #endif
74