File indexing completed on 2025-12-16 09:44:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_DETAIL_SHA1_HPP
0012 #define BOOST_COMPUTE_DETAIL_SHA1_HPP
0013
0014 #include <sstream>
0015 #include <iomanip>
0016 #include <boost/version.hpp>
0017 #if BOOST_VERSION >= 106600
0018 # include <boost/uuid/detail/sha1.hpp>
0019 #else
0020 # include <boost/uuid/sha1.hpp>
0021 #endif
0022
0023 namespace boost {
0024 namespace compute {
0025 namespace detail {
0026
0027
0028 class sha1 {
0029 public:
0030 sha1(const std::string &s = "") {
0031 if (!s.empty()) this->process(s);
0032 }
0033
0034 sha1& process(const std::string &s) {
0035 h.process_bytes(s.c_str(), s.size());
0036 return *this;
0037 }
0038
0039 operator std::string() {
0040 #if BOOST_VERSION >= 108600
0041 boost::uuids::detail::sha1::digest_type digest;
0042 #else
0043 unsigned int digest[5];
0044 #endif
0045
0046 h.get_digest(digest);
0047
0048 std::ostringstream buf;
0049 #if BOOST_VERSION >= 108600
0050 for(int i = 0; i < 20; ++i)
0051 buf << std::hex << std::setfill('0') << std::setw(2) << +digest[i];
0052 #else
0053 for(int i = 0; i < 5; ++i)
0054 buf << std::hex << std::setfill('0') << std::setw(8) << digest[i];
0055 #endif
0056 return buf.str();
0057 }
0058 private:
0059 boost::uuids::detail::sha1 h;
0060 };
0061
0062 }
0063 }
0064 }
0065
0066
0067 #endif