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,
65  kRoot,
66 
67  COUNT
68  };
69 
70  enum class Grantable {
76 
77  COUNT
78  };
79 
81 
86  bool isValid(interface::permissions::Role perm) noexcept;
87 
92  bool isValid(interface::permissions::Grantable perm) noexcept;
93  } // namespace permissions
94 
95  template <typename Perm>
96  class PermissionSet {
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 constexpr size_t size() {
106  return static_cast<size_t>(Perm::COUNT);
107  }
108 
109  PermissionSet &unsetAll();
110  PermissionSet &setAll();
111  PermissionSet &set(Perm p);
112  PermissionSet &unset(Perm p);
113 
114  bool isSet(Perm p) const;
115  bool isEmpty() const;
116 
118  bool isSubsetOf(const PermissionSet<Perm> &r) const;
119 
120  bool operator==(const PermissionSet<Perm> &r) const;
121  bool operator!=(const PermissionSet<Perm> &r) const;
122  PermissionSet<Perm> &operator&=(const PermissionSet<Perm> &r);
123  PermissionSet<Perm> &operator|=(const PermissionSet<Perm> &r);
124  PermissionSet<Perm> &operator^=(const PermissionSet<Perm> &r);
125 
126  void iterate(std::function<void(Perm)> f) const;
127 
128  private:
129  std::bitset<static_cast<size_t>(Perm::COUNT)> perms_bitset_;
130  };
131 
134  } // namespace interface
135 } // namespace shared_model
136 
137 #endif // IROHA_SHARED_MODEL_TRANSACTION_HPP
Grantable
Definition: permissions.hpp:70
Definition: permissions.hpp:96
static constexpr size_t size()
Definition: permissions.hpp:105
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