comparison Orthanc/Core/Toolbox.cpp @ 129:2c73a785c08e

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 14 May 2016 16:39:55 +0200
parents e8cfda4c8a2f
children d73006baca3f
comparison
equal deleted inserted replaced
128:e8cfda4c8a2f 129:2c73a785c08e
580 } 580 }
581 581
582 void Toolbox::DecodeBase64(std::string& result, 582 void Toolbox::DecodeBase64(std::string& result,
583 const std::string& data) 583 const std::string& data)
584 { 584 {
585 for (size_t i = 0; i < data.length(); i++)
586 {
587 if (!isalnum(data[i]) &&
588 data[i] != '+' &&
589 data[i] != '/' &&
590 data[i] != '=')
591 {
592 // This is not a valid character for a Base64 string
593 throw OrthancException(ErrorCode_BadFileFormat);
594 }
595 }
596
585 result = base64_decode(data); 597 result = base64_decode(data);
586 } 598 }
587 599
588 600
589 # if BOOST_HAS_REGEX == 1 601 # if BOOST_HAS_REGEX == 1
590 void Toolbox::DecodeDataUriScheme(std::string& mime, 602 bool Toolbox::DecodeDataUriScheme(std::string& mime,
591 std::string& content, 603 std::string& content,
592 const std::string& source) 604 const std::string& source)
593 { 605 {
594 boost::regex pattern("data:([^;]+);base64,([a-zA-Z0-9=+/]*)", 606 boost::regex pattern("data:([^;]+);base64,([a-zA-Z0-9=+/]*)",
595 boost::regex::icase /* case insensitive search */); 607 boost::regex::icase /* case insensitive search */);
597 boost::cmatch what; 609 boost::cmatch what;
598 if (regex_match(source.c_str(), what, pattern)) 610 if (regex_match(source.c_str(), what, pattern))
599 { 611 {
600 mime = what[1]; 612 mime = what[1];
601 DecodeBase64(content, what[2]); 613 DecodeBase64(content, what[2]);
614 return true;
602 } 615 }
603 else 616 else
604 { 617 {
605 throw OrthancException(ErrorCode_BadFileFormat); 618 return false;
606 } 619 }
607 } 620 }
608 # endif 621 # endif
609 622
610 623