Permalink
Browse files

Rename crypto string conversion functions

  • Loading branch information...
mbasaglia committed Mar 10, 2016
1 parent 0eb3a9a commit 4a13ad96ced8c9d405dc977bff40d3bbd06b3aa4
@@ -1468,7 +1468,7 @@ static void CL_RconDeliver(const Rcon::Message &message)
}
std::string method = "PLAIN";
Crypto::Data key = Crypto::Hash::Sha256(Crypto::String(message.password));
Crypto::Data key = Crypto::Hash::Sha256(Crypto::FromString(message.password));
std::string plaintext = message.command;
if ( message.secure == Rcon::Secure::EncryptedChallenge )
@@ -1478,11 +1478,11 @@ static void CL_RconDeliver(const Rcon::Message &message)
}
Crypto::Data cypher;
if ( Crypto::Aes256Encrypt(Crypto::String(plaintext), key, cypher) )
if ( Crypto::Aes256Encrypt(Crypto::FromString(plaintext), key, cypher) )
{
Net::OutOfBandPrint(netsrc_t::NS_CLIENT, message.remote, "srcon %s %s",
method,
Crypto::String(Crypto::Encoding::Base64Encode(cypher))
Crypto::ToString(Crypto::Encoding::Base64Encode(cypher))
);
}
}
@@ -37,12 +37,12 @@ namespace Crypto {
Data RandomData( std::size_t bytes );
inline Data String(const std::string& string)
inline Data FromString(const std::string& string)
{
return Data(string.begin(), string.end());
}
inline std::string String(const Data string)
inline std::string ToString(const Data string)
{
return std::string(string.begin(), string.end());
}
@@ -75,7 +75,7 @@ std::string Challenge::GenerateString()
{
Crypto::Data data( Bytes() );
Sys::GenRandomBytes(data.data(), data.size());
return Crypto::String(Crypto::Encoding::HexEncode(data));
return Crypto::ToString(Crypto::Encoding::HexEncode(data));
}
bool Challenge::ValidString(const std::string& challenge)
@@ -162,7 +162,7 @@ bool ChallengeManager::MatchString( const netadr_t& source,
const std::string& challenge,
Challenge::Duration* ping )
{
auto challenge_data = Crypto::String(challenge);
auto challenge_data = Crypto::FromString(challenge);
if ( Crypto::Encoding::HexDecode(challenge_data, challenge_data) )
{
return Match({source, challenge_data}, ping);
@@ -97,7 +97,7 @@ class Challenge
*/
std::string String() const
{
return Crypto::String( Crypto::Encoding::HexEncode( challenge ) );
return Crypto::ToString( Crypto::Encoding::HexEncode( challenge ) );
}
/*
@@ -903,22 +903,22 @@ static Rcon::Message RconDecode(const netadr_t& remote, const Cmd::Args& args)
}
auto authentication = args[1];
Crypto::Data cyphertext = Crypto::String(args[2]);
Crypto::Data cyphertext = Crypto::FromString(args[2]);
Crypto::Data data;
if ( !Crypto::Encoding::Base64Decode( cyphertext, data ) )
{
return Rcon::Message("Invalid Base64 string");
}
Crypto::Data key = Crypto::Hash::Sha256( Crypto::String( cvar_rcon_server_password.Get() ) );
Crypto::Data key = Crypto::Hash::Sha256( Crypto::FromString( cvar_rcon_server_password.Get() ) );
if ( !Crypto::Aes256Decrypt( data, key, data ) )
{
return Rcon::Message("Error during decryption");
}
std::string command = Crypto::String( data );
std::string command = Crypto::ToString( data );
if ( authentication == "CHALLENGE" )
{

0 comments on commit 4a13ad9

Please sign in to comment.