USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
Public Member Functions | Static Public Member Functions | List of all members
usbguard::RuleConditionBase Class Referenceabstract

Base class for all specialized rule condition classes. More...

#include <RuleCondition.hpp>

Public Member Functions

 RuleConditionBase (const std::string &identifier, const std::string &parameter, bool negated=false)
 Constructs new rule condition. More...
 
 RuleConditionBase (const std::string &identifier, bool negated=false)
 Constructs new rule condition without a parameter. More...
 
 RuleConditionBase (const RuleConditionBase &rhs)
 Constructs new rule condition with the same attributes as rhs. More...
 
virtual ~RuleConditionBase ()
 Calls fini() and destroys this object. More...
 
virtual void init (Interface *const interface_ptr)
 Initialization algorithm for this object. More...
 
virtual void fini ()
 Implement what should be done before destroying this object.
 
virtual bool update (const Rule &rule)=0
 Implement update algorithm for this object. More...
 
virtual RuleConditionBaseclone () const =0
 Implement cloning algorithm for this object. More...
 
bool evaluate (const Rule &rule)
 Evaluate based on given rule. More...
 
const std::string & identifier () const
 Returns rule condition identifier/name. More...
 
const std::string & parameter () const
 Returns parameter of rule condition. More...
 
bool hasParameter () const
 Checks whether rule condition has parameter. More...
 
bool isNegated () const
 Checks whether this rule condition is negated or not. More...
 
const std::string toString () const
 Returns string representation of this rule condition. More...
 
const std::string toRuleString () const
 Returns string representation of this rule condition. More...
 

Static Public Member Functions

static RuleConditionBasegetImplementation (const std::string &condition_string)
 Parses given rule string and constructs new specialized rule condition object. More...
 
static RuleConditionBasegetImplementation (const std::string &identifier, const std::string &parameter, bool negated)
 Constructs new specialized rule condition object based on given arguments. More...
 

Detailed Description

Base class for all specialized rule condition classes.

Constructor & Destructor Documentation

◆ RuleConditionBase() [1/3]

usbguard::RuleConditionBase::RuleConditionBase ( const std::string &  identifier,
const std::string &  parameter,
bool  negated = false 
)

Constructs new rule condition.

Parameters
identifierIdentifier/name of rule condition.
parameterParameter of rule condition.
negatedDefines whether rule condition should be negated or not. Rule condition is defaultly not negated.

◆ RuleConditionBase() [2/3]

usbguard::RuleConditionBase::RuleConditionBase ( const std::string &  identifier,
bool  negated = false 
)

Constructs new rule condition without a parameter.

Parameters
identifierIdentifier/name of rule condition.
negatedDefines whether rule condition should be negated or not. Rule condition is defaultly not negated.

◆ RuleConditionBase() [3/3]

usbguard::RuleConditionBase::RuleConditionBase ( const RuleConditionBase rhs)

Constructs new rule condition with the same attributes as rhs.

Parameters
rhsRule condition to copy.

◆ ~RuleConditionBase()

usbguard::RuleConditionBase::~RuleConditionBase ( )
virtual

Calls fini() and destroys this object.

See also
fini()

Member Function Documentation

◆ clone()

virtual RuleConditionBase* usbguard::RuleConditionBase::clone ( ) const
pure virtual

Implement cloning algorithm for this object.

Returns
Clone of this object.

◆ evaluate()

bool usbguard::RuleConditionBase::evaluate ( const Rule rule)

Evaluate based on given rule.

Evaluation returns true if update(rule) succeeds or if this condition is negated then returns true if update(rule) does not succeed.

Parameters
ruleRule to evaluate.
Returns
True if rule has been evaluated successfully, false otherwise.
See also
update()

◆ getImplementation() [1/2]

RuleConditionBase * usbguard::RuleConditionBase::getImplementation ( const std::string &  condition_string)
static

Parses given rule string and constructs new specialized rule condition object.

Parameters
condition_stringString should be a valid rule string.
Returns
Pointer to newly constructed specialized rule condition object.
Exceptions
runtime_errorIf given string is empty or does not contain a valid rule.

◆ getImplementation() [2/2]

RuleConditionBase * usbguard::RuleConditionBase::getImplementation ( const std::string &  identifier,
const std::string &  parameter,
bool  negated 
)
static

Constructs new specialized rule condition object based on given arguments.

Parameters
identifierIdentifies what rule condition object should be constructed.
parameterParameter of new rule condition.
negatedDefines whether new rule condition is negated or not.
Returns
Pointer to newly constructed specialized rule condition object.
Exceptions
runtime_errorIf identifier is not valid.

◆ hasParameter()

bool usbguard::RuleConditionBase::hasParameter ( ) const

Checks whether rule condition has parameter.

In other words, checks whether the parameter is not empty.

Returns
True if rule condition has parameter, false otherwise.

◆ identifier()

const std::string & usbguard::RuleConditionBase::identifier ( ) const

Returns rule condition identifier/name.

Returns
rule condition identifier/name.

◆ init()

void usbguard::RuleConditionBase::init ( Interface *const  interface_ptr)
virtual

Initialization algorithm for this object.

Parameters
interface_ptrPointer to the interface.

◆ isNegated()

bool usbguard::RuleConditionBase::isNegated ( ) const

Checks whether this rule condition is negated or not.

Returns
True if this rule condition is negated, false otherwise.

◆ parameter()

const std::string & usbguard::RuleConditionBase::parameter ( ) const

Returns parameter of rule condition.

Returns
Parameter of rule condition.

◆ toRuleString()

const std::string usbguard::RuleConditionBase::toRuleString ( ) const

Returns string representation of this rule condition.

  • Format: [!]<identifier>[(<parameter>)]
  • Example 1: !rule-evaluated
  • Example 2: random(0.1666)
Returns
String representation of this rule condition.

◆ toString()

const std::string usbguard::RuleConditionBase::toString ( ) const

Returns string representation of this rule condition.

  • Format: [!]<identifier>[(<parameter>)]
  • Example 1: !rule-evaluated
  • Example 2: random(0.1666)
Returns
String representation of this rule condition.

◆ update()

virtual bool usbguard::RuleConditionBase::update ( const Rule rule)
pure virtual

Implement update algorithm for this object.

Parameters
ruleYou might want to update based on some rule.
Returns
True if update is successful, false otherwise.

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