Skip to content

Commit 75594bd

Browse files
committed
torcontrol: Use fs::path instead of std::string for private key path
1 parent 2a5f574 commit 75594bd

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/torcontrol.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
314314
* @param maxsize Puts a maximum size limit on the file that is read. If the file is larger than this, truncated data
315315
* (with len > maxsize) will be returned.
316316
*/
317-
static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, size_t maxsize=std::numeric_limits<size_t>::max())
317+
static std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size_t maxsize=std::numeric_limits<size_t>::max())
318318
{
319-
FILE *f = fopen(filename.c_str(), "rb");
319+
FILE *f = fsbridge::fopen(filename, "rb");
320320
if (f == NULL)
321321
return std::make_pair(false,"");
322322
std::string retval;
@@ -334,9 +334,9 @@ static std::pair<bool,std::string> ReadBinaryFile(const std::string &filename, s
334334
/** Write contents of std::string to a file.
335335
* @return true on success.
336336
*/
337-
static bool WriteBinaryFile(const std::string &filename, const std::string &data)
337+
static bool WriteBinaryFile(const fs::path &filename, const std::string &data)
338338
{
339-
FILE *f = fopen(filename.c_str(), "wb");
339+
FILE *f = fsbridge::fopen(filename, "wb");
340340
if (f == NULL)
341341
return false;
342342
if (fwrite(data.data(), 1, data.size(), f) != data.size()) {
@@ -359,7 +359,7 @@ class TorController
359359
~TorController();
360360

361361
/** Get name fo file to store private key in */
362-
std::string GetPrivateKeyFile();
362+
fs::path GetPrivateKeyFile();
363363

364364
/** Reconnect, after getting disconnected */
365365
void Reconnect();
@@ -411,7 +411,7 @@ TorController::TorController(struct event_base* _base, const std::string& _targe
411411
// Read service private key if cached
412412
std::pair<bool,std::string> pkf = ReadBinaryFile(GetPrivateKeyFile());
413413
if (pkf.first) {
414-
LogPrint(BCLog::TOR, "tor: Reading cached private key from %s\n", GetPrivateKeyFile());
414+
LogPrint(BCLog::TOR, "tor: Reading cached private key from %s\n", GetPrivateKeyFile().string());
415415
private_key = pkf.second;
416416
}
417417
}
@@ -442,9 +442,9 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
442442
service = LookupNumeric(std::string(service_id+".onion").c_str(), GetListenPort());
443443
LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString());
444444
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
445-
LogPrint(BCLog::TOR, "tor: Cached service private key to %s\n", GetPrivateKeyFile());
445+
LogPrint(BCLog::TOR, "tor: Cached service private key to %s\n", GetPrivateKeyFile().string());
446446
} else {
447-
LogPrintf("tor: Error writing service private key to %s\n", GetPrivateKeyFile());
447+
LogPrintf("tor: Error writing service private key to %s\n", GetPrivateKeyFile().string());
448448
}
449449
AddLocal(service, LOCAL_MANUAL);
450450
// ... onion requested - keep connection open
@@ -651,9 +651,9 @@ void TorController::Reconnect()
651651
}
652652
}
653653

654-
std::string TorController::GetPrivateKeyFile()
654+
fs::path TorController::GetPrivateKeyFile()
655655
{
656-
return (GetDataDir() / "onion_private_key").string();
656+
return GetDataDir() / "onion_private_key";
657657
}
658658

659659
void TorController::reconnect_cb(evutil_socket_t fd, short what, void *arg)

0 commit comments

Comments
 (0)