From 833a606b1361d03360220e872c5911591fe3c163 Mon Sep 17 00:00:00 2001 From: EinMByte Date: Sun, 2 Aug 2015 16:38:46 +0200 Subject: [PATCH] Add a constant for the I2PControl token size. --- i2pcontrol/I2PControl.cpp | 8 +++----- i2pcontrol/I2PControl.h | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/i2pcontrol/I2PControl.cpp b/i2pcontrol/I2PControl.cpp index 071dd60a..8e680307 100644 --- a/i2pcontrol/I2PControl.cpp +++ b/i2pcontrol/I2PControl.cpp @@ -199,14 +199,12 @@ bool I2PControlSession::authenticate(const PropertyTree& pt, Response& response) std::string I2PControlSession::generateToken() const { - const std::size_t token_size = 8; // 64 bits of security - - byte random_data[token_size] = {}; + byte random_data[I2P_CONTROL_TOKEN_SIZE] = {}; CryptoPP::AutoSeededRandomPool rng; - rng.GenerateBlock(random_data, token_size); + rng.GenerateBlock(random_data, I2P_CONTROL_TOKEN_SIZE); std::string token; CryptoPP::StringSource ss( - random_data, token_size, true, + random_data, I2P_CONTROL_TOKEN_SIZE, true, new CryptoPP::HexEncoder(new CryptoPP::StringSink(token)) ); return token; diff --git a/i2pcontrol/I2PControl.h b/i2pcontrol/I2PControl.h index ef423bd2..4a164790 100644 --- a/i2pcontrol/I2PControl.h +++ b/i2pcontrol/I2PControl.h @@ -13,6 +13,7 @@ namespace client { const char I2P_CONTROL_DEFAULT_PASSWORD[] = "itoopie"; const uint64_t I2P_CONTROL_TOKEN_LIFETIME = 600; // Token lifetime in seconds +const std::size_t I2P_CONTROL_TOKEN_SIZE = 8; // Token size in bytes const char I2P_CONTROL_PROPERTY_ID[] = "id"; const char I2P_CONTROL_PROPERTY_METHOD[] = "method";