Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_KeysAndAccess.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Oct 16, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
10#include <common/cs_Types.h>
11#include <protocol/cs_Packets.h>
12
20public:
23 static KeysAndAccess instance;
24 return instance;
25 }
26
30 void init();
31
40
49 bool getKey(EncryptionAccessLevel accessLevel, buffer_ptr_t outBuf, cs_buffer_size_t outBufSize);
50
57
64
74
79
80private:
81 // This class is singleton, make constructor private.
83
84 // This class is singleton, deny implementation
86
87 // This class is singleton, deny implementation
89
93 OperationMode _operationMode = OperationMode::OPERATION_MODE_UNINITIALIZED;
94
98 bool _encryptionEnabled = true;
99
104
108 bool _setupKeyValid = false;
109};
Class to get keys based on access level, and to check access levels.
Definition: cs_KeysAndAccess.h:19
OperationMode _operationMode
Cached operation mode.
Definition: cs_KeysAndAccess.h:93
uint8_t _setupKey[ENCRYPTION_KEY_LENGTH]
Current setup key.
Definition: cs_KeysAndAccess.h:103
void generateSetupKey()
Generate a new setup key.
void invalidateSetupKey()
Invalidate the setup key.
bool _encryptionEnabled
Cache of whether encryption is enabled.
Definition: cs_KeysAndAccess.h:98
void operator=(KeysAndAccess const &)
bool _setupKeyValid
Whether the setup key is valid.
Definition: cs_KeysAndAccess.h:108
static KeysAndAccess & getInstance()
Use static variant of singleton, no dynamic memory allocation.
Definition: cs_KeysAndAccess.h:22
bool getKey(EncryptionAccessLevel accessLevel, buffer_ptr_t outBuf, cs_buffer_size_t outBufSize)
Get key of given access level.
KeysAndAccess(KeysAndAccess const &)
cs_ret_code_t setSetupKey(cs_data_t data)
Set the setup key.
void init()
Init the class: reads from State.
bool allowAccess(EncryptionAccessLevel minimum, EncryptionAccessLevel provided)
Verify if the access level provided is sufficient.
cs_data_t getSetupKey()
Get a pointer to the setup key.
#define ENCRYPTION_KEY_LENGTH
Definition: cs_Config.h:162
EncryptionAccessLevel
Packets (structs) that are used over the air, over uart, or stored in flash.
Definition: cs_Packets.h:36
uint16_t cs_buffer_size_t
Definition: cs_Typedefs.h:20
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
uint8_t * buffer_ptr_t
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: 10 May....
Definition: cs_Typedefs.h:19
OperationMode
Definition: cs_Types.h:440
Packets (structs) that are used internally in the firmware, and can be changed freely.
Definition: cs_PacketsInternal.h:27