USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
Public Member Functions | List of all members
usbguard::Rule::Attribute< ValueType > Class Template Reference

Specifies which devices to match or what condition have to be met for the rule to be aplicable. More...

#include <Rule.hpp>

Public Member Functions

 Attribute (const char *name)
 Constructs new rule attribute with a given name and default set operator. More...
 
 Attribute (const Attribute< ValueType > &rhs)=default
 Default copy constructor. More...
 
Attributeoperator= (const Attribute< ValueType > &rhs)=default
 Default copy assignment. More...
 
void setSetOperator (SetOperator op)
 Sets set operator. More...
 
SetOperator setOperator () const
 Returns set operator of this attribute. More...
 
void append (ValueType &&value)
 Appends new value into attribute values using move semantics. More...
 
void append (const ValueType &value)
 Appends new value into attribute values. More...
 
size_t count () const
 Returns number of values of this attribute. More...
 
bool empty () const
 Checks whether attribute does not contain any values. More...
 
void clear ()
 Clears all values of this attribute and sets set operator to default. More...
 
std::string getName () const
 Returns name of the attribute. More...
 
const ValueType & get () const
 Returns value of single-value attribute. More...
 
const ValueType & get (size_t index) const
 Returns value at given index in values vector. More...
 
void set (ValueType &&value)
 Sets value in single-value attribute using move semantics. More...
 
void set (const ValueType &value)
 Sets value in single-value attribute. More...
 
void set (const std::vector< ValueType > &values, SetOperator op)
 Sets given values and set operator. More...
 
bool appliesTo (const Attribute< ValueType > &target) const
 Checks whether attribute applies to target attribute. More...
 
std::string toRuleString () const
 Returns string representation of this attribute. More...
 
const std::vector< ValueType > & values () const
 Returns imutable vector of attribute values. More...
 
std::vector< ValueType > & values ()
 Returns mutable vector of attribute values. More...
 

Detailed Description

template<class ValueType>
class usbguard::Rule::Attribute< ValueType >

Specifies which devices to match or what condition have to be met for the rule to be aplicable.

Attribute can be either single valued or multi-valued in which case set operator may be used to allow finer definition of the rule.

Constructor & Destructor Documentation

◆ Attribute() [1/2]

template<class ValueType>
usbguard::Rule::Attribute< ValueType >::Attribute ( const char *  name)
inline

Constructs new rule attribute with a given name and default set operator.

Note
Default set operator is Equals.
Parameters
nameName of the attribute.

◆ Attribute() [2/2]

template<class ValueType>
usbguard::Rule::Attribute< ValueType >::Attribute ( const Attribute< ValueType > &  rhs)
default

Default copy constructor.

Parameters
rhsAttribute to copy.

Member Function Documentation

◆ append() [1/2]

template<class ValueType>
void usbguard::Rule::Attribute< ValueType >::append ( ValueType &&  value)
inline

Appends new value into attribute values using move semantics.

Parameters
valueValue to append into attribute values.

◆ append() [2/2]

template<class ValueType>
void usbguard::Rule::Attribute< ValueType >::append ( const ValueType &  value)
inline

Appends new value into attribute values.

Parameters
valueValue to append into attribute values.

◆ appliesTo()

template<class ValueType>
bool usbguard::Rule::Attribute< ValueType >::appliesTo ( const Attribute< ValueType > &  target) const
inline

Checks whether attribute applies to target attribute.

In other words, checks whether values of this attribute satisfy set operator against target attribute values.
For example if this.values = { v1 } and target.values = { v1, v2 }, then { v1 } OneOf { v1, v2 } = True.

Parameters
targetTarget attribute to apply to.
Exceptions
USBGUARD_BUGIf attributes set operator is invalid.

◆ clear()

template<class ValueType>
void usbguard::Rule::Attribute< ValueType >::clear ( )
inline

Clears all values of this attribute and sets set operator to default.

Note
Default set operator is Equals.

◆ count()

template<class ValueType>
size_t usbguard::Rule::Attribute< ValueType >::count ( ) const
inline

Returns number of values of this attribute.

Returns
Number of values of this attribute.

◆ empty()

template<class ValueType>
bool usbguard::Rule::Attribute< ValueType >::empty ( ) const
inline

Checks whether attribute does not contain any values.

Returns
True if this attribute does not contain any value, false otherwise.

◆ get() [1/2]

template<class ValueType>
const ValueType& usbguard::Rule::Attribute< ValueType >::get ( ) const
inline

Returns value of single-value attribute.

Returns
Value of single-value attribute.
Exceptions
runtime_errorIf attribute is not single-value or is empty.

◆ get() [2/2]

template<class ValueType>
const ValueType& usbguard::Rule::Attribute< ValueType >::get ( size_t  index) const
inline

Returns value at given index in values vector.

Parameters
indexIndex in values vector.
Returns
Value at given index.
Exceptions
std::out_of_rangeIf index >= number of values.

◆ getName()

template<class ValueType>
std::string usbguard::Rule::Attribute< ValueType >::getName ( ) const
inline

Returns name of the attribute.

Returns
Name of the attribute.

◆ operator=()

template<class ValueType>
Attribute& usbguard::Rule::Attribute< ValueType >::operator= ( const Attribute< ValueType > &  rhs)
default

Default copy assignment.

Parameters
rhsAttribute to copy assign.

◆ set() [1/3]

template<class ValueType>
void usbguard::Rule::Attribute< ValueType >::set ( ValueType &&  value)
inline

Sets value in single-value attribute using move semantics.

Parameters
Valueto set.
Exceptions
runtime_errorIf attribute is multi-value.

◆ set() [2/3]

template<class ValueType>
void usbguard::Rule::Attribute< ValueType >::set ( const ValueType &  value)
inline

Sets value in single-value attribute.

Parameters
Valueto set.
Exceptions
runtime_errorIf attribute is multi-value.

◆ set() [3/3]

template<class ValueType>
void usbguard::Rule::Attribute< ValueType >::set ( const std::vector< ValueType > &  values,
SetOperator  op 
)
inline

Sets given values and set operator.

Parameters
valuesValues to set.
opSet operator to set.

◆ setOperator()

template<class ValueType>
SetOperator usbguard::Rule::Attribute< ValueType >::setOperator ( ) const
inline

Returns set operator of this attribute.

Returns
Set operator of this attribute.

◆ setSetOperator()

template<class ValueType>
void usbguard::Rule::Attribute< ValueType >::setSetOperator ( SetOperator  op)
inline

Sets set operator.

Parameters
opSet operator to set.

◆ toRuleString()

template<class ValueType>
std::string usbguard::Rule::Attribute< ValueType >::toRuleString ( ) const
inline

Returns string representation of this attribute.

Format:

  • single-valued: <name> <value>
  • multi-valued: <name> <non-default set operator> { <value[0]> <value[1]> ... } Default set operator is not included in the string.
Returns
String representation of this attribute.

◆ values() [1/2]

template<class ValueType>
const std::vector<ValueType>& usbguard::Rule::Attribute< ValueType >::values ( ) const
inline

Returns imutable vector of attribute values.

Returns
Imutable vector of attribute values.

◆ values() [2/2]

template<class ValueType>
std::vector<ValueType>& usbguard::Rule::Attribute< ValueType >::values ( )
inline

Returns mutable vector of attribute values.

Returns
Mutable vector of attribute values.

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