From 164894858a2f8c3ef29cdd7aaf423791e56fd291 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav <69809379+jadhavrohit924@users.noreply.github.com> Date: Thu, 17 Feb 2022 11:54:18 +0530 Subject: [PATCH] ESP32: Maximum length of NVS key should be 15 characters (#15240) * Maximum length of key name should be 15 charactors * Addressed review comment * Restyled by whitespace * Restyled by clang-format Co-authored-by: Restyled.io --- src/platform/ESP32/ESP32Config.cpp | 2 +- src/platform/ESP32/ESP32Config.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index ecdc3674900b98..7d70179ed5debe 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -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" }; diff --git a/src/platform/ESP32/ESP32Config.h b/src/platform/ESP32/ESP32Config.h index 7dd2a60864e6e2..5d009ad0091e00 100644 --- a/src/platform/ESP32/ESP32Config.h +++ b/src/platform/ESP32/ESP32Config.h @@ -113,6 +113,17 @@ struct ESP32Config::Key const char * Name; bool operator==(const Key & other) const; + + template ::value, int> = 0> + Key(const char * aNamespace, T aName) : Namespace(aNamespace), Name(aName) + {} + + template + 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