]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3398] Moved to unordered set
authorFrancis Dupont <fdupont@isc.org>
Sun, 22 Dec 2024 17:49:58 +0000 (18:49 +0100)
committerFrancis Dupont <fdupont@isc.org>
Mon, 27 Jan 2025 14:05:12 +0000 (15:05 +0100)
src/lib/cc/default_credentials.cc
src/lib/cc/default_credentials.h

index d502cc0b980870c73ab0cbb647056a19c6f4bd6b..39ebc4f23a71cce5ca1f96a53622a94a7f3e8c33 100644 (file)
@@ -10,7 +10,8 @@
 namespace isc {
 namespace data {
 
-const std::list<std::string> DefaultCredentials::DEFAULT_CREDENTIALS = {
+const std::unordered_set<std::string>
+DefaultCredentials::DEFAULT_CREDENTIALS = {
 #ifndef IGNORE_KEA_DEFAULT_CREDENTIALS
 #ifndef ALLOW_KEATEST
     "keatest",
@@ -22,12 +23,11 @@ const std::list<std::string> DefaultCredentials::DEFAULT_CREDENTIALS = {
 #endif
 };
 
-void DefaultCredentials::check(const std::string& value) {
-    for (auto const& cred : DEFAULT_CREDENTIALS) {
-        if (value == cred) {
-            isc_throw(DefaultCredential,
-                      "illegal use of a default value as credential");
-        }
+void
+DefaultCredentials::check(const std::string& value) {
+    if (DEFAULT_CREDENTIALS.count(value)) {
+        isc_throw(DefaultCredential,
+                  "illegal use of a default value as credential");
     }
 }
 
index 462330f2e8122f9c54bad96544b420a55695e31d..1ed98aa5611098075d2271b63d1a00cb4eab8683 100644 (file)
@@ -8,7 +8,7 @@
 #define DEFAULT_CREDENTIALS_H
 
 #include <exceptions/exceptions.h>
-#include <list>
+#include <unordered_set>
 #include <string>
 
 namespace isc {
@@ -24,9 +24,7 @@ public:
 /// @brief Base class for default credentials.
 struct DefaultCredentials {
     /// @brief Default credentials.
-    ///
-    /// @note Using a list as there are only a few default credentials.
-    static const std::list<std::string> DEFAULT_CREDENTIALS;
+    static const std::unordered_set<std::string> DEFAULT_CREDENTIALS;
 
     /// @brief Check if the value is a default credential.
     ///