changed: in Crypto::Crypt()
MSVC compiler in debug mode reports accessing to vector[0] element (assertion) when the vector was empty (we took only a pointer without dereferencing) now we are using a dummy char object in such a case git-svn-id: svn://ttmath.org/publicrep/tito/trunk@398 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
a5a0201ec1
commit
23b06ec094
|
@ -86,6 +86,14 @@ void Crypto::AssignString(const std::wstring & src, std::string & dst, bool clea
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Crypto::Crypto()
|
||||||
|
{
|
||||||
|
dummy_char = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Crypto::SetAESKey(unsigned char aes_key[32])
|
bool Crypto::SetAESKey(unsigned char aes_key[32])
|
||||||
{
|
{
|
||||||
if( !aes.Key(aes_key, 32) )
|
if( !aes.Key(aes_key, 32) )
|
||||||
|
@ -102,7 +110,11 @@ return true;
|
||||||
void Crypto::Crypt(const std::wstring & in, std::wstring & out)
|
void Crypto::Crypt(const std::wstring & in, std::wstring & out)
|
||||||
{
|
{
|
||||||
PT::WideToUTF8(in, utf8_str);
|
PT::WideToUTF8(in, utf8_str);
|
||||||
aes.Encode((const unsigned char*)utf8_str.c_str(), utf8_str.size(), aes_name, uint8_tab);
|
|
||||||
|
if( utf8_str.empty() )
|
||||||
|
aes.Encode(&dummy_char, 0, aes_name, uint8_tab);
|
||||||
|
else
|
||||||
|
aes.Encode((const unsigned char*)utf8_str.c_str(), utf8_str.size(), aes_name, uint8_tab);
|
||||||
|
|
||||||
base64_str.clear();
|
base64_str.clear();
|
||||||
|
|
||||||
|
@ -116,16 +128,32 @@ void Crypto::Crypt(const std::wstring & in, std::wstring & out)
|
||||||
|
|
||||||
void Crypto::Crypt(const std::string & in, std::string & out)
|
void Crypto::Crypt(const std::string & in, std::string & out)
|
||||||
{
|
{
|
||||||
aes.Encode((const unsigned char*)&in[0], in.size(), aes_name, uint8_tab);
|
if( in.empty() )
|
||||||
base64.Encode((const char*)&uint8_tab[0], uint8_tab.size(), out);
|
aes.Encode(&dummy_char, 0, aes_name, uint8_tab);
|
||||||
|
else
|
||||||
|
aes.Encode((const unsigned char*)&in[0], in.size(), aes_name, uint8_tab);
|
||||||
|
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
if( !uint8_tab.empty() )
|
||||||
|
base64.Encode((const char*)&uint8_tab[0], uint8_tab.size(), out);
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Crypto::Crypt(const std::vector<char> & in, std::string & out)
|
void Crypto::Crypt(const std::vector<char> & in, std::string & out)
|
||||||
{
|
{
|
||||||
aes.Encode((const unsigned char*)&in[0], in.size(), aes_name, uint8_tab);
|
if( in.empty() )
|
||||||
base64.Encode((const char*)&uint8_tab[0], uint8_tab.size(), out);
|
aes.Encode(&dummy_char, 0, aes_name, uint8_tab);
|
||||||
|
else
|
||||||
|
aes.Encode((const unsigned char*)&in[0], in.size(), aes_name, uint8_tab);
|
||||||
|
|
||||||
|
out.clear();
|
||||||
|
|
||||||
|
if( !uint8_tab.empty() )
|
||||||
|
base64.Encode((const char*)&uint8_tab[0], uint8_tab.size(), out);
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ class Crypto
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Crypto();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
setting AES256 key
|
setting AES256 key
|
||||||
|
@ -106,6 +107,9 @@ private:
|
||||||
std::string base64_str;
|
std::string base64_str;
|
||||||
std::string aes_str;
|
std::string aes_str;
|
||||||
|
|
||||||
|
// a dummy character used when an input string is empty
|
||||||
|
unsigned char dummy_char;
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue