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

Class to get keys based on access level, and to check access levels. More...

#include <cs_KeysAndAccess.h>

Public Member Functions

void init ()
 Init the class: reads from State. More...
 
bool allowAccess (EncryptionAccessLevel minimum, EncryptionAccessLevel provided)
 Verify if the access level provided is sufficient. More...
 
bool getKey (EncryptionAccessLevel accessLevel, buffer_ptr_t outBuf, cs_buffer_size_t outBufSize)
 Get key of given access level. More...
 
cs_data_t getSetupKey ()
 Get a pointer to the setup key. More...
 
void generateSetupKey ()
 Generate a new setup key. More...
 
cs_ret_code_t setSetupKey (cs_data_t data)
 Set the setup key. More...
 
void invalidateSetupKey ()
 Invalidate the setup key. More...
 

Static Public Member Functions

static KeysAndAccess & getInstance ()
 Use static variant of singleton, no dynamic memory allocation. More...
 

Private Member Functions

 KeysAndAccess ()
 
 KeysAndAccess (KeysAndAccess const &)
 
void operator= (KeysAndAccess const &)
 

Private Attributes

OperationMode _operationMode = OperationMode::OPERATION_MODE_UNINITIALIZED
 Cached operation mode. More...
 
bool _encryptionEnabled = true
 Cache of whether encryption is enabled. More...
 
uint8_t _setupKey [ENCRYPTION_KEY_LENGTH]
 Current setup key. More...
 
bool _setupKeyValid = false
 Whether the setup key is valid. More...
 

Detailed Description

Class to get keys based on access level, and to check access levels.

  • Generates temporary keys.
  • Caches state.

Constructor & Destructor Documentation

◆ KeysAndAccess() [1/2]

◆ KeysAndAccess() [2/2]

Member Function Documentation

◆ allowAccess()

bool KeysAndAccess::allowAccess ( EncryptionAccessLevel  minimum,
EncryptionAccessLevel  provided 
)

Verify if the access level provided is sufficient.

Parameters
[in]minimumMinimum required access level.
[in]providedProvided access level.
Returns
True when provided access level meets the minimum required level.

◆ generateSetupKey()

void KeysAndAccess::generateSetupKey ( )

Generate a new setup key.

Will only do so if operation mode is setup.

◆ getInstance()

static KeysAndAccess & KeysAndAccess::getInstance ( )
inlinestatic

Use static variant of singleton, no dynamic memory allocation.

◆ getKey()

bool KeysAndAccess::getKey ( EncryptionAccessLevel  accessLevel,
buffer_ptr_t  outBuf,
cs_buffer_size_t  outBufSize 
)

Get key of given access level.

Parameters
[in]accessLevelAccess level of which to get the key.
[out]outBufBuffer to write the key to.
[in]outBufSizeSize of the buffer.
Returns
True on success.

◆ getSetupKey()

cs_data_t KeysAndAccess::getSetupKey ( )

Get a pointer to the setup key.

Returns
Pointer and size of key. Pointer can be NULL when setup key is unavailable.

◆ init()

void KeysAndAccess::init ( )

Init the class: reads from State.

◆ invalidateSetupKey()

void KeysAndAccess::invalidateSetupKey ( )

Invalidate the setup key.

◆ operator=()

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

◆ setSetupKey()

cs_ret_code_t KeysAndAccess::setSetupKey ( cs_data_t  data)

Set the setup key.

To be used when connecting to another crownstone.

Parameters
[in]dataThe key that has been read.
Returns
ERR_WRONG_PAYLOAD_LENGTH When the data is of incorrect size.
ERR_SUCCESS When the setup key is set.

Member Data Documentation

◆ _encryptionEnabled

bool KeysAndAccess::_encryptionEnabled = true
private

Cache of whether encryption is enabled.

◆ _operationMode

OperationMode KeysAndAccess::_operationMode = OperationMode::OPERATION_MODE_UNINITIALIZED
private

Cached operation mode.

◆ _setupKey

uint8_t KeysAndAccess::_setupKey[ENCRYPTION_KEY_LENGTH]
private

Current setup key.

◆ _setupKeyValid

bool KeysAndAccess::_setupKeyValid = false
private

Whether the setup key is valid.


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