Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
ConnectionEncryption Class Reference

#include <cs_ConnectionEncryption.h>

Inheritance diagram for ConnectionEncryption:
Collaboration diagram for ConnectionEncryption:

Public Member Functions

void init ()
 Initialize the class, reads from State. More...
 
cs_ret_code_t encrypt (cs_data_t input, cs_data_t output, EncryptionAccessLevel accessLevel, ConnectionEncryptionType encryptionType)
 Add headers and encrypt data. More...
 
cs_ret_code_t decrypt (cs_data_t input, cs_data_t output, EncryptionAccessLevel &accessLevel, ConnectionEncryptionType encryptionType)
 Parses headers, decrypts data, and validates decrypted data. More...
 
cs_ret_code_t setSessionData (session_data_t &sessionData)
 Set session data. More...
 
void disconnect ()
 Close connection due to insufficient access. More...
 
void handleEvent (event_t &event) override
 Handle events. More...
 

Static Public Member Functions

static ConnectionEncryptiongetInstance ()
 Use static variant of singleton, no dynamic memory allocation. More...
 
static cs_buffer_size_t getEncryptedBufferSize (cs_buffer_size_t plaintextBufferSize, ConnectionEncryptionType encryptionType)
 Get the required output buffer size when encrypting plaintext. More...
 
static cs_buffer_size_t getPlaintextBufferSize (cs_buffer_size_t encryptedBufferSize, ConnectionEncryptionType encryptionType)
 Get the required output buffer size when decrypting encrypted data. More...
 

Private Member Functions

 ConnectionEncryption ()
 
 ConnectionEncryption (ConnectionEncryption const &)
 
void operator= (ConnectionEncryption const &)
 
void generateSessionData ()
 Generate new session data. More...
 
- Private Member Functions inherited from EventListener
 EventListener ()
 
virtual ~EventListener ()
 unregisters the listener. More...
 
virtual void handleEvent (event_t &event)=0
 Handle events. More...
 
void listen ()
 Registers this with the EventDispatcher. More...
 

Private Attributes

session_data_t _sessionData
 Session data: data that's valid for a whole session (connection). More...
 
encryption_nonce_t _nonce
 Nonce used for encryption and decryption. More...
 

Constructor & Destructor Documentation

◆ ConnectionEncryption() [1/2]

◆ ConnectionEncryption() [2/2]

Member Function Documentation

◆ decrypt()

cs_ret_code_t ConnectionEncryption::decrypt ( cs_data_t  input,
cs_data_t  output,
EncryptionAccessLevel accessLevel,
ConnectionEncryptionType  encryptionType 
)

Parses headers, decrypts data, and validates decrypted data.

Parameters
[in]inputInput data to be parsed and decrypted.
[out]outputBuffer to write decrypted payload to.
[out]accessLevelAccess level that was used for encryption.
[in]encryptionTypeType of encryption to use.
Returns
Return code.

◆ disconnect()

void ConnectionEncryption::disconnect ( )

Close connection due to insufficient access.

◆ encrypt()

cs_ret_code_t ConnectionEncryption::encrypt ( cs_data_t  input,
cs_data_t  output,
EncryptionAccessLevel  accessLevel,
ConnectionEncryptionType  encryptionType 
)

Add headers and encrypt data.

Parameters
[in]inputInput data to be encrypted.
[out]outputBuffer to write headers and encrypted data to.
[in]accessLevelAccess level to use for encryption.
[in]encryptionTypeType of encryption to use.
Returns
Return code.

◆ generateSessionData()

void ConnectionEncryption::generateSessionData ( )
private

Generate new session data.

To be called on connect.

◆ getEncryptedBufferSize()

static cs_buffer_size_t ConnectionEncryption::getEncryptedBufferSize ( cs_buffer_size_t  plaintextBufferSize,
ConnectionEncryptionType  encryptionType 
)
static

Get the required output buffer size when encrypting plaintext.

Parameters
[in]plaintextBufferSizeSize of the buffer with the payload that will be encrypted.
[in]encryptionTypeType of encryption to use.
Returns
Required size of the buffer that will hold the encryption headers and encrypted payload.

◆ getInstance()

static ConnectionEncryption & ConnectionEncryption::getInstance ( )
inlinestatic

Use static variant of singleton, no dynamic memory allocation.

◆ getPlaintextBufferSize()

static cs_buffer_size_t ConnectionEncryption::getPlaintextBufferSize ( cs_buffer_size_t  encryptedBufferSize,
ConnectionEncryptionType  encryptionType 
)
static

Get the required output buffer size when decrypting encrypted data.

Parameters
[in]encryptedBufferSizeSize of the buffer with encryption headers and encrypted payload.
[in]encryptionTypeType of encryption to use.
Returns
Required size of the buffer that will hold the decrypted payload.

◆ handleEvent()

void ConnectionEncryption::handleEvent ( event_t event)
overridevirtual

Handle events.

Implements EventListener.

◆ init()

void ConnectionEncryption::init ( )

Initialize the class, reads from State.

◆ operator=()

void ConnectionEncryption::operator= ( ConnectionEncryption const &  )
private

◆ setSessionData()

cs_ret_code_t ConnectionEncryption::setSessionData ( session_data_t sessionData)

Set session data.

To be used when connecting to another crownstone.

Parameters
[in]sessionDataThe session data that has been read.
Returns
ERR_PROTOCOL_UNSUPPORTED When the protocol is not supported.
ERR_SUCCESS When the session data is set.

Member Data Documentation

◆ _nonce

encryption_nonce_t ConnectionEncryption::_nonce
private

Nonce used for encryption and decryption.

Cached because it holds the session nonce.

◆ _sessionData

session_data_t ConnectionEncryption::_sessionData
private

Session data: data that's valid for a whole session (connection).


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