PIP 5.6.1
Platform-Independent Primitives
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
PIEthUtilBase Class Reference

Base helper that adds optional packet encryption to transport utilities. More...

#include <piethutilbase.h>

Inheritance diagram for PIEthUtilBase:
Inheritance graph
[legend]

Public Member Functions

 PIEthUtilBase ()
 Constructs helper with crypt layer disabled.
 
 ~PIEthUtilBase ()
 Destroys the crypt helper.
 
void setCryptEnabled (bool on)
 Enables or disables the crypt layer.
 
void cryptEnable ()
 Enables the crypt layer.
 
void cryptDisable ()
 Disables the crypt layer.
 
bool isCryptEnabled () const
 Returns whether the crypt layer is enabled.
 
void setCryptKey (const PIByteArray &k)
 Sets crypt key "k" and enables the crypt layer.
 
void createCryptKey (const PIString &k)
 Generates crypt key from passphrase "k" and enables the crypt layer.
 
PIByteArray cryptKey () const
 Returns current crypt key.
 

Static Public Member Functions

static size_t cryptSizeAddition ()
 Returns extra size added by encryption.
 

Protected Member Functions

PIByteArray cryptData (const PIByteArray &data)
 Encrypts "data" when the crypt layer is enabled.
 
PIByteArray decryptData (const PIByteArray &data)
 Decrypts "data" when the crypt layer is enabled. More...
 

Detailed Description

Base helper that adds optional packet encryption to transport utilities.

Base class for ethernet utils.

Synopsis

PIEthUtilBase provides crypt layer for derived classes: PIStreamPacker and PIBroadcast. All input and output (sended and received) data can be decrypted/encrypted by this layer.

By default crypt layer is disabled.

You can separetely enable it and set ready-to-use key by setCryptEnabled() and setCryptKey(). Or you can use createCryptKey() to generate key from your passphrase and automatic enable crypt layer.

Note
To use crypt layer, PIP should be built with crypt module, otherwise your in/out data will be lost.

You can use this class as base for your own classes. Use cryptData() and decryptData() when send and receive your data.

Member Function Documentation

◆ decryptData()

PIByteArray PIEthUtilBase::decryptData ( const PIByteArray data)
protected

Decrypts "data" when the crypt layer is enabled.

Returns decrypted data if layer enabled, otherwise returns unchanged "data". If decryption was unsuccessful returns empty PIByteArray