Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. 2018 All Rights Reserved.
3 : * http://soramitsu.co.jp
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #include "cryptography/hash.hpp"
19 :
20 : #include <boost/functional/hash.hpp>
21 :
22 : #include "common/byteutils.hpp"
23 : namespace shared_model {
24 : namespace crypto {
25 :
26 : Hash::Hash() : Blob() {}
27 :
28 : Hash::Hash(const std::string &hash) : Blob(hash) {}
29 :
30 : Hash::Hash(const Blob &blob) : Blob(blob) {}
31 :
32 : Hash Hash::fromHexString(const std::string &hex) {
33 213 : return Hash(Blob::fromHexString(hex));
34 0 : }
35 :
36 : std::string Hash::toString() const {
37 1919 : return detail::PrettyStringBuilder()
38 1917 : .init("Hash")
39 1918 : .append(Blob::hex())
40 1919 : .finalize();
41 0 : }
42 :
43 : std::size_t Hash::Hasher::operator()(const Hash &h) const {
44 : using boost::hash_combine;
45 : using boost::hash_value;
46 :
47 10974 : std::size_t seed = 0;
48 10974 : hash_combine(seed, hash_value(h.blob()));
49 :
50 10974 : return seed;
51 : }
52 : } // namespace crypto
53 : } // namespace shared_model
|