when read/writing a .loki privkey file we dont rewind a llarp_buffer_t
after use. this is an argument in favor of just removing that type
from the code entirely.

fixes by using 2 distinct locally scoped llarp_buffer_t, one for read,
one for write.
pull/2030/head
Jeff Becker 2 years ago
parent cd858a00ea
commit bd5da10885
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -80,7 +80,6 @@ namespace llarp
Clear();
std::array<byte_t, 4096> tmp;
llarp_buffer_t buf(tmp);
// this can throw
bool exists = fs::exists(fname);
@ -94,6 +93,7 @@ namespace llarp
// check for file
if (!exists)
{
llarp_buffer_t buf{tmp};
// regen and encode
RegenerateKeys();
if (!BEncode(&buf))
@ -108,6 +108,7 @@ namespace llarp
{
throw std::runtime_error{fmt::format("failed to write {}: {}", fname, e.what())};
}
return;
}
if (not fs::is_regular_file(fname))
@ -125,10 +126,11 @@ namespace llarp
throw std::length_error{"service identity too big"};
}
// (don't catch io error exceptions)
if (!bencode_decode_dict(*this, &buf))
throw std::length_error{"could not decode service identity"};
{
llarp_buffer_t buf{tmp};
if (!bencode_decode_dict(*this, &buf))
throw std::length_error{"could not decode service identity"};
}
auto crypto = CryptoManager::instance();
// ensure that the encryption key is set

Loading…
Cancel
Save