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  kGetPeers,
64  COUNT
65  };
66 
67  enum class Grantable {
73 
74  COUNT
75  };
76 
78 
83  bool isValid(interface::permissions::Role perm) noexcept;
84 
89  bool isValid(interface::permissions::Grantable perm) noexcept;
90  } // namespace permissions
91 
92  template <typename Perm>
93  class PermissionSet {
94  public:
95  PermissionSet();
96  PermissionSet(std::initializer_list<Perm> list);
97  explicit PermissionSet(const std::string &bitstring);
98 
99  // TODO [IR-1889] Akvinikym 21.11.18: introduce toString() method
100  std::string toBitstring() const;
101 
102  static size_t size();
103  PermissionSet &unsetAll();
104  PermissionSet &setAll();
105  PermissionSet &set(Perm p);
106  PermissionSet &unset(Perm p);
107 
108  bool isSet(Perm p) const;
109  bool isEmpty() const;
110 
112  bool isSubsetOf(const PermissionSet<Perm> &r) const;
113 
114  bool operator==(const PermissionSet<Perm> &r) const;
115  bool operator!=(const PermissionSet<Perm> &r) const;
116  PermissionSet<Perm> &operator&=(const PermissionSet<Perm> &r);
117  PermissionSet<Perm> &operator|=(const PermissionSet<Perm> &r);
118  PermissionSet<Perm> &operator^=(const PermissionSet<Perm> &r);
119 
120  void iterate(std::function<void(Perm)> f) const;
121 
122  private:
123  std::bitset<static_cast<size_t>(Perm::COUNT)> perms_bitset_;
124  };
125 
128  } // namespace interface
129 } // namespace shared_model
130 
131 #endif // IROHA_SHARED_MODEL_TRANSACTION_HPP
Grantable
Definition: permissions.hpp:67
Definition: permissions.hpp:93
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