Ethereum  PoC-8
The C++ Implementation of Ethereum
FixedHash.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "FixedHash.h"
19 #include <boost/algorithm/string.hpp>
20 
21 namespace dev
22 {
23 
24 std::random_device s_fixedHashEngine;
25 
26 h128 fromUUID(std::string const& _uuid)
27 {
28  try
29  {
30  return h128(boost::replace_all_copy(_uuid, "-", ""));
31  }
32  catch (...)
33  {
34  return h128();
35  }
36 }
37 
38 std::string toUUID(h128 const& _uuid)
39 {
40  std::string ret = toHex(_uuid.ref());
41  for (unsigned i: {20, 16, 12, 8})
42  ret.insert(ret.begin() + i, '-');
43  return ret;
44 }
45 
46 }
47 
48 
49 
FixedHash.h
dev::FixedHash::ref
bytesRef ref()
Definition: FixedHash.h:132
dev::fromUUID
h128 fromUUID(std::string const &_uuid)
Definition: FixedHash.cpp:26
dev::FixedHash
Definition: FixedHash.h:47
dev::h128
FixedHash< 16 > h128
Definition: FixedHash.h:358
dev::toUUID
std::string toUUID(h128 const &_uuid)
Definition: FixedHash.cpp:38
dev::s_fixedHashEngine
std::random_device s_fixedHashEngine
Definition: FixedHash.cpp:24
dev
Definition: Address.cpp:21
dev::toHex
std::string toHex(Iterator _it, Iterator _end, std::string const &_prefix)
Definition: CommonData.h:46