use RsRandom::alphaNumeric

This commit is contained in:
sehraf 2020-06-13 11:07:07 +02:00
parent 8323b94a6a
commit f18d49db48
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
3 changed files with 3 additions and 28 deletions

View File

@ -945,13 +945,9 @@ void p3I2pBob::finalizeSettings_locked()
// setup commands // setup commands
// new lines are appended later! // new lines are appended later!
// generate random suffix for name // generate 8 characater long random suffix for name
// RSRandom::random_alphaNumericString can return very weird looking strings like: ,,@z+M constexpr size_t len = 8;
// use base32 instead const std::string location = RsRandom::alphaNumeric(len);
size_t len = 5; // 5 characters = 8 base32 symbols
std::vector<uint8_t> tmp(len);
RSRandom::random_bytes(tmp.data(), len);
const std::string location = Radix32::encode(tmp.data(), len);
RS_DBG4("using suffix ", location); RS_DBG4("using suffix ", location);
mTunnelName = "RetroShare-" + location; mTunnelName = "RetroShare-" + location;

View File

@ -5,14 +5,6 @@
namespace i2p { namespace i2p {
const std::string generateNameSuffix(const size_t len) {
std::vector<uint8_t> tmp(len);
RsRandom::random_bytes(tmp.data(), len);
const std::string location = Radix32::encode(tmp.data(), len);
return location;
}
std::string keyToBase32Addr(const std::string &key) std::string keyToBase32Addr(const std::string &key)
{ {
std::string copy(key); std::string copy(key);

View File

@ -184,19 +184,6 @@ static const std::array<std::pair<uint16_t, uint16_t>, 12> signingKeyLengths {
/*SigningKeyType::RedDSA_SHA512_Ed25519 */ std::make_pair<uint16_t, uint16_t>( 32, 32), /*SigningKeyType::RedDSA_SHA512_Ed25519 */ std::make_pair<uint16_t, uint16_t>( 32, 32),
}; };
/**
* @brief generateNameSuffix Generates a base32 name suffix for tunnel identification
* @param len lenght of random bytes, will be expanded by base32 encoding
* @return base32 string
*
* RSRandom::random_alphaNumericString can return very weird looking strings like: ,,@z+M
* -> so use base32 instead
*
* 5 characters = 8 base32 symbols
*/
const std::string generateNameSuffix(const size_t len = 5);
/** /**
* @brief makeOption Creates the string "lhs=rhs" used by BOB and SAM. Converts rhs * @brief makeOption Creates the string "lhs=rhs" used by BOB and SAM. Converts rhs
* @param lhs option to set * @param lhs option to set