idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::nvs::flash Class Reference

#include <idfxx_nvs/include/idfxx/nvs.hpp>

Classes

struct  insecure_t
 Tag type to indicate insecure (non-encrypted) initialization. More...
 
struct  secure_config
 Key for encryption and decryption. More...
 

Public Member Functions

 flash ()=delete
 

Static Public Member Functions

static void init ()
 Initializes the default NVS partition.
 
static void init (const secure_config &cfg)
 Initialize the default NVS partition with encryption.
 
static void init (insecure_t)
 Initialize the default NVS partition without encryption.
 
static void init (std::string_view partition_label)
 Initialize NVS flash storage for the specified partition.
 
static void init (std::string_view partition_label, const secure_config &cfg)
 Initialize NVS flash storage for the specified partition.
 
static void init (insecure_t, std::string_view partition_label)
 Initialize NVS flash storage for the specified partition without encryption.
 
static result< void > try_init ()
 Initializes the default NVS partition.
 
static result< void > try_init (const secure_config &cfg)
 Initialize the default NVS partition with encryption.
 
static result< void > try_init (insecure_t)
 Initialize the default NVS partition without encryption.
 
static result< void > try_init (std::string_view partition_label)
 Initialize NVS flash storage for the specified partition.
 
static result< void > try_init (std::string_view partition_label, const secure_config &cfg)
 Initialize NVS flash storage for the specified partition.
 
static result< void > try_init (insecure_t, std::string_view partition_label)
 Initialize NVS flash storage for the specified partition without encryption.
 
static void deinit ()
 Deinitialize NVS storage for the default NVS partition.
 
static void deinit (std::string_view partition_label)
 Deinitialize NVS storage for the specified partition.
 
static result< void > try_deinit ()
 Deinitialize NVS storage for the default NVS partition.
 
static result< void > try_deinit (std::string_view partition_label)
 Deinitialize NVS storage for the specified partition.
 
static void erase ()
 Erases the default NVS partition.
 
static void erase (std::string_view partition_label)
 Erase specified NVS partition.
 
static result< void > try_erase ()
 Erases the default NVS partition.
 
static result< void > try_erase (std::string_view partition_label)
 Erases the specified NVS partition.
 

Static Public Attributes

static constexpr size_t key_size = 32
 
static constexpr insecure_t insecure {}
 Insecure (non-encrypted) initialization tag.
 

Detailed Description

Definition at line 342 of file nvs.hpp.

Constructor & Destructor Documentation

◆ flash()

idfxx::nvs::flash::flash ( )
delete

Member Function Documentation

◆ deinit() [1/2]

static void idfxx::nvs::flash::deinit ( )
inlinestatic

Deinitialize NVS storage for the default NVS partition.

Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 556 of file nvs.hpp.

References idfxx::unwrap().

◆ deinit() [2/2]

static void idfxx::nvs::flash::deinit ( std::string_view  partition_label)
inlinestatic

Deinitialize NVS storage for the specified partition.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 566 of file nvs.hpp.

References idfxx::unwrap().

◆ erase() [1/2]

static void idfxx::nvs::flash::erase ( )
inlinestatic

Erases the default NVS partition.

Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 592 of file nvs.hpp.

References idfxx::unwrap().

◆ erase() [2/2]

static void idfxx::nvs::flash::erase ( std::string_view  partition_label)
inlinestatic

Erase specified NVS partition.

Parameters
partition_labelLabel of the partition which should be erased
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 602 of file nvs.hpp.

References idfxx::unwrap().

◆ init() [1/6]

static void idfxx::nvs::flash::init ( )
inlinestatic

Initializes the default NVS partition.

This API initialises the default NVS partition. The default NVS partition is the one that is labeled "nvs" in the partition table.

When "NVS_ENCRYPTION" is enabled in the menuconfig, this API enables the NVS encryption for the default NVS partition as follows

  1. Read security configurations from the first NVS key partition listed in the partition table. (NVS key partition is any "data" type partition which has the subtype value set to "nvs_keys")
  2. If the NVS key partition obtained in the previous step is empty, generate and store new keys in that NVS key partition.
  3. Internally call "nvs::flash::secure_init()" with the security configurations obtained/generated in the previous steps.

Post initialization NVS read/write APIs remain the same irrespective of NVS encryption.

Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 388 of file nvs.hpp.

References idfxx::unwrap().

◆ init() [2/6]

static void idfxx::nvs::flash::init ( const secure_config cfg)
inlinestatic

Initialize the default NVS partition with encryption.

This API initialises the default NVS partition. The default NVS partition is the one that is labeled "nvs" in the partition table.

Parameters
cfgSecurity configuration (keys) to be used for NVS encryption/decryption.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 401 of file nvs.hpp.

References idfxx::unwrap().

◆ init() [3/6]

static void idfxx::nvs::flash::init ( insecure_t  )
inlinestatic

Initialize the default NVS partition without encryption.

This API initialises the default NVS partition. The default NVS partition is the one that is labeled "nvs" in the partition table.

Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 412 of file nvs.hpp.

References idfxx::unwrap().

◆ init() [4/6]

static void idfxx::nvs::flash::init ( insecure_t  ,
std::string_view  partition_label 
)
inlinestatic

Initialize NVS flash storage for the specified partition without encryption.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 445 of file nvs.hpp.

References idfxx::unwrap().

◆ init() [5/6]

static void idfxx::nvs::flash::init ( std::string_view  partition_label)
inlinestatic

Initialize NVS flash storage for the specified partition.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 422 of file nvs.hpp.

References idfxx::unwrap().

◆ init() [6/6]

static void idfxx::nvs::flash::init ( std::string_view  partition_label,
const secure_config cfg 
)
inlinestatic

Initialize NVS flash storage for the specified partition.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
cfgSecurity configuration (keys) to be used for NVS encryption/decryption
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

Definition at line 433 of file nvs.hpp.

References idfxx::unwrap().

◆ try_deinit() [1/2]

static result< void > idfxx::nvs::flash::try_deinit ( )
static

Deinitialize NVS storage for the default NVS partition.

Returns
Success, or an error.
Return values
nvs::errc::not_initializedif the storage was not initialized prior to this call.

◆ try_deinit() [2/2]

static result< void > idfxx::nvs::flash::try_deinit ( std::string_view  partition_label)
static

Deinitialize NVS storage for the specified partition.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
Returns
Success, or an error.
Return values
nvs::errc::not_initializedif the storage was not initialized prior to this call.

◆ try_erase() [1/2]

static result< void > idfxx::nvs::flash::try_erase ( )
static

Erases the default NVS partition.

Returns
Success, or an error.
Return values
nvs::errc::not_foundif there is no NVS partition labeled "nvs" in the partition table.

◆ try_erase() [2/2]

static result< void > idfxx::nvs::flash::try_erase ( std::string_view  partition_label)
static

Erases the specified NVS partition.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
Returns
Success, or an error.
Return values
nvs::errc::not_foundif specified partition is not found in the partition table.

◆ try_init() [1/6]

static result< void > idfxx::nvs::flash::try_init ( )
static

Initializes the default NVS partition.

This API initialises the default NVS partition. The default NVS partition is the one that is labeled "nvs" in the partition table.

When "NVS_ENCRYPTION" is enabled in the menuconfig, this API enables the NVS encryption for the default NVS partition as follows

  1. Read security configurations from the first NVS key partition listed in the partition table. (NVS key partition is any "data" type partition which has the subtype value set to "nvs_keys")
  2. If the NVS key partition obtained in the previous step is empty, generate and store new keys in that NVS key partition.
  3. Internally call "nvs::flash::try_init()" with the security configurations obtained/generated in the previous steps.

Post initialization NVS read/write APIs remain the same irrespective of NVS encryption.

Returns
Success, or an error.
Return values
nvs::errc::no_free_pagesif the NVS storage contains no empty pages (which may happen if NVS partition was truncated).
nvs::errc::part_not_foundif no partition with label "nvs" is found in the partition table.
nvs::errc::no_memin case memory could not be allocated for the internal structures.
Othererror codes from the underlying flash storage driver.

◆ try_init() [2/6]

static result< void > idfxx::nvs::flash::try_init ( const secure_config cfg)
static

Initialize the default NVS partition with encryption.

This API initialises the default NVS partition. The default NVS partition is the one that is labeled "nvs" in the partition table.

Parameters
cfgSecurity configuration (keys) to be used for NVS encryption/decryption.
Returns
Success, or an error.
Return values
nvs::errc::no_free_pagesif the NVS storage contains no empty pages (which may happen if NVS partition was truncated).
nvs::errc::part_not_foundif no partition with label "nvs" is found in the partition table.
nvs::errc::no_memin case memory could not be allocated for the internal structures.
Othererror codes from the underlying flash storage driver.

◆ try_init() [3/6]

static result< void > idfxx::nvs::flash::try_init ( insecure_t  )
static

Initialize the default NVS partition without encryption.

This API initialises the default NVS partition. The default NVS partition is the one that is labeled "nvs" in the partition table.

Returns
Success, or an error.
Return values
nvs::errc::no_free_pagesif the NVS storage contains no empty pages (which may happen if NVS partition was truncated).
nvs::errc::part_not_foundif no partition with label "nvs" is found in the partition table.
nvs::errc::no_memin case memory could not be allocated for the internal structures.
Othererror codes from the underlying flash storage driver.

◆ try_init() [4/6]

static result< void > idfxx::nvs::flash::try_init ( insecure_t  ,
std::string_view  partition_label 
)
static

Initialize NVS flash storage for the specified partition without encryption.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
Returns
Success, or an error.
Return values
nvs::errc::no_free_pagesif the NVS storage contains no empty pages (which may happen if NVS partition was truncated).
nvs::errc::not_foundif specified partition is not found in the partition table.
nvs::errc::no_memin case memory could not be allocated for the internal structures.
Othererror codes from the underlying flash storage driver.

◆ try_init() [5/6]

static result< void > idfxx::nvs::flash::try_init ( std::string_view  partition_label)
static

Initialize NVS flash storage for the specified partition.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
Returns
Success, or an error.
Return values
nvs::errc::no_free_pagesif the NVS storage contains no empty pages (which may happen if NVS partition was truncated).
nvs::errc::not_foundif specified partition is not found in the partition table.
nvs::errc::no_memin case memory could not be allocated for the internal structures.
Othererror codes from the underlying flash storage driver.

◆ try_init() [6/6]

static result< void > idfxx::nvs::flash::try_init ( std::string_view  partition_label,
const secure_config cfg 
)
static

Initialize NVS flash storage for the specified partition.

Parameters
partition_labelLabel of the partition. Must be no longer than 16 characters.
cfgSecurity configuration (keys) to be used for NVS encryption/decryption.
Returns
Success, or an error.
Return values
nvs::errc::no_free_pagesif the NVS storage contains no empty pages (which may happen if NVS partition was truncated).
nvs::errc::not_foundif specified partition is not found in the partition table.
nvs::errc::no_memin case memory could not be allocated for the internal structures.
Othererror codes from the underlying flash storage driver.

Member Data Documentation

◆ insecure

constexpr insecure_t idfxx::nvs::flash::insecure {}
staticconstexpr

Insecure (non-encrypted) initialization tag.

Definition at line 364 of file nvs.hpp.

◆ key_size

constexpr size_t idfxx::nvs::flash::key_size = 32
staticconstexpr

Size of each NVS encryption key in bytes

Definition at line 344 of file nvs.hpp.


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