1 //---------------------------------------------------------------------------// 2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> 3 // 4 // Distributed under the Boost Software License, Version 1.0 5 // See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt 7 // 8 // See http://boostorg.github.com/compute for more information. 9 //---------------------------------------------------------------------------// 10 11 #ifndef BOOST_COMPUTE_DETAIL_SHA1_HPP 12 #define BOOST_COMPUTE_DETAIL_SHA1_HPP 13 14 #include <sstream> 15 #include <iomanip> 16 #include <boost/version.hpp> 17 #if BOOST_VERSION >= 106600 18 # include <boost/uuid/detail/sha1.hpp> 19 #else 20 # include <boost/uuid/sha1.hpp> 21 #endif 22 23 namespace boost { 24 namespace compute { 25 namespace detail { 26 27 // Accumulates SHA1 hash of the passed strings. 28 class sha1 { 29 public: sha1(const std::string & s="")30 sha1(const std::string &s = "") { 31 if (!s.empty()) this->process(s); 32 } 33 process(const std::string & s)34 sha1& process(const std::string &s) { 35 h.process_bytes(s.c_str(), s.size()); 36 return *this; 37 } 38 operator std::string()39 operator std::string() { 40 unsigned int digest[5]; 41 h.get_digest(digest); 42 43 std::ostringstream buf; 44 for(int i = 0; i < 5; ++i) 45 buf << std::hex << std::setfill('0') << std::setw(8) << digest[i]; 46 47 return buf.str(); 48 } 49 private: 50 boost::uuids::detail::sha1 h; 51 }; 52 53 } // end detail namespace 54 } // end compute namespace 55 } // end boost namespace 56 57 58 #endif // BOOST_COMPUTE_DETAIL_SHA1_HPP 59