Mercurial > hg > orthanc
diff Core/Toolbox.cpp @ 605:b82292ba2083 dicom-rt
integration mainline -> dicom-rt
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 17 Oct 2013 14:21:50 +0200 |
parents | b22312081388 2737806bcf60 |
children | 8cfc6119a5bd |
line wrap: on
line diff
--- a/Core/Toolbox.cpp Wed Sep 04 14:19:14 2013 +0200 +++ b/Core/Toolbox.cpp Thu Oct 17 14:21:50 2013 +0200 @@ -39,6 +39,7 @@ #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/uuid/sha1.hpp> #include <algorithm> #include <ctype.h> @@ -65,7 +66,19 @@ #include "../Resources/md5/md5.h" #include "../Resources/base64/base64.h" -#include "../Resources/sha1/sha1.h" + + +#ifdef _MSC_VER +// Patch for the missing "_strtoll" symbol when compiling with Visual Studio +extern "C" +{ +int64_t _strtoi64(const char *nptr, char **endptr, int base); +int64_t strtoll(const char *nptr, char **endptr, int base) +{ + return _strtoi64(nptr, endptr, base); +} +} +#endif #if BOOST_HAS_LOCALE == 0 @@ -559,31 +572,27 @@ void Toolbox::ComputeSHA1(std::string& result, const std::string& data) { - SHA1 sha1; + boost::uuids::detail::sha1 sha1; + if (data.size() > 0) { - sha1.Input(&data[0], data.size()); + sha1.process_bytes(&data[0], data.size()); } - unsigned digest[5]; + unsigned int digest[5]; // Sanity check for the memory layout: A SHA-1 digest is 160 bits wide - assert(sizeof(unsigned) == 4 && sizeof(digest) == (160 / 8)); + assert(sizeof(unsigned int) == 4 && sizeof(digest) == (160 / 8)); - if (sha1.Result(digest)) - { - result.resize(8 * 5 + 4); - sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", - digest[0], - digest[1], - digest[2], - digest[3], - digest[4]); - } - else - { - throw OrthancException(ErrorCode_InternalError); - } + sha1.get_digest(digest); + + result.resize(8 * 5 + 4); + sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", + digest[0], + digest[1], + digest[2], + digest[3], + digest[4]); } bool Toolbox::IsSHA1(const std::string& str)