LCOV - code coverage report
Current view: top level - irohad/validation - utils.hpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 11 14 78.6 %
Date: 2019-03-07 14:46:43 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #ifndef IROHA_VALIDATION_UTILS
       7             : #define IROHA_VALIDATION_UTILS
       8             : 
       9             : #include <string>
      10             : #include <vector>
      11             : 
      12             : #include <boost/range/adaptor/transformed.hpp>
      13             : #include <boost/range/any_range.hpp>
      14             : 
      15             : #include "cryptography/public_key.hpp"
      16             : #include "interfaces/common_objects/types.hpp"
      17             : 
      18             : namespace iroha {
      19             :   namespace validation {
      20             :     /**
      21             :      * Checks if signatures' public keys are present in vector of pubkeys
      22             :      * @param signatures - collection of signatures
      23             :      * @param public_keys - collection of public keys
      24             :      * @return true, if all public keys of signatures are present in vector of
      25             :      * pubkeys
      26             :      */
      27             :     inline bool signaturesSubset(
      28             :         const shared_model::interface::types::SignatureRangeType &signatures,
      29             :         const boost::any_range<shared_model::crypto::PublicKey,
      30             :                                boost::forward_traversal_tag> &public_keys) {
      31           9 :       return std::all_of(
      32           9 :           signatures.begin(),
      33           9 :           signatures.end(),
      34             :           [&public_keys](const auto &signature) {
      35          26 :             return std::find_if(public_keys.begin(),
      36          26 :                                 public_keys.end(),
      37             :                                 [&signature](const auto &public_key) {
      38          55 :                                   return signature.publicKey() == public_key;
      39             :                                 })
      40          26 :                 != public_keys.end();
      41           0 :           });
      42           0 :     }
      43             : 
      44             :     /**
      45             :      * Checks if `signatures' is a subset of signatures of `peers'
      46             :      * @param signatures to check
      47             :      * @param peers with signatures
      48             :      * @return true if is a subset or false otherwise
      49             :      */
      50             :     template <typename Peers>
      51             :     inline bool peersSubset(
      52             :         const shared_model::interface::types::SignatureRangeType &signatures,
      53             :         const Peers &peers) {
      54           5 :       return signaturesSubset(signatures,
      55           5 :                               peers
      56           5 :                                   | boost::adaptors::transformed(
      57             :                                         [](const auto &p) -> decltype(auto) {
      58          38 :                                           return p->pubkey();
      59             :                                         }));
      60           0 :     }
      61             : 
      62             :   }  // namespace validation
      63             : }  // namespace iroha
      64             : 
      65             : #endif  // IROHA_VALIDATION_UTILS

Generated by: LCOV version 1.13