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>
93  : private std::bitset<static_cast<size_t>(Perm::COUNT)> {
94  private:
95  using Parent = std::bitset<static_cast<size_t>(Perm::COUNT)>;
96 
97  public:
98  PermissionSet();
99  PermissionSet(std::initializer_list<Perm> list);
100  explicit PermissionSet(const std::string &bitstring);
101 
102  // TODO [IR-1889] Akvinikym 21.11.18: introduce toString() method
103  std::string toBitstring() const;
104 
105  static size_t size();
106  PermissionSet &reset();
107  PermissionSet &set();
108  PermissionSet &set(Perm p);
109  PermissionSet &unset(Perm p);
110 
111  bool test(Perm p) const;
112  bool none() const;
113 
114  bool isSubsetOf(const PermissionSet<Perm> &r) const;
115 
116  bool operator==(const PermissionSet<Perm> &r) const;
117  bool operator!=(const PermissionSet<Perm> &r) const;
118  PermissionSet<Perm> &operator&=(const PermissionSet<Perm> &r);
119  PermissionSet<Perm> &operator|=(const PermissionSet<Perm> &r);
120  PermissionSet<Perm> &operator^=(const PermissionSet<Perm> &r);
121 
122  void iterate(std::function<void(Perm)> f) const;
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