Skip to content

Commit

Permalink
ESP32: Maximum length of NVS key should be 15 characters (#15240)
Browse files Browse the repository at this point in the history
* Maximum length of key name should be 15 charactors

* Addressed review comment

* Restyled by whitespace

* Restyled by clang-format

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Nov 23, 2023
1 parent 03e60e3 commit 1648948
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/platform/ESP32/ESP32Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_GroupKeyIndex = { kConfigNam
const ESP32Config::Key ESP32Config::kConfigKey_LastUsedEpochKeyId = { kConfigNamespace_ChipConfig, "last-ek-id" };
const ESP32Config::Key ESP32Config::kConfigKey_FailSafeArmed = { kConfigNamespace_ChipConfig, "fail-safe-armed" };
const ESP32Config::Key ESP32Config::kConfigKey_WiFiStationSecType = { kConfigNamespace_ChipConfig, "sta-sec-type" };
const ESP32Config::Key ESP32Config::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "regulatory-location" };
const ESP32Config::Key ESP32Config::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "reg-location" };
const ESP32Config::Key ESP32Config::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" };
const ESP32Config::Key ESP32Config::kConfigKey_Breadcrumb = { kConfigNamespace_ChipConfig, "breadcrumb" };

Expand Down
11 changes: 11 additions & 0 deletions src/platform/ESP32/ESP32Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ struct ESP32Config::Key
const char * Name;

bool operator==(const Key & other) const;

template <typename T, typename std::enable_if_t<std::is_convertible<T, const char *>::value, int> = 0>
Key(const char * aNamespace, T aName) : Namespace(aNamespace), Name(aName)
{}

template <size_t N>
Key(const char * aNamespace, const char (&aName)[N]) : Namespace(aNamespace), Name(aName)
{
// Note: N includes null-terminator.
static_assert(N <= ESP32Config::kMaxConfigKeyNameLength + 1, "Key too long");
}
};

inline bool ESP32Config::Key::operator==(const Key & other) const
Expand Down

0 comments on commit 1648948

Please sign in to comment.