hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
permissions.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_PERMISSIONS_HPP
7 #define IROHA_SHARED_MODEL_PERMISSIONS_HPP
8 
9 #include <bitset>
10 #include <functional>
11 #include <initializer_list>
12 #include <string>
13 
14 namespace shared_model {
15  namespace interface {
16  namespace permissions {
17  enum class Role {
23  kAddPeer,
26  kSetQuorum,
28  kSetDetail,
30  kTransfer,
31  kReceive,
34  kGetRoles,
53  kGetMyTxs,
54  kGetAllTxs,
60  kGetBlocks,
63  COUNT
64  };
65 
66  enum class Grantable {
72 
73  COUNT
74  };
75 
77 
82  bool isValid(interface::permissions::Role perm) noexcept;
83 
88  bool isValid(interface::permissions::Grantable perm) noexcept;
89  } // namespace permissions
90 
91  template <typename Perm>
92  class PermissionSet {
93  public:
94  PermissionSet();
95  PermissionSet(std::initializer_list<Perm> list);
96  explicit PermissionSet(const std::string &bitstring);
97 
98  // TODO [IR-1889] Akvinikym 21.11.18: introduce toString() method
99  std::string toBitstring() const;
100 
101  static size_t size();
102  PermissionSet &unsetAll();
103  PermissionSet &setAll();
104  PermissionSet &set(Perm p);
105  PermissionSet &unset(Perm p);
106 
107  bool isSet(Perm p) const;
108  bool isEmpty() const;
109 
111  bool isSubsetOf(const PermissionSet<Perm> &r) const;
112 
113  bool operator==(const PermissionSet<Perm> &r) const;
114  bool operator!=(const PermissionSet<Perm> &r) const;
115  PermissionSet<Perm> &operator&=(const PermissionSet<Perm> &r);
116  PermissionSet<Perm> &operator|=(const PermissionSet<Perm> &r);
117  PermissionSet<Perm> &operator^=(const PermissionSet<Perm> &r);
118 
119  void iterate(std::function<void(Perm)> f) const;
120 
121  private:
122  std::bitset<static_cast<size_t>(Perm::COUNT)> perms_bitset_;
123  };
124 
127  } // namespace interface
128 } // namespace shared_model
129 
130 #endif // IROHA_SHARED_MODEL_TRANSACTION_HPP
Grantable
Definition: permissions.hpp:66
Definition: permissions.hpp:92
Role
Definition: permissions.hpp:17
Role permissionFor(Grantable g)
Definition: permissions.cpp:14
Definition: command_executor.hpp:12
bool isValid(Role perm) noexcept
Definition: permissions.cpp:31