LCOV - code coverage report
Current view: top level - irohad/model - model_crypto_provider_impl.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 18 30 60.0 %
Date: 2019-03-07 14:46:43 Functions: 9 14 64.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 "model/model_crypto_provider_impl.hpp"
       7             : #include <algorithm>
       8             : #include "cryptography/ed25519_sha3_impl/internal/ed25519_impl.hpp"
       9             : #include "model/queries/get_account.hpp"
      10             : #include "model/queries/get_account_assets.hpp"
      11             : #include "model/queries/get_asset_info.hpp"
      12             : #include "model/queries/get_roles.hpp"
      13             : #include "model/queries/get_signatories.hpp"
      14             : #include "model/queries/get_transactions.hpp"
      15             : #include "model/sha3_hash.hpp"
      16             : 
      17             : namespace iroha {
      18             :   namespace model {
      19             :     ModelCryptoProviderImpl::ModelCryptoProviderImpl(const keypair_t &keypair)
      20           3 :         : keypair_(keypair) {}
      21             : 
      22             :     bool ModelCryptoProviderImpl::verify(const Transaction &tx) const {
      23           2 :       return std::all_of(tx.signatures.begin(),
      24           2 :                          tx.signatures.end(),
      25             :                          [tx](const Signature &sig) {
      26           2 :                            return iroha::verify(iroha::hash(tx).to_string(),
      27           2 :                                                 sig.pubkey,
      28           2 :                                                 sig.signature);
      29           0 :                          });
      30           0 :     }
      31             : 
      32             :     bool ModelCryptoProviderImpl::verify(const Query &query) const {
      33           2 :       return iroha::verify(iroha::hash(query).to_string(),
      34           2 :                            query.signature.pubkey,
      35           2 :                            query.signature.signature);
      36           0 :     }
      37             : 
      38             :     bool ModelCryptoProviderImpl::verify(const Block &block) const {
      39           0 :       return std::all_of(
      40             :           block.sigs.begin(), block.sigs.end(), [block](const Signature &sig) {
      41           0 :             return iroha::verify(
      42           0 :                 iroha::hash(block).to_string(), sig.pubkey, sig.signature);
      43           0 :           });
      44           0 :     }
      45             : 
      46             :     void ModelCryptoProviderImpl::sign(Block &block) const {
      47           0 :       auto signature = iroha::sign(
      48           0 :           iroha::hash(block).to_string(), keypair_.pubkey, keypair_.privkey);
      49             : 
      50           0 :       block.sigs.emplace_back(signature, keypair_.pubkey);
      51           0 :     }
      52             : 
      53             :     void ModelCryptoProviderImpl::sign(Transaction &transaction) const {
      54           1 :       auto signature = iroha::sign(iroha::hash(transaction).to_string(),
      55           1 :                                    keypair_.pubkey,
      56           1 :                                    keypair_.privkey);
      57             : 
      58           1 :       transaction.signatures.emplace_back(signature, keypair_.pubkey);
      59           1 :     }
      60             : 
      61             :     void ModelCryptoProviderImpl::sign(Query &query) const {
      62           2 :       auto signature = iroha::sign(
      63           2 :           iroha::hash(query).to_string(), keypair_.pubkey, keypair_.privkey);
      64             : 
      65           2 :       query.signature = Signature{signature, keypair_.pubkey};
      66           2 :     }
      67             :   }  // namespace model
      68             : }  // namespace iroha

Generated by: LCOV version 1.13