refactor(rpc): GenerateAuthCookieResult -> AuthCookieResult
What changed, and why it matters
This commit is a simple code cleanup: it renames an internal status type from GenerateAuthCookieResult to AuthCookieResult and changes its value names to CamelCase. It also fixes a typo in a code comment where 'ERROR' was written as 'ERR'. No behavior of the Bitcoin RPC authentication cookie is changed.
No security action needed; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
Pure refactor of an enum class and its usages across httprpc.cpp and rpc/request.{h,cpp}. The underlying constants (Disabled/Error/Ok) map 1:1 to the previous values (DISABLED/ERR/OK), and all call sites are updated consistently. The docstring in request.h is corrected to match the actual enum member names. No functional changes are introduced.
Changed components
src/rpc/request.hsrc/rpc/request.cppsrc/httprpc.cppInspect captured patch +19 / −19
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
index 2a6751df..9a076996 100644
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -264,12 +264,12 @@ static bool InitRPCAuthentication()
}
switch (GenerateAuthCookie(cookie_perms, user, pass)) {
- case GenerateAuthCookieResult::ERR:
+ case AuthCookieResult::Error:
return false;
- case GenerateAuthCookieResult::DISABLED:
+ case AuthCookieResult::Disabled:
LogInfo("RPC authentication cookie file generation is disabled.");
break;
- case GenerateAuthCookieResult::OK:
+ case AuthCookieResult::Ok:
LogInfo("Using random cookie authentication.");
break;
}
diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp
index 1798cdef..cf7109a4 100644
--- a/src/rpc/request.cpp
+++ b/src/rpc/request.cpp
@@ -97,9 +97,9 @@ static fs::path GetAuthCookieFile(bool temp=false)
static bool g_generated_cookie = false;
-GenerateAuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cookie_perms,
- std::string& user,
- std::string& pass)
+AuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cookie_perms,
+ std::string& user,
+ std::string& pass)
{
const size_t COOKIE_SIZE = 32;
unsigned char rand_pwd[COOKIE_SIZE];
@@ -112,12 +112,12 @@ GenerateAuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cook
std::ofstream file;
fs::path filepath_tmp = GetAuthCookieFile(true);
if (filepath_tmp.empty()) {
- return GenerateAuthCookieResult::DISABLED; // -norpccookiefile
+ return AuthCookieResult::Disabled; // -norpccookiefile
}
file.open(filepath_tmp.std_path());
if (!file.is_open()) {
LogWarning("Unable to open cookie authentication file %s for writing", fs::PathToString(filepath_tmp));
- return GenerateAuthCookieResult::ERR;
+ return AuthCookieResult::Error;
}
file << COOKIEAUTH_USER << ":" << rand_pwd_hex;
file.close();
@@ -125,14 +125,14 @@ GenerateAuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cook
fs::path filepath = GetAuthCookieFile(false);
if (!RenameOver(filepath_tmp, filepath)) {
LogWarning("Unable to rename cookie authentication file %s to %s", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
- return GenerateAuthCookieResult::ERR;
+ return AuthCookieResult::Error;
}
if (cookie_perms) {
std::error_code code;
fs::permissions(filepath, cookie_perms.value(), fs::perm_options::replace, code);
if (code) {
LogWarning("Unable to set permissions on cookie authentication file %s", fs::PathToString(filepath));
- return GenerateAuthCookieResult::ERR;
+ return AuthCookieResult::Error;
}
}
@@ -142,7 +142,7 @@ GenerateAuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cook
user = COOKIEAUTH_USER;
pass = rand_pwd_hex;
- return GenerateAuthCookieResult::OK;
+ return AuthCookieResult::Ok;
}
bool GetAuthCookie(std::string *cookie_out)
diff --git a/src/rpc/request.h b/src/rpc/request.h
index 4588db51..357f5d7e 100644
--- a/src/rpc/request.h
+++ b/src/rpc/request.h
@@ -23,10 +23,10 @@ UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params,
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue> id, JSONRPCVersion jsonrpc_version);
UniValue JSONRPCError(int code, const std::string& message);
-enum class GenerateAuthCookieResult : uint8_t {
- DISABLED, // -norpccookiefile
- ERR,
- OK,
+enum class AuthCookieResult : uint8_t {
+ Disabled, // -norpccookiefile
+ Error,
+ Ok,
};
/**
@@ -34,11 +34,11 @@ enum class GenerateAuthCookieResult : uint8_t {
* @param[in] cookie_perms Filesystem permissions to use for the cookie file.
* @param[out] user Generated username, only set if `OK` is returned.
* @param[out] pass Generated password, only set if `OK` is returned.
- * @retval GenerateAuthCookieResult::DISABLED Authentication via cookie is disabled.
- * @retval GenerateAuthCookieResult::ERROR Error occurred, auth data could not be saved to disk.
- * @retval GenerateAuthCookieResult::OK Auth data was generated, saved to disk and in `user` and `pass`.
+ * @retval AuthCookieResult::Disabled Authentication via cookie is disabled.
+ * @retval AuthCookieResult::Error Error occurred, auth data could not be saved to disk.
+ * @retval AuthCookieResult::Ok Auth data was generated, saved to disk and in `user` and `pass`.
*/
-GenerateAuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cookie_perms,
+AuthCookieResult GenerateAuthCookie(const std::optional<fs::perms>& cookie_perms,
std::string& user,
std::string& pass);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.