LCOV - code coverage report
Current view: top level - shared_model/cryptography/model_impl - blob.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 12 18 66.7 %
Date: 2019-03-07 14:46:43 Functions: 14 15 93.3 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "cryptography/blob.hpp"
       7             : 
       8             : #include "common/byteutils.hpp"
       9             : 
      10             : namespace shared_model {
      11             :   namespace crypto {
      12             : 
      13             :     std::string toBinaryString(const Blob &b) {
      14      843452 :       return std::string(b.blob().begin(), b.blob().end());
      15             :     }
      16             : 
      17             :     Blob::Blob(const std::string &blob)
      18      446449 :         : Blob(Bytes(blob.begin(), blob.end())) {}
      19             : 
      20             :     Blob::Blob(const Bytes &blob) : Blob(Bytes(blob)) {}
      21             : 
      22             :     Blob::Blob(Bytes &&blob) noexcept : blob_(std::move(blob)) {
      23      731869 :       hex_ = iroha::bytestringToHexstring(toBinaryString(*this));
      24      731869 :     }
      25             : 
      26             :     Blob *Blob::clone() const {
      27           1 :       return new Blob(blob());
      28           0 :     }
      29             : 
      30             :     bool Blob::operator==(const Blob &rhs) const {
      31       38836 :       return blob() == rhs.blob();
      32             :     }
      33             : 
      34             :     Blob Blob::fromHexString(const std::string &hex) {
      35             :       using iroha::operator|;
      36      214143 :       Blob b("");
      37             :       iroha::hexstringToBytestring(hex) | [&](auto &&s) { b = Blob(s); };
      38      218559 :       return b;
      39      218573 :     }
      40             : 
      41             :     const Blob::Bytes &Blob::blob() const {
      42     2009882 :       return blob_;
      43             :     }
      44             : 
      45             :     const std::string &Blob::hex() const {
      46      122446 :       return hex_;
      47             :     }
      48             : 
      49             :     size_t Blob::size() const {
      50         305 :       return blob_.size();
      51             :     }
      52             : 
      53             :     std::string Blob::toString() const {
      54           0 :       return detail::PrettyStringBuilder()
      55           0 :           .init("Blob")
      56           0 :           .append(hex())
      57           0 :           .finalize();
      58           0 :     }
      59             : 
      60             :   }  // namespace crypto
      61             : }  // namespace shared_model

Generated by: LCOV version 1.13