remove some string conversions entirely

pull/1281/head
Rick V 4 years ago
parent 5529371637
commit 1340cd0dce

@ -186,7 +186,7 @@ namespace llarp
bool
KeyManager::backupKeyFilesByMoving() const
{
std::vector<std::string> files = {m_rcPath.string(), m_idKeyPath.string(), m_encKeyPath.string(), m_transportKeyPath.string()};
std::vector<fs::path> files = {m_rcPath, m_idKeyPath, m_encKeyPath, m_transportKeyPath};
for (auto& filepath : files)
{
@ -216,7 +216,7 @@ namespace llarp
LogInfo("Generating new key", filepath);
keygen(key);
if (!key.SaveToFile(filepath.string().c_str()))
if (!key.SaveToFile(filepath))
{
LogError("Failed to save new key");
return false;
@ -224,7 +224,7 @@ namespace llarp
}
LogDebug("Loading key from file ", filepath);
return key.LoadFromFile(filepath.string().c_str());
return key.LoadFromFile(filepath);
}
bool

@ -27,9 +27,9 @@ namespace llarp
}
bool
SecretKey::LoadFromFile(const char* fname)
SecretKey::LoadFromFile(const fs::path& fname)
{
std::ifstream f(fname, std::ios::in | std::ios::binary);
std::ifstream f(fname.string(), std::ios::in | std::ios::binary);
if (!f.is_open())
{
return false;
@ -89,7 +89,7 @@ namespace llarp
}
bool
SecretKey::SaveToFile(const char* fname) const
SecretKey::SaveToFile(const fs::path& fname) const
{
std::array<byte_t, 128> tmp;
llarp_buffer_t buf(tmp);
@ -97,8 +97,7 @@ namespace llarp
{
return false;
}
const fs::path fpath = std::string(fname);
auto optional_f = llarp::util::OpenFileStream<std::ofstream>(fpath, std::ios::binary);
auto optional_f = llarp::util::OpenFileStream<std::ofstream>(fname, std::ios::binary);
if (!optional_f)
return false;
auto& f = *optional_f;
@ -109,10 +108,9 @@ namespace llarp
}
bool
IdentitySecret::LoadFromFile(const char* fname)
IdentitySecret::LoadFromFile(const fs::path& fname)
{
const fs::path fpath = std::string(fname);
auto optional = util::OpenFileStream<std::ifstream>(fpath, std::ios::binary | std::ios::in);
auto optional = util::OpenFileStream<std::ifstream>(fname, std::ios::binary | std::ios::in);
if (!optional)
return false;
auto& f = *optional;

@ -5,6 +5,7 @@
#include <router_id.hpp>
#include <util/aligned.hpp>
#include <util/types.hpp>
#include <util/fs.hpp>
#include <algorithm>
#include <iostream>
@ -122,10 +123,10 @@ namespace llarp
toPrivate(PrivateKey& key) const;
bool
LoadFromFile(const char* fname);
LoadFromFile(const fs::path& fname);
bool
SaveToFile(const char* fname) const;
SaveToFile(const fs::path& fname) const;
};
inline std::ostream&
@ -204,7 +205,7 @@ namespace llarp
/// load service node seed from file
bool
LoadFromFile(const char* fname);
LoadFromFile(const fs::path& fname);
};
inline std::ostream&

@ -301,12 +301,12 @@ llarp_nodedb::loadfile(const fs::path& fpath)
llarp::RouterContact rc;
if (!rc.Read(fpath))
{
llarp::LogError("failed to read file ", fpath.string());
llarp::LogError("failed to read file ", fpath);
return false;
}
if (!rc.Verify(llarp::time_now_ms()))
{
llarp::LogError(fpath.string(), " contains invalid RC");
llarp::LogError(fpath, " contains invalid RC");
return false;
}
{

@ -473,7 +473,7 @@ namespace llarp
}
if (isListFile)
{
if (not BDecodeReadFile(router.string().c_str(), b_list))
if (not BDecodeReadFile(router, b_list))
{
throw std::runtime_error(stringify("failed to read bootstrap list file '", router, "'"));
}
@ -481,7 +481,7 @@ namespace llarp
else
{
RouterContact rc;
if (not rc.Read(router.string().c_str()))
if (not rc.Read(router))
{
throw std::runtime_error(
stringify("failed to decode bootstrap RC, file='", router, "' rc=", rc));

@ -296,12 +296,12 @@ namespace llarp
/// read entire file and decode its contents into t
template <typename T>
bool
BDecodeReadFile(const char* fpath, T& t)
BDecodeReadFile(const fs::path& fpath, T& t)
{
std::vector<byte_t> ptr;
{
std::ifstream f;
f.open(fpath);
f.open(fpath.string());
if (!f.is_open())
{
return false;

Loading…
Cancel
Save