23#include <idfxx/partition>
41 std::same_as<T, uint8_t> || std::same_as<T, int8_t> || std::same_as<T, uint16_t> || std::same_as<T, int16_t> ||
42 std::same_as<T, uint32_t> || std::same_as<T, int32_t> || std::same_as<T, uint64_t> || std::same_as<T, int64_t>;
105#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
128#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
168#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
349 bool _read_only =
false;
381 constexpr static size_t key_size = 32;
387 std::array<uint8_t, key_size>
eky;
388 std::array<uint8_t, key_size>
tky;
403#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
655#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
691#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
// end of idfxx_nvs
Error category for NVS errors.
std::string message(int ec) const override final
Returns a human-readable message for the given error code.
const char * name() const noexcept override final
Returns the name of the error category.
static result< void > try_init(std::string_view partition_label, const secure_config &cfg)
Initialize NVS flash storage for the specified partition.
static result< secure_config > try_generate_keys(const partition &key_part)
Generate NVS encryption keys and store them on a key partition.
static secure_config generate_keys(const partition &key_part)
Generate NVS encryption keys and store them on a key partition.
static secure_config read_security_cfg(const partition &key_part)
Read NVS encryption keys from a key partition.
static result< void > try_init(const secure_config &cfg)
Initialize the default NVS partition with encryption.
static result< void > try_erase(const partition &part)
Erases the specified NVS partition.
static void init(insecure_t)
Initialize the default NVS partition without encryption.
static result< void > try_deinit()
Deinitialize NVS storage for the default NVS partition.
static result< secure_config > try_read_security_cfg(const partition &key_part)
Read NVS encryption keys from a key partition.
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(const secure_config &cfg)
Initialize the default NVS partition with encryption.
static void deinit()
Deinitialize NVS storage for the default NVS partition.
static void erase(std::string_view partition_label)
Erase specified NVS partition.
static result< void > try_init(const partition &part)
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 result< void > try_init()
Initializes the default NVS partition.
static result< void > try_erase(std::string_view partition_label)
Erases the specified NVS partition.
static void erase(const partition &part)
Erase the specified NVS partition.
static result< void > try_erase()
Erases the default NVS partition.
static result< void > try_init(insecure_t)
Initialize the default NVS partition without encryption.
static void init(insecure_t, const partition &part)
Initialize NVS flash storage for the specified partition without encryption.
static void deinit(std::string_view partition_label)
Deinitialize NVS storage for the specified partition.
static result< void > try_init(const partition &part, const secure_config &cfg)
Initialize NVS flash storage for the specified partition with encryption.
static void init()
Initializes the default NVS partition.
static result< void > try_deinit(std::string_view partition_label)
Deinitialize NVS storage for the specified partition.
static result< void > try_init(std::string_view partition_label)
Initialize NVS flash storage for the specified partition.
static void erase()
Erases the default NVS partition.
static void init(const partition &part)
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 void init(const partition &part, const secure_config &cfg)
Initialize NVS flash storage for the specified partition with encryption.
static result< void > try_init(insecure_t, const partition &part)
Initialize NVS flash storage for the specified partition without encryption.
Non-Volatile Storage handle.
nvs(nvs &&other) noexcept
Move constructor.
result< T > try_get_value(std::string_view key)
Retrieves an integer value.
result< void > try_erase_all()
Erases all keys in the namespace.
T get_value(std::string_view key)
Retrieves an integer value.
void commit()
Commits pending changes to flash.
result< void > try_erase(std::string_view key)
Erases a key.
std::string get_string(std::string_view key)
Retrieves a string.
result< std::string > try_get_string(std::string_view key)
Retrieves a string.
result< std::vector< uint8_t > > try_get_blob(std::string_view key)
Retrieves binary data.
void set_value(std::string_view key, T value)
Stores an integer value.
nvs & operator=(const nvs &)=delete
nvs & operator=(nvs &&other) noexcept
Move assignment.
void set_blob(std::string_view key, const void *data, size_t length)
Stores binary data.
static result< nvs > make(const partition &part, std::string_view namespace_name, bool read_only=false)
Opens a NVS namespace on a specific partition.
result< void > try_commit()
Commits pending changes to flash.
void set_string(std::string_view key, std::string_view value)
Stores a string.
result< void > try_set_blob(std::string_view key, const void *data, size_t length)
Stores binary data.
std::vector< uint8_t > get_blob(std::string_view key)
Retrieves binary data.
bool is_writeable() const
Returns true if the handle allows writes.
nvs(const partition &part, std::string_view namespace_name, bool read_only=false)
Opens a NVS namespace on a specific partition.
result< void > try_set_value(std::string_view key, T value)
Stores an integer value.
void erase(std::string_view key)
Erases a key.
errc
Error codes for NVS operations.
void set_blob(std::string_view key, std::span< const uint8_t > data)
Stores binary data.
nvs(std::string_view namespace_name, bool read_only=false)
Opens a NVS namespace.
result< void > try_set_blob(std::string_view key, std::span< const uint8_t > data)
Stores binary data.
result< void > try_set_string(std::string_view key, std::string_view value)
Stores a string.
static result< nvs > make(std::string_view namespace_name, bool read_only=false)
Opens a NVS namespace.
void erase_all()
Erases all keys in the namespace.
const nvs::error_category & nvs_category() noexcept
Returns a reference to the NVS error category singleton.
std::unexpected< std::error_code > nvs_error(esp_err_t e)
Creates an unexpected error from an ESP-IDF error code, mapping to NVS error codes where possible.
std::error_code make_error_code(errc e) noexcept
Creates a std::error_code from an idfxx::errc value.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Tag type to indicate insecure (non-encrypted) initialization.
Key for encryption and decryption.
std::array< uint8_t, key_size > eky
std::array< uint8_t, key_size > tky