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 
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  std::optional<ValidationError> validateImpl(const Model &model,
22  Validator &&validator) const {
23  ValidationErrorCreator error_creator;
24 
25  error_creator |= std::forward<Validator>(validator)(model);
26  if (SignatureRequired or not model.signatures().empty()) {
27  error_creator |= field_validator_.validateSignatures(
28  model.signatures(), model.payload());
29  }
30 
31  return std::move(error_creator).getValidationError("SignedData");
32  }
33 
34  explicit SignableModelValidator(std::shared_ptr<ValidatorsConfig> config,
35  FieldValidator &&validator)
36  : ModelValidator(config), field_validator_(std::move(validator)) {}
37 
38  public:
39  explicit SignableModelValidator(std::shared_ptr<ValidatorsConfig> config)
40  : SignableModelValidator(config, FieldValidator{config}) {}
41 
42  std::optional<ValidationError> validate(
43  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  std::optional<ValidationError> 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
std::optional< ValidationError > validate(const Model &model, interface::types::TimestampType current_timestamp) const
Definition: signable_validator.hpp:42
std::optional< ValidationError > validate(const Model &model) const
Definition: signable_validator.hpp:50
SignableModelValidator(std::shared_ptr< ValidatorsConfig > config)
Definition: signable_validator.hpp:39
Helper class for ValidationError creation.
Definition: validation_error_helpers.hpp:16
std::optional< ValidationError > validateSignatures(const interface::types::SignatureRangeType &signatures, const crypto::Blob &source) const
Definition: field_validator.cpp:320
Definition: command_executor.hpp:12
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:67