Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_ConnectionEncryption.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Oct 21, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
11#include <protocol/cs_Packets.h>
13
14#define DEFAULT_VALIDATION_KEY 0xCAFEBABE
15
17
19public:
22 static ConnectionEncryption instance;
23 return instance;
24 }
25
29 void init();
30
41 cs_data_t input,
42 cs_data_t output,
43 EncryptionAccessLevel accessLevel,
44 ConnectionEncryptionType encryptionType);
45
56 cs_data_t input,
57 cs_data_t output,
58 EncryptionAccessLevel& accessLevel,
59 ConnectionEncryptionType encryptionType);
60
70 cs_buffer_size_t plaintextBufferSize, ConnectionEncryptionType encryptionType);
71
80 cs_buffer_size_t encryptedBufferSize, ConnectionEncryptionType encryptionType);
81
91
95 void disconnect();
96
100 void handleEvent(event_t& event) override;
101
102private:
103 // This class is singleton, make constructor private.
105
106 // This class is singleton, deny implementation
108
109 // This class is singleton, deny implementation
111
116
123
130};
Definition: cs_ConnectionEncryption.h:18
void disconnect()
Close connection due to insufficient access.
void generateSessionData()
Generate new session data.
static cs_buffer_size_t getPlaintextBufferSize(cs_buffer_size_t encryptedBufferSize, ConnectionEncryptionType encryptionType)
Get the required output buffer size when decrypting encrypted data.
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.
ConnectionEncryption(ConnectionEncryption const &)
encryption_nonce_t _nonce
Nonce used for encryption and decryption.
Definition: cs_ConnectionEncryption.h:122
static ConnectionEncryption & getInstance()
Use static variant of singleton, no dynamic memory allocation.
Definition: cs_ConnectionEncryption.h:21
void init()
Initialize the class, reads from State.
static cs_buffer_size_t getEncryptedBufferSize(cs_buffer_size_t plaintextBufferSize, ConnectionEncryptionType encryptionType)
Get the required output buffer size when encrypting plaintext.
cs_ret_code_t encrypt(cs_data_t input, cs_data_t output, EncryptionAccessLevel accessLevel, ConnectionEncryptionType encryptionType)
Add headers and encrypt data.
session_data_t _sessionData
Session data: data that's valid for a whole session (connection).
Definition: cs_ConnectionEncryption.h:115
void operator=(ConnectionEncryption const &)
cs_ret_code_t setSessionData(session_data_t &sessionData)
Set session data.
void handleEvent(event_t &event) override
Handle events.
Event listener.
Definition: cs_EventListener.h:17
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
ConnectionEncryptionType
Definition: cs_ConnectionEncryption.h:16
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
Packets (structs) that are used internally in the firmware, and can be changed freely.
Definition: cs_PacketsInternal.h:27
Nonce used for encryption.
Definition: cs_Packets.h:51
Definition: cs_Packets.h:71