Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
544:a482948c1fd6 | 605:b82292ba2083 |
---|---|
37 #include <stdint.h> | 37 #include <stdint.h> |
38 #include <string.h> | 38 #include <string.h> |
39 #include <boost/filesystem.hpp> | 39 #include <boost/filesystem.hpp> |
40 #include <boost/filesystem/fstream.hpp> | 40 #include <boost/filesystem/fstream.hpp> |
41 #include <boost/date_time/posix_time/posix_time.hpp> | 41 #include <boost/date_time/posix_time/posix_time.hpp> |
42 #include <boost/uuid/sha1.hpp> | |
42 #include <algorithm> | 43 #include <algorithm> |
43 #include <ctype.h> | 44 #include <ctype.h> |
44 | 45 |
45 #if defined(_WIN32) | 46 #if defined(_WIN32) |
46 #include <windows.h> | 47 #include <windows.h> |
63 #include <iconv.h> | 64 #include <iconv.h> |
64 #endif | 65 #endif |
65 | 66 |
66 #include "../Resources/md5/md5.h" | 67 #include "../Resources/md5/md5.h" |
67 #include "../Resources/base64/base64.h" | 68 #include "../Resources/base64/base64.h" |
68 #include "../Resources/sha1/sha1.h" | 69 |
70 | |
71 #ifdef _MSC_VER | |
72 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio | |
73 extern "C" | |
74 { | |
75 int64_t _strtoi64(const char *nptr, char **endptr, int base); | |
76 int64_t strtoll(const char *nptr, char **endptr, int base) | |
77 { | |
78 return _strtoi64(nptr, endptr, base); | |
79 } | |
80 } | |
81 #endif | |
69 | 82 |
70 | 83 |
71 #if BOOST_HAS_LOCALE == 0 | 84 #if BOOST_HAS_LOCALE == 0 |
72 namespace | 85 namespace |
73 { | 86 { |
557 } | 570 } |
558 | 571 |
559 void Toolbox::ComputeSHA1(std::string& result, | 572 void Toolbox::ComputeSHA1(std::string& result, |
560 const std::string& data) | 573 const std::string& data) |
561 { | 574 { |
562 SHA1 sha1; | 575 boost::uuids::detail::sha1 sha1; |
576 | |
563 if (data.size() > 0) | 577 if (data.size() > 0) |
564 { | 578 { |
565 sha1.Input(&data[0], data.size()); | 579 sha1.process_bytes(&data[0], data.size()); |
566 } | 580 } |
567 | 581 |
568 unsigned digest[5]; | 582 unsigned int digest[5]; |
569 | 583 |
570 // Sanity check for the memory layout: A SHA-1 digest is 160 bits wide | 584 // Sanity check for the memory layout: A SHA-1 digest is 160 bits wide |
571 assert(sizeof(unsigned) == 4 && sizeof(digest) == (160 / 8)); | 585 assert(sizeof(unsigned int) == 4 && sizeof(digest) == (160 / 8)); |
572 | 586 |
573 if (sha1.Result(digest)) | 587 sha1.get_digest(digest); |
574 { | 588 |
575 result.resize(8 * 5 + 4); | 589 result.resize(8 * 5 + 4); |
576 sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", | 590 sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", |
577 digest[0], | 591 digest[0], |
578 digest[1], | 592 digest[1], |
579 digest[2], | 593 digest[2], |
580 digest[3], | 594 digest[3], |
581 digest[4]); | 595 digest[4]); |
582 } | |
583 else | |
584 { | |
585 throw OrthancException(ErrorCode_InternalError); | |
586 } | |
587 } | 596 } |
588 | 597 |
589 bool Toolbox::IsSHA1(const std::string& str) | 598 bool Toolbox::IsSHA1(const std::string& str) |
590 { | 599 { |
591 if (str.size() != 44) | 600 if (str.size() != 44) |