mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
RsBase64 handle correcly 0 lenght buffer encoding
This commit is contained in:
parent
d87abb45e3
commit
3332c32a84
@ -40,6 +40,12 @@
|
|||||||
rs_view_ptr<const uint8_t> data, size_t len, std::string& outString,
|
rs_view_ptr<const uint8_t> data, size_t len, std::string& outString,
|
||||||
bool padding, bool urlSafe )
|
bool padding, bool urlSafe )
|
||||||
{
|
{
|
||||||
|
if(!data || !len)
|
||||||
|
{
|
||||||
|
outString.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const char* sDict = urlSafe ? uDict : bDict;
|
const char* sDict = urlSafe ? uDict : bDict;
|
||||||
|
|
||||||
// Workaround if input and output are the same buffer.
|
// Workaround if input and output are the same buffer.
|
||||||
@ -137,6 +143,7 @@
|
|||||||
|
|
||||||
/*static*/ size_t RsBase64::encodedSize(size_t decodedSize, bool padding)
|
/*static*/ size_t RsBase64::encodedSize(size_t decodedSize, bool padding)
|
||||||
{
|
{
|
||||||
|
if(!decodedSize) return 0;
|
||||||
if(padding) return 4 * (decodedSize + 2) / 3;
|
if(padding) return 4 * (decodedSize + 2) / 3;
|
||||||
return static_cast<size_t>(
|
return static_cast<size_t>(
|
||||||
std::ceil(4L * static_cast<double>(decodedSize) / 3L) );
|
std::ceil(4L * static_cast<double>(decodedSize) / 3L) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user