mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
fixed #1424. Check if .b32.i2p address string is valid
This commit is contained in:
parent
d6b1d0d4fb
commit
c2f47119ce
4 changed files with 15 additions and 7 deletions
|
@ -237,17 +237,19 @@ namespace client
|
|||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
Address::Address (const std::string& b32)
|
||||
Address::Address (const std::string& b32):
|
||||
addressType (eAddressInvalid)
|
||||
{
|
||||
if (b32.length () <= B33_ADDRESS_THRESHOLD)
|
||||
{
|
||||
addressType = eAddressIndentHash;
|
||||
identHash.FromBase32 (b32);
|
||||
if (identHash.FromBase32 (b32) > 0)
|
||||
addressType = eAddressIndentHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
addressType = eAddressBlindedPublicKey;
|
||||
blindedPublicKey = std::make_shared<i2p::data::BlindedPublicKey>(b32);
|
||||
if (blindedPublicKey->IsValid ())
|
||||
addressType = eAddressBlindedPublicKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,7 +322,10 @@ namespace client
|
|||
{
|
||||
auto pos = address.find(".b32.i2p");
|
||||
if (pos != std::string::npos)
|
||||
return std::make_shared<const Address>(address.substr (0, pos));
|
||||
{
|
||||
auto addr = std::make_shared<const Address>(address.substr (0, pos));
|
||||
return addr->IsValid () ? addr : nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = address.find (".i2p");
|
||||
|
|
|
@ -33,13 +33,14 @@ namespace client
|
|||
|
||||
struct Address
|
||||
{
|
||||
enum { eAddressIndentHash, eAddressBlindedPublicKey } addressType;
|
||||
enum { eAddressIndentHash, eAddressBlindedPublicKey, eAddressInvalid } addressType;
|
||||
i2p::data::IdentHash identHash;
|
||||
std::shared_ptr<i2p::data::BlindedPublicKey> blindedPublicKey;
|
||||
|
||||
Address (const std::string& b32);
|
||||
Address (const i2p::data::IdentHash& hash);
|
||||
bool IsIdentHash () const { return addressType == eAddressIndentHash; };
|
||||
bool IsValid () const { return addressType != eAddressInvalid; };
|
||||
};
|
||||
|
||||
inline std::string GetB32Address(const i2p::data::IdentHash& ident) { return ident.ToBase32().append(".b32.i2p"); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue