]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/uuid/sha1.hpp> | |
17 | ||
18 | namespace boost { | |
19 | namespace compute { | |
20 | namespace detail { | |
21 | ||
22 | // Accumulates SHA1 hash of the passed strings. | |
23 | class sha1 { | |
24 | public: | |
25 | sha1(const std::string &s = "") { | |
26 | if (!s.empty()) this->process(s); | |
27 | } | |
28 | ||
29 | sha1& process(const std::string &s) { | |
30 | h.process_bytes(s.c_str(), s.size()); | |
31 | return *this; | |
32 | } | |
33 | ||
34 | operator std::string() { | |
35 | unsigned int digest[5]; | |
36 | h.get_digest(digest); | |
37 | ||
38 | std::ostringstream buf; | |
39 | for(int i = 0; i < 5; ++i) | |
40 | buf << std::hex << std::setfill('0') << std::setw(8) << digest[i]; | |
41 | ||
42 | return buf.str(); | |
43 | } | |
44 | private: | |
45 | boost::uuids::detail::sha1 h; | |
46 | }; | |
47 | ||
48 | } // end detail namespace | |
49 | } // end compute namespace | |
50 | } // end boost namespace | |
51 | ||
52 | ||
53 | #endif // BOOST_COMPUTE_DETAIL_SHA1_HPP |