hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
signable_validator.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_SIGNABLE_VALIDATOR_HPP
7 #define IROHA_SHARED_MODEL_SIGNABLE_VALIDATOR_HPP
8 
9 #include "validators/answer.hpp"
10 
11 namespace shared_model {
12  namespace validation {
13 
14  template <typename ModelValidator,
15  typename Model,
16  typename FieldValidator,
17  bool SignatureRequired = true>
18  class SignableModelValidator : public ModelValidator {
19  private:
20  template <typename Validator>
21  Answer validateImpl(const Model &model, Validator &&validator) const {
22  auto answer = std::forward<Validator>(validator)(model);
23  std::string reason_name = "Signature";
24  ReasonsGroupType reason(reason_name, GroupedReasons());
25  if (SignatureRequired or not model.signatures().empty()) {
26  field_validator_.validateSignatures(
27  reason, model.signatures(), model.payload());
28  }
29  if (not reason.second.empty()) {
30  answer.addReason(std::move(reason));
31  }
32  return answer;
33  }
34 
35  explicit SignableModelValidator(std::shared_ptr<ValidatorsConfig> config,
36  FieldValidator &&validator)
37  : ModelValidator(config), field_validator_(std::move(validator)) {}
38 
39  public:
40  explicit SignableModelValidator(std::shared_ptr<ValidatorsConfig> config)
41  : SignableModelValidator(config, FieldValidator{config}) {}
42 
43  Answer validate(const Model &model,
44  interface::types::TimestampType current_timestamp) const {
45  return validateImpl(model, [&, current_timestamp](const Model &m) {
46  return ModelValidator::validate(m, current_timestamp);
47  });
48  }
49 
50  Answer validate(const Model &model) const {
51  return validateImpl(
52  model, [&](const Model &m) { return ModelValidator::validate(m); });
53  }
54 
55  private:
56  FieldValidator field_validator_;
57  };
58  } // namespace validation
59 } // namespace shared_model
60 #endif // IROHA_SHARED_MODEL_SIGNABLE_VALIDATOR_HPP
Definition: signable_validator.hpp:18
void validateSignatures(ReasonsGroupType &reason, const interface::types::SignatureRangeType &signatures, const crypto::Blob &source) const
Definition: field_validator.cpp:305
Answer validate(const Model &model) const
Definition: signable_validator.hpp:50
Answer validate(const Model &model, interface::types::TimestampType current_timestamp) const
Definition: signable_validator.hpp:43
SignableModelValidator(std::shared_ptr< ValidatorsConfig > config)
Definition: signable_validator.hpp:40
std::vector< ConcreteReasonType > GroupedReasons
Definition: answer.hpp:20
std::pair< ReasonsGroupName, GroupedReasons > ReasonsGroupType
Definition: answer.hpp:22
Definition: command_executor.hpp:12
Definition: answer.hpp:28
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:59