comparison OrthancFramework/Sources/Toolbox.cpp @ 5813:2b429588de28

fix support for Boost 1.86
author Alain Mazy <am@orthanc.team>
date Wed, 25 Sep 2024 16:27:07 +0200
parents 16df20505710
children 122fd5f97d39
comparison
equal deleted inserted replaced
5806:16df20505710 5813:2b429588de28
810 if (size > 0) 810 if (size > 0)
811 { 811 {
812 sha1.process_bytes(data, size); 812 sha1.process_bytes(data, size);
813 } 813 }
814 814
815 #if BOOST_VERSION >= 108600
816 unsigned char digest[20];
817
818 // Sanity check for the memory layout: A SHA-1 digest is 160 bits wide
819 assert(sizeof(digest) == (160 / 8));
820 assert(sizeof(boost::uuids::detail::sha1::digest_type) == 20);
821
822 // From Boost 1.86, digest_type is "unsigned char[20]" while it was "unsigned int[5]"" in previous versions.
823 // Always perform the cast even if it is useless for Boost < 1.86
824 sha1.get_digest(digest);
825
826 result.resize(8 * 5 + 4);
827 sprintf(&result[0], "%02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x%02x%02x-%02x%02x%02x%02x",
828 digest[0], digest[1], digest[2], digest[3],
829 digest[4], digest[5], digest[6], digest[7],
830 digest[8], digest[9], digest[10], digest[11],
831 digest[12], digest[13], digest[14], digest[15],
832 digest[16], digest[17], digest[18], digest[19]);
833
834 #else
815 unsigned int digest[5]; 835 unsigned int digest[5];
816 // Sanity check for the memory layout: A SHA-1 digest is 160 bits wide 836 // Sanity check for the memory layout: A SHA-1 digest is 160 bits wide
817 assert(sizeof(unsigned int) == 4 && sizeof(digest) == (160 / 8)); 837 assert(sizeof(unsigned int) == 4 && sizeof(digest) == (160 / 8));
818 assert(sizeof(boost::uuids::detail::sha1::digest_type) == 20); 838 assert(sizeof(boost::uuids::detail::sha1::digest_type) == 20);
819 839
820 // From Boost 1.86, digest_type is "unsigned char[20]" while it was "unsigned int[5]"" in previous versions. 840 sha1.get_digest(digest));
821 // Always perform the cast even if it is useless for Boost < 1.86
822 sha1.get_digest(*(reinterpret_cast<boost::uuids::detail::sha1::digest_type*>(digest)));
823 841
824 result.resize(8 * 5 + 4); 842 result.resize(8 * 5 + 4);
825 sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", 843 sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x",
826 digest[0], 844 digest[0],
827 digest[1], 845 digest[1],
828 digest[2], 846 digest[2],
829 digest[3], 847 digest[3],
830 digest[4]); 848 digest[4]);
849
850 #endif
851
831 } 852 }
832 853
833 void Toolbox::ComputeSHA1(std::string& result, 854 void Toolbox::ComputeSHA1(std::string& result,
834 const std::string& data) 855 const std::string& data)
835 { 856 {