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::USBDeviceID Class Reference

Represents ID of a USB device. More...

#include <USB.hpp>

Public Member Functions

 USBDeviceID ()=default
 Default constructor.
 
 USBDeviceID (const std::string &vendor_id, const std::string &product_id=std::string())
 Constructs a new ID with vendor_id and product_id. More...
 
 USBDeviceID (const USBDeviceID &rhs)=default
 Default copy constructor. More...
 
USBDeviceIDoperator= (const USBDeviceID &rhs)=default
 Default copy assignment. More...
 
void setVendorID (const std::string &vendor_id)
 Sets vendor ID. More...
 
void setProductID (const std::string &product_id)
 Sets product ID. More...
 
const std::string & getVendorID () const
 Returns vendor ID. More...
 
const std::string & getProductID () const
 Returns product ID. More...
 
std::string toRuleString () const
 Returns ID in form of a string. More...
 
std::string toString () const
 Same as toRuleString(). More...
 
bool isSubsetOf (const USBDeviceID &rhs) const
 Checks if ID is subset of other ID. More...
 

Static Public Member Functions

static void checkDeviceID (const std::string &vendor_id, const std::string &product_id)
 Checks if ID has a valid format. More...
 

Detailed Description

Represents ID of a USB device.

Format: <vendor id>:<product id>
Example: ffff:ffff

Constructor & Destructor Documentation

◆ USBDeviceID() [1/2]

usbguard::USBDeviceID::USBDeviceID ( const std::string &  vendor_id,
const std::string &  product_id = std::string() 
)

Constructs a new ID with vendor_id and product_id.

Also performs checkDeviceID().

Parameters
vendor_idVendor ID.
product_idProduct ID.
Exceptions
runtime_errorIf ID would have invalid format.

◆ USBDeviceID() [2/2]

usbguard::USBDeviceID::USBDeviceID ( const USBDeviceID rhs)
default

Default copy constructor.

Parameters
rhsUSBDeviceID to copy.

Member Function Documentation

◆ checkDeviceID()

void usbguard::USBDeviceID::checkDeviceID ( const std::string &  vendor_id,
const std::string &  product_id 
)
static

Checks if ID has a valid format.

If vendor id is empty or * then product id must also be empty or *. Both vendor id and product id can not be larger then their maximum size.

Parameters
vendor_idVendor ID.
product_idProduct ID.
Exceptions
runtime_errorIf ID has invalid format.

◆ getProductID()

const std::string & usbguard::USBDeviceID::getProductID ( ) const

Returns product ID.

Returns
Product ID.

◆ getVendorID()

const std::string & usbguard::USBDeviceID::getVendorID ( ) const

Returns vendor ID.

Returns
Vendor ID.

◆ isSubsetOf()

bool usbguard::USBDeviceID::isSubsetOf ( const USBDeviceID rhs) const

Checks if ID is subset of other ID.

Basically checks if both IDs have the same vendor and product ID. Either vendor or product ID can be empty and it might still be a subset.

Parameters
rhsID to compare with.
Returns
True if this ID is subset of rhs ID, false otherwise.

◆ operator=()

USBDeviceID& usbguard::USBDeviceID::operator= ( const USBDeviceID rhs)
default

Default copy assignment.

Parameters
rhsUSBDeviceID to copy.
Returns
New USBDeviceID object.

◆ setProductID()

void usbguard::USBDeviceID::setProductID ( const std::string &  product_id)

Sets product ID.

Also performs checkDeviceID().

Parameters
product_idProduct ID.
Exceptions
runtime_errorIf product ID invalidates ID format. Respectively, if setting product_id would cause checkDeviceID() to fail.

◆ setVendorID()

void usbguard::USBDeviceID::setVendorID ( const std::string &  vendor_id)

Sets vendor ID.

Also performs checkDeviceID().

Parameters
vendor_idVendor ID.
Exceptions
runtime_errorIf vendor ID invalidates ID format. Respectively, if setting vendor_id would cause checkDeviceID() to fail.

◆ toRuleString()

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

Returns ID in form of a string.

String has the form: <vendor id>:<product id>.

Returns
ID in form of a string.

◆ toString()

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

Same as toRuleString().

Returns
ID in form of a string.

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