diff --git a/llarp/crypto/types.hpp b/llarp/crypto/types.hpp index e62c0476a..0092adcfb 100644 --- a/llarp/crypto/types.hpp +++ b/llarp/crypto/types.hpp @@ -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); diff --git a/llarp/router_contact.cpp b/llarp/router_contact.cpp index 7f1280f7a..11aa3341f 100644 --- a/llarp/router_contact.cpp +++ b/llarp/router_contact.cpp @@ -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("p")); + auto pubkey = data.require("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("p"); diff --git a/llarp/router_id.hpp b/llarp/router_id.hpp index 6a25ff9d4..d587f8365 100644 --- a/llarp/router_id.hpp +++ b/llarp/router_id.hpp @@ -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);