Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::authority_checker< PermissionToAuthorityFunc > Class Template Reference

namespace detail More...

#include <authority_checker.hpp>

Public Types

enum  permission_cache_status { being_evaluated , permission_unsatisfied , permission_satisfied }
 
typedef map< permission_level, permission_cache_statuspermission_cache_type
 

Public Member Functions

 authority_checker (PermissionToAuthorityFunc permission_to_authority, uint16_t recursion_depth_limit, const flat_set< public_key_type > &provided_keys, const flat_set< permission_level > &provided_permissions, fc::microseconds provided_delay, const std::function< void()> &checktime)
 
bool satisfied (const permission_level &permission, fc::microseconds override_provided_delay, permission_cache_type *cached_perms=nullptr)
 
bool satisfied (const permission_level &permission, permission_cache_type *cached_perms=nullptr)
 
template<typename AuthorityType >
bool satisfied (const AuthorityType &authority, fc::microseconds override_provided_delay, permission_cache_type *cached_perms=nullptr)
 
template<typename AuthorityType >
bool satisfied (const AuthorityType &authority, permission_cache_type *cached_perms=nullptr)
 
bool all_keys_used () const
 
flat_set< public_key_typeused_keys () const
 
flat_set< public_key_typeunused_keys () const
 

Static Public Member Functions

static std::optional< permission_cache_statuspermission_status_in_cache (const permission_cache_type &permissions, const permission_level &level)
 

Detailed Description

template<typename PermissionToAuthorityFunc>
class sysio::chain::authority_checker< PermissionToAuthorityFunc >

This class determines whether a set of signing keys are sufficient to satisfy an authority or not

To determine whether an authority is satisfied or not, we first determine which keys have approved of a message, and then determine whether that list of keys is sufficient to satisfy the authority. This class takes a list of keys and provides the satisfied method to determine whether that list of keys satisfies a provided authority.

Template Parameters
FA callable which takes a single argument of type AccountPermission and returns the corresponding authority

Definition at line 35 of file authority_checker.hpp.

Member Typedef Documentation

◆ permission_cache_type

template<typename PermissionToAuthorityFunc >
map<permission_level, permission_cache_status> sysio::chain::authority_checker< PermissionToAuthorityFunc >::permission_cache_type

Definition at line 70 of file authority_checker.hpp.

Member Enumeration Documentation

◆ permission_cache_status

template<typename PermissionToAuthorityFunc >
enum sysio::chain::authority_checker::permission_cache_status
Enumerator
being_evaluated 
permission_unsatisfied 
permission_satisfied 

Definition at line 64 of file authority_checker.hpp.

Constructor & Destructor Documentation

◆ authority_checker()

template<typename PermissionToAuthorityFunc >
sysio::chain::authority_checker< PermissionToAuthorityFunc >::authority_checker ( PermissionToAuthorityFunc permission_to_authority,
uint16_t recursion_depth_limit,
const flat_set< public_key_type > & provided_keys,
const flat_set< permission_level > & provided_permissions,
fc::microseconds provided_delay,
const std::function< void()> & checktime )
inline

Definition at line 46 of file authority_checker.hpp.

53 :permission_to_authority(permission_to_authority)
54 ,checktime( checktime )
55 ,provided_keys(provided_keys.begin(), provided_keys.end())
56 ,provided_permissions(provided_permissions)
57 ,_used_keys(provided_keys.size(), false)
58 ,provided_delay(provided_delay)
59 ,recursion_depth_limit(recursion_depth_limit)
60 {
61 SYS_ASSERT( static_cast<bool>(checktime), authorization_exception, "checktime cannot be empty" );
62 }
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7

Member Function Documentation

◆ all_keys_used()

template<typename PermissionToAuthorityFunc >
bool sysio::chain::authority_checker< PermissionToAuthorityFunc >::all_keys_used ( ) const
inline

Definition at line 121 of file authority_checker.hpp.

121{ return boost::algorithm::all_of_equal(_used_keys, true); }

◆ permission_status_in_cache()

template<typename PermissionToAuthorityFunc >
static std::optional< permission_cache_status > sysio::chain::authority_checker< PermissionToAuthorityFunc >::permission_status_in_cache ( const permission_cache_type & permissions,
const permission_level & level )
inlinestatic

Definition at line 133 of file authority_checker.hpp.

135 {
136 auto itr = permissions.find( level );
137 if( itr != permissions.end() )
138 return itr->second;
139
140 itr = permissions.find( {level.actor, permission_name()} );
141 if( itr != permissions.end() )
142 return itr->second;
143
144 return std::optional<permission_cache_status>();
145 }
name permission_name
Definition types.hpp:121
uint32_t level
Type of a channel package.
Definition levels.hpp:37

◆ satisfied() [1/4]

template<typename PermissionToAuthorityFunc >
template<typename AuthorityType >
bool sysio::chain::authority_checker< PermissionToAuthorityFunc >::satisfied ( const AuthorityType & authority,
fc::microseconds override_provided_delay,
permission_cache_type * cached_perms = nullptr )
inline

Definition at line 97 of file authority_checker.hpp.

101 {
102 auto delay_reverter = fc::make_scoped_exit( [this, delay = provided_delay] () mutable {
103 provided_delay = delay;
104 });
105
106 provided_delay = override_provided_delay;
107
108 return satisfied( authority, cached_perms );
109 }
bool satisfied(const permission_level &permission, fc::microseconds override_provided_delay, permission_cache_type *cached_perms=nullptr)
void delay(websocketpp::connection_hdl, long duration)
scoped_exit< Callback > make_scoped_exit(Callback &&c)
Here is the call graph for this function:

◆ satisfied() [2/4]

template<typename PermissionToAuthorityFunc >
template<typename AuthorityType >
bool sysio::chain::authority_checker< PermissionToAuthorityFunc >::satisfied ( const AuthorityType & authority,
permission_cache_type * cached_perms = nullptr )
inline

Definition at line 112 of file authority_checker.hpp.

112 {
113 permission_cache_type cached_permissions;
114
115 if( cached_perms == nullptr )
116 cached_perms = initialize_permission_cache( cached_permissions );
117
118 return satisfied( authority, *cached_perms, 0 );
119 }
map< permission_level, permission_cache_status > permission_cache_type
Here is the call graph for this function:

◆ satisfied() [3/4]

template<typename PermissionToAuthorityFunc >
bool sysio::chain::authority_checker< PermissionToAuthorityFunc >::satisfied ( const permission_level & permission,
fc::microseconds override_provided_delay,
permission_cache_type * cached_perms = nullptr )
inline

Definition at line 72 of file authority_checker.hpp.

76 {
77 auto delay_reverter = fc::make_scoped_exit( [this, delay = provided_delay] () mutable {
78 provided_delay = delay;
79 });
80
81 provided_delay = override_provided_delay;
82
83 return satisfied( permission, cached_perms );
84 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ satisfied() [4/4]

template<typename PermissionToAuthorityFunc >
bool sysio::chain::authority_checker< PermissionToAuthorityFunc >::satisfied ( const permission_level & permission,
permission_cache_type * cached_perms = nullptr )
inline

Definition at line 86 of file authority_checker.hpp.

86 {
87 permission_cache_type cached_permissions;
88
89 if( cached_perms == nullptr )
90 cached_perms = initialize_permission_cache( cached_permissions );
91
92 weight_tally_visitor visitor(*this, *cached_perms, 0);
93 return ( visitor(permission_level_weight{permission, 1}) > 0 );
94 }

◆ unused_keys()

template<typename PermissionToAuthorityFunc >
flat_set< public_key_type > sysio::chain::authority_checker< PermissionToAuthorityFunc >::unused_keys ( ) const
inline

Definition at line 127 of file authority_checker.hpp.

127 {
128 auto range = filter_data_by_marker(provided_keys, _used_keys, false);
129 return {range.begin(), range.end()};
130 }
DataRange filter_data_by_marker(DataRange data, MarkerRange markers, const Marker &markerValue)
Return values in DataRange corresponding to matching Markers.
Here is the call graph for this function:

◆ used_keys()

template<typename PermissionToAuthorityFunc >
flat_set< public_key_type > sysio::chain::authority_checker< PermissionToAuthorityFunc >::used_keys ( ) const
inline

Definition at line 123 of file authority_checker.hpp.

123 {
124 auto range = filter_data_by_marker(provided_keys, _used_keys, true);
125 return {range.begin(), range.end()};
126 }
Here is the call graph for this function:

The documentation for this class was generated from the following file: