LCOV - code coverage report
Current view: top level - shared_model/cryptography/model_impl - hash.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 8 10 80.0 %
Date: 2018-12-05 17:11:35 Functions: 9 9 100.0 %

          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

Generated by: LCOV version 1.13