diff -r 5cc91383ab1e -r 7333d7932ef7 secureswitools/swisistools/source/common/util.cpp --- a/secureswitools/swisistools/source/common/util.cpp Thu Aug 19 10:02:49 2010 +0300 +++ b/secureswitools/swisistools/source/common/util.cpp Tue Aug 31 15:21:33 2010 +0300 @@ -31,10 +31,13 @@ #include #include #include + #ifdef _WIN32 #include #endif // _WIN32 -#include "utf8.h" + + +#include "utf8_wrapper.h" static const TUint32 CrcTab32[256] = { @@ -212,9 +215,10 @@ TInt64 Util::WideCharToInt64(const wchar_t* aWideChar) { - TInt64 i64 = 0; - swscanf(aWideChar, L"%I64d", &i64); - return i64; + TInt64 value=0; + std::wstringstream str(aWideChar); + str >> value; + return value; } DllExport const std::wstring Util::IntegerToWideString(int aInt) @@ -243,23 +247,31 @@ std::string Util::Base64Decode( const std::string& aEncodedData ) { - BIO *mem = BIO_new(BIO_s_mem()); - BIO_write(mem, aEncodedData.c_str(), aEncodedData.length()); + unsigned char* pIn = aEncodedData.c_str(); + int inLen = aEncodedData.length(); + unsigned char* pOut = new unsigned char[inLen]; - BIO* b64 = BIO_new(BIO_f_base64()); - mem = BIO_push(b64, mem); - int inlen = 0; - char inbuf[40]={0}; + int outLen; + std::string aDecodeData; + + // create a memory buffer containing base64 encoded data + BIO* bmem = BIO_new_mem_buf((void*)pIn, inLen); - inlen = BIO_read(b64, inbuf, aEncodedData.length()); - BIO_write(mem, inbuf, inlen); - std::string decodedData = inbuf; - - BIO_free_all(mem); - return decodedData; + // push a Base64 filter so that reading from buffer decodes it + BIO *bioCmd = BIO_new(BIO_f_base64()); + // we don't want newlines + BIO_set_flags(bioCmd, BIO_FLAGS_BASE64_NO_NL); + bmem = BIO_push(bioCmd, bmem); + + int finalLen = BIO_read(bmem, (void*)pOut, outLen); + + aDecodeData.assign(pOut, pOut+finalLen); + delete pOut; + BIO_free_all(bmem); + + return aDecodeData; } - TUint32 Util::Crc32(const void* aPtr, TInt aLength) { const TUint8* p = (const TUint8*)aPtr; @@ -269,3 +281,7 @@ crc = (crc >> 8) ^ CrcTab32[(crc ^ *p++) & 0xff]; return crc; } + + + +