hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
field_validator.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
7 #define IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
8 
9 #include <regex>
10 
11 #include "datetime/time.hpp"
15 #include "validators/answer.hpp"
17 
18 namespace shared_model {
19 
20  namespace interface {
21  class Amount;
22  class BatchMeta;
23  class Peer;
24  class AssetPaginationMeta;
25  class TxPaginationMeta;
26  class AccountDetailPaginationMeta;
27  } // namespace interface
28 
29  namespace validation {
30 
36  private:
37  using TimeFunction = std::function<iroha::ts64_t()>;
38 
39  public:
40  FieldValidator(std::shared_ptr<ValidatorsConfig> config,
41  time_t future_gap = kDefaultFutureGap,
42  TimeFunction time_provider = [] {
43  return iroha::time::now();
44  });
45 
46  void validateAccountId(
47  ReasonsGroupType &reason,
48  const interface::types::AccountIdType &account_id) const;
49 
50  void validateAssetId(ReasonsGroupType &reason,
51  const interface::types::AssetIdType &asset_id) const;
52 
53  void validatePeer(ReasonsGroupType &reason,
54  const interface::Peer &peer) const;
55 
56  void validateAmount(ReasonsGroupType &reason,
57  const interface::Amount &amount) const;
58 
59  void validatePubkey(ReasonsGroupType &reason,
60  const interface::types::PubkeyType &pubkey) const;
61 
62  void validatePeerAddress(
63  ReasonsGroupType &reason,
64  const interface::types::AddressType &address) const;
65 
66  void validateRoleId(ReasonsGroupType &reason,
67  const interface::types::RoleIdType &role_id) const;
68 
69  void validateAccountName(
70  ReasonsGroupType &reason,
71  const interface::types::AccountNameType &account_name) const;
72 
73  // clang-format off
94  // clang-format on
95  void validateDomainId(
96  ReasonsGroupType &reason,
97  const interface::types::DomainIdType &domain_id) const;
98 
99  void validateAssetName(
100  ReasonsGroupType &reason,
101  const interface::types::AssetNameType &asset_name) const;
102 
103  void validateAccountDetailKey(
104  ReasonsGroupType &reason,
105  const interface::types::AccountDetailKeyType &key) const;
106 
107  void validateAccountDetailValue(
108  ReasonsGroupType &reason,
109  const interface::types::AccountDetailValueType &value) const;
110 
111  void validateOldAccountDetailValue(
112  ReasonsGroupType &reason,
113  const boost::optional<interface::types::AccountDetailValueType>
114  &old_value) const;
115 
116  void validatePrecision(
117  ReasonsGroupType &reason,
118  const interface::types::PrecisionType &precision) const;
119 
120  void validateRolePermission(
121  ReasonsGroupType &reason,
122  const interface::permissions::Role &permission) const;
123 
124  void validateGrantablePermission(
125  ReasonsGroupType &reason,
126  const interface::permissions::Grantable &permission) const;
127 
128  void validateQuorum(ReasonsGroupType &reason,
129  const interface::types::QuorumType &quorum) const;
130 
131  void validateCreatorAccountId(
132  ReasonsGroupType &reason,
133  const interface::types::AccountIdType &account_id) const;
134 
138  void validateCreatedTime(ReasonsGroupType &reason,
141 
145  void validateCreatedTime(ReasonsGroupType &reason,
146  interface::types::TimestampType timestamp) const;
147 
148  void validateCounter(ReasonsGroupType &reason,
149  const interface::types::CounterType &counter) const;
150 
151  void validateSignatures(
152  ReasonsGroupType &reason,
153  const interface::types::SignatureRangeType &signatures,
154  const crypto::Blob &source) const;
155 
156  void validateQueryPayloadMeta(
157  ReasonsGroupType &reason,
158  const interface::QueryPayloadMeta &meta) const;
159 
160  void validateDescription(
161  ReasonsGroupType &reason,
162  const interface::types::DescriptionType &description) const;
163 
164  void validateBatchMeta(ReasonsGroupType &reason,
165  const interface::BatchMeta &description) const;
166 
167  void validateHeight(ReasonsGroupType &reason,
168  const interface::types::HeightType &height) const;
169 
170  void validateHash(ReasonsGroupType &reason,
171  const crypto::Hash &hash) const;
172 
173  void validateTxPaginationMeta(
174  ReasonsGroupType &reason,
175  const interface::TxPaginationMeta &tx_pagination_meta) const;
176 
177  void validateAssetPaginationMeta(
178  ReasonsGroupType &reason,
179  const interface::AssetPaginationMeta &asset_pagination_meta) const;
180 
181  void validateAccountDetailPaginationMeta(
182  ReasonsGroupType &reason,
183  const interface::AccountDetailPaginationMeta &pagination_meta) const;
184 
185  private:
186  const static std::string account_name_pattern_;
187  const static std::string asset_name_pattern_;
188  const static std::string domain_pattern_;
189  const static std::string ip_v4_pattern_;
190  const static std::string peer_address_pattern_;
191  const static std::string account_id_pattern_;
192  const static std::string asset_id_pattern_;
193  const static std::string detail_key_pattern_;
194  const static std::string role_id_pattern_;
195 
196  const static std::regex account_name_regex_;
197  const static std::regex asset_name_regex_;
198  const static std::regex domain_regex_;
199  const static std::regex ip_v4_regex_;
200  const static std::regex peer_address_regex_;
201  const static std::regex account_id_regex_;
202  const static std::regex asset_id_regex_;
203  const static std::regex detail_key_regex_;
204  const static std::regex role_id_regex_;
205 
206  // gap for future transactions
207  time_t future_gap_;
208  // time provider callback
209  TimeFunction time_provider_;
210 
211  public:
212  // max-delay between tx creation and validation
213  static constexpr auto kMaxDelay =
214  std::chrono::hours(24) / std::chrono::milliseconds(1);
215  // default value for future_gap field of FieldValidator
216  static constexpr auto kDefaultFutureGap =
217  std::chrono::minutes(5) / std::chrono::milliseconds(1);
218 
219  // size of key
220  static const size_t public_key_size;
221  static const size_t signature_size;
222  static const size_t hash_size;
223  static const size_t value_size;
225  };
226 
227  boost::optional<ConcreteReasonType> validatePubkey(
228  const interface::types::PubkeyType &pubkey);
229 
230  } // namespace validation
231 } // namespace shared_model
232 
233 #endif // IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
static const size_t signature_size
Definition: field_validator.hpp:221
std::string AddressType
Type of peer address.
Definition: types.hpp:45
uint64_t HeightType
Type of height (for Block, Proposal etc)
Definition: types.hpp:43
Definition: hash.hpp:18
Definition: blob.hpp:25
Grantable
Definition: permissions.hpp:70
Definition: peer.hpp:20
Provides query metadata for account detail list pagination.
Definition: account_detail_pagination_meta.hpp:18
decltype(iroha::time::now()) time_t
Definition: time.hpp:38
std::string DomainIdType
Iroha domain id type.
Definition: types.hpp:53
Definition: amount.hpp:19
static const size_t public_key_size
Definition: field_validator.hpp:220
auto now()
Definition: time.hpp:23
size_t max_description_size
Definition: field_validator.hpp:224
boost::any_range< interface::Signature, boost::forward_traversal_tag, const Signature & > SignatureRangeType
Type of signature range, which returns when signatures are invoked.
Definition: range_types.hpp:24
std::string DescriptionType
Type of the transfer message.
Definition: types.hpp:83
Definition: query_payload_meta.hpp:19
std::string AccountDetailKeyType
Type of account detail key.
Definition: types.hpp:76
Role
Definition: permissions.hpp:17
std::string AccountIdType
Type of account id.
Definition: types.hpp:39
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
Provides query metadata for any transaction list pagination.
Definition: tx_pagination_meta.hpp:17
Definition: field_validator.hpp:35
uint8_t PrecisionType
Type of precision.
Definition: types.hpp:41
boost::optional< ConcreteReasonType > validatePubkey(const interface::types::PubkeyType &pubkey)
Definition: field_validator.cpp:389
std::string AccountNameType
Type of account name.
Definition: types.hpp:68
static const size_t value_size
limit for the set account detail size in bytes
Definition: field_validator.hpp:223
uint64_t CounterType
Type of counter.
Definition: types.hpp:66
Definition: public_key.hpp:16
Definition: batch_meta.hpp:18
static const size_t hash_size
Definition: field_validator.hpp:222
Provides query metadata for asset list pagination.
Definition: asset_pagination_meta.hpp:17
std::pair< ReasonsGroupName, GroupedReasons > ReasonsGroupType
Definition: answer.hpp:22
std::string AccountDetailValueType
Type of account detail value.
Definition: types.hpp:78
Definition: command_executor.hpp:12
uint16_t QuorumType
Type of Quorum used in transaction and set quorum.
Definition: types.hpp:62
std::string AssetNameType
Type of asset name.
Definition: types.hpp:70
std::string RoleIdType
Type of role (i.e admin, user)
Definition: types.hpp:51
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:64
std::string AssetIdType
Type of asset id.
Definition: types.hpp:55