Mercurial > hg > orthanc
comparison Core/Toolbox.cpp @ 577:2737806bcf60 laaw
integration mainline->laaw
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 30 Sep 2013 15:03:36 +0200 |
parents | 86c5bb651bfa 69c024f9c06b |
children | b82292ba2083 0bedf8ff9288 |
comparison
equal
deleted
inserted
replaced
576:bf2fda1c6760 | 577:2737806bcf60 |
---|---|
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 | 69 |
70 | 70 |
71 #ifdef _MSC_VER | 71 #ifdef _MSC_VER |
72 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio | 72 // Patch for the missing "_strtoll" symbol when compiling with Visual Studio |
73 extern "C" | 73 extern "C" |
570 } | 570 } |
571 | 571 |
572 void Toolbox::ComputeSHA1(std::string& result, | 572 void Toolbox::ComputeSHA1(std::string& result, |
573 const std::string& data) | 573 const std::string& data) |
574 { | 574 { |
575 SHA1 sha1; | 575 boost::uuids::detail::sha1 sha1; |
576 | |
576 if (data.size() > 0) | 577 if (data.size() > 0) |
577 { | 578 { |
578 sha1.Input(&data[0], data.size()); | 579 sha1.process_bytes(&data[0], data.size()); |
579 } | 580 } |
580 | 581 |
581 unsigned digest[5]; | 582 unsigned int digest[5]; |
582 | 583 |
583 // 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 |
584 assert(sizeof(unsigned) == 4 && sizeof(digest) == (160 / 8)); | 585 assert(sizeof(unsigned int) == 4 && sizeof(digest) == (160 / 8)); |
585 | 586 |
586 if (sha1.Result(digest)) | 587 sha1.get_digest(digest); |
587 { | 588 |
588 result.resize(8 * 5 + 4); | 589 result.resize(8 * 5 + 4); |
589 sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", | 590 sprintf(&result[0], "%08x-%08x-%08x-%08x-%08x", |
590 digest[0], | 591 digest[0], |
591 digest[1], | 592 digest[1], |
592 digest[2], | 593 digest[2], |
593 digest[3], | 594 digest[3], |
594 digest[4]); | 595 digest[4]); |
595 } | |
596 else | |
597 { | |
598 throw OrthancException(ErrorCode_InternalError); | |
599 } | |
600 } | 596 } |
601 | 597 |
602 bool Toolbox::IsSHA1(const std::string& str) | 598 bool Toolbox::IsSHA1(const std::string& str) |
603 { | 599 { |
604 if (str.size() != 44) | 600 if (str.size() != 44) |