Fix pubkey parsing to be read as bytes

from_string was trying to parse it as base32z.snode

Also leave FIXMEs behind for the badly named methods (both in RouterID
itself and in ancestor classes).
This commit is contained in:
Jason Rhinelander 2023-12-11 15:41:16 -04:00
parent 636de93b1a
commit febcd44ea1
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262
3 changed files with 10 additions and 1 deletions

View File

@ -32,9 +32,11 @@ namespace llarp
std::string
ToString() const;
// FIXME: this is deceptively named: it should be "from_hex" since that's what it does.
bool
FromString(const std::string& str);
// FIXME: this is deceptively named: it should be "from_hex" since that's what it does.
static PubKey
from_string(const std::string& s);

View File

@ -61,7 +61,11 @@ namespace llarp
"Invalid RC netid: expected {}, got {}; this is an RC for a different network!"_format(
ACTIVE_NETID, netid)};
_router_id.from_string(data.require<std::string_view>("p"));
auto pubkey = data.require<std::string_view>("p");
if (pubkey.size() != 32)
throw std::runtime_error{
"Invalid RC pubkey: expected 32 bytes, got {}"_format(pubkey.size())};
std::memcpy(_router_id.data(), pubkey.data(), 32);
// auto pk = data.require<std::string_view>("p");

View File

@ -33,6 +33,9 @@ namespace llarp
std::string
ShortString() const;
// FIXME: this is deceptively named: it parses something base32z formatted with .snode on the
// end, so should probably be called "from_snode_address" or "from_base32z" or something that
// doesn't sound exactly like the other (different) from_strings of its base classes.
bool
from_string(std::string_view str);